#!/usr/bin/env node
'use strict';

const { createInterface } = require('readline');
const rl = createInterface({
  input: process.stdin,
  crlfDelay: Infinity
});

const buf = [];
const prom = [];
let maxBuf = 0;
let maxProm = 0;
rl.on('line', (line) => {
  if (prom.length > 0) {
    maxProm = Math.max(maxProm, prom.length);
    const [resolve, reject] = prom.shift();
    resolve(line);
  } else {
    rl.pause();
    buf.push(line);
    maxBuf = Math.max(maxBuf, buf.length);
  }
});

rl.on('close', () => {
  // console.error({maxProm, maxBuf});
});

async function getLine() {
  return new Promise((resolve, reject) => {
    if (buf.length > 0) {
      const line = buf.shift();
      resolve(line);
    } else {
      prom.push([resolve, reject]);
      rl.resume();
    }
  });
}

/**
 *
 * @param {Number []} arr
 * @param {Number} l
 * @returns {Number}
 */
function solve(arr, l) {
  const n = arr.length;
  if (n < 1) {
    return l / 2;
  }
  arr.unshift(0);
  arr.push(l);
  const tl = [0];
  for (let i = 1; i < n + 2; i++) {
    tl[i] = tl[i-1] + (arr[i] - arr[i-1]) / i;
  }
  const tr = [];
  tr[n+1] = 0;
  for (let i = n; i >= 0; --i) {
    const v = n - i + 1;
    tr[i] = tr[i+1] + (arr[i+1] - arr[i]) / v;
  }

  let ti = 0;
  for (; ti < n + 2; ti++) {
    if (tl[ti] >= tr[ti]) {
      break;
    }
  }
  // console.error({tl, tr, ti})

  if (tl[ti] === tr[ti]) {
    return tl[ti];
  }

  const vl = ti;
  const vr = n - ti + 2;
  const t = (arr[ti] - arr[ti-1] +
      vl * tl[ti-1] + vr * tr[ti])/ (n + 2);
  return t;
}

async function main() {
  const t = Number(await getLine());
  for (let i = 0; i < t; i++) {
    const [n, l] = (await getLine()).split(' ').map(Number);
    const arr = (await getLine()).split(' ').map(Number);
    const res = solve(arr, l);
    console.log(res);
  }
}

if (require.main === module) {
  main();
}

function closeInd(s, x) {
    var lo = 0;
    var hi = s.length - 1;
    var res = -1;
    while (hi >= lo) {
        var mid=Math.floor((hi + lo) / 2);
        if (s[mid] <= x) {
            lo = mid + 1;
            res = mid;
        }
        else hi = mid - 1;
    }
    return res;
}

function solv() {
    var ip = readline().split(' ').map(x => parseInt(x))
    var x = ip[0]
    var y = ip[1]
    var s = readline().split(' ').map(x => parseInt(x))

    x += 2

    s = [0].concat(s).concat(y)
    var rgtp = []
    for (var n = 0; n < x; n++)rgtp.push(Math.abs(y - s[n]))
    rgtp.reverse();

    var leftvelc = [1]

    for (var n = 1; n < x; n++)leftvelc.push(1 + leftvelc[n - 1]);

    var leftm = [0]
    var curtm = 0
    var spd = 1;
    for (var n = 1; n < x; n++) {
        var ln = s[n] - s[n - 1];
        var tim = ln / spd;
        curtm += tim;
        leftm.push(curtm)
        spd++;
    }

    var rightvelc = [1];
    for (var n = 1; n < x; n++)rightvelc.push(rightvelc[n - 1] + 1);

    curtm = 0
    spd = 1
    var rgtm = [0];

    for (var n = 1; n < x; n++) {
        var ln = rgtp[n] - rgtp[n - 1];
        var tim = ln / spd;
        curtm += tim;
        rgtm.push(curtm)
        spd++;
    }
    var lo = 0;
    var hi = y;
    while (hi > lo) {
        var mid = ((hi + lo) / 2.0);
        var mid1 = y - mid;
        var lfpos = closeInd(s, mid);
        var rgpos = closeInd(rgtp, mid1);
        var df1 = ((mid - s[lfpos]) / leftvelc[lfpos]) + leftm[lfpos];
        var df2 = ((mid1 - rgtp[rgpos]) / rightvelc[rgpos]) + rgtm[rgpos];
        if (Math.abs(df1 - df2) < (1e-5)) {
            print(df1);
            return;
        }
        else {
            if (df1 < df2) lo = mid;
            else hi = mid;
        }
    }
}

var tc = 1;
tc = parseInt(readline())
while (tc--) solv()

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
let MOD = 998244353
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
  return (u + MOD) % MOD;
}
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let t = $()
  while (t--) {
    let [n, l] = $(2), a = $(n);
    a.unshift(0); a.push(l);
    let i = 0; j = n + 1;
    let ti = 0, vi = 1, tj = 0, vj = 1;
    while (i + 1 < j) {
      let nti = ti + (a[i + 1] - a[i]) / vi;
      let ntj = tj + (a[j] - a[j - 1]) / vj;
      if (nti < ntj) {
        ti = nti;
        i++; vi++;
      } else {
        tj = ntj;
        j--; vj++;
      }
    }
    if (ti < tj) {
      log((a[j] - (tj - ti) * vi - a[i]) / (vi + vj) + tj)
    } else {
      log((a[j] - (ti - tj) * vj - a[i]) / (vi + vj) + ti)
    }
    // log(i, j, ti, tj, vi, vj)
  }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    C();
});

function readline() {
    return inputString[currentLine++];
}

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function C(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [n,l] = ti(readline().split(' '));
        let a = ti(readline().split(' '));

        let min = 0;
        let max = n-1;
        let i = 0;
        let j = l;
        let s1 = 1;
        let s2 = 1;
        let res = 0;
        while(i < j){
            if(a[min] <= a[max]){
                let x1 = (a[min]-i)/s1;
                let x2 = (j-a[max])/s2;
                if(x1 < x2){
                    i = a[min];
                    min++;
                    res += x1;
                    j -= x1*s2;
                    s1 += 1;
                }else if(x1 > x2){
                    j = a[max];
                    max--;
                    res += x2;
                    i += x2*s1;
                    s2 += 1;
                }else{
                    res += x1;
                    i = a[min];
                    j = a[max];
                    max--;
                    min++;
                    s1 += 1;
                    s2 += 1;
                }
            }else{
                res += (j-i)/(s1+s2);
                break;
            }
        }
        console.log(res);
    }
}

function closeInd(s, x) {
    var lo = 0;
    var hi = s.length - 1;
    var res = -1;
    while (hi >= lo) {
        var mid=Math.floor((hi + lo) / 2);
        if (s[mid] <= x) {
            lo = mid + 1;
            res = mid;
        }
        else hi = mid - 1;
    }
    return res;
}

function solv() {
    var ip = readline().split(' ').map(x => parseInt(x))
    var x = ip[0]
    var y = ip[1]
    var s = readline().split(' ').map(x => parseInt(x))

    x += 2

    s = [0].concat(s).concat(y)
    var rgtp = []
    for (var n = 0; n < x; n++)rgtp.push(Math.abs(y - s[n]))
    rgtp.reverse();

    var leftvelc = [1]

    for (var n = 1; n < x; n++)leftvelc.push(1 + leftvelc[n - 1]);

    var leftm = [0]
    var curtm = 0
    var spd = 1;
    for (var n = 1; n < x; n++) {
        var ln = s[n] - s[n - 1];
        var tim = ln / spd;
        curtm += tim;
        leftm.push(curtm)
        spd++;
    }

    var rightvelc = [1];
    for (var n = 1; n < x; n++)rightvelc.push(rightvelc[n - 1] + 1);

    curtm = 0
    spd = 1
    var rgtm = [0];

    for (var n = 1; n < x; n++) {
        var ln = rgtp[n] - rgtp[n - 1];
        var tim = ln / spd;
        curtm += tim;
        rgtm.push(curtm)
        spd++;
    }
    var lo = 0;
    var hi = y;
    while (hi > lo) {
        var mid = ((hi + lo) / 2.0);
        var mid1 = y - mid;
        var lfpos = closeInd(s, mid);
        var rgpos = closeInd(rgtp, mid1);
        var df1 = ((mid - s[lfpos]) / leftvelc[lfpos]) + leftm[lfpos];
        var df2 = ((mid1 - rgtp[rgpos]) / rightvelc[rgpos]) + rgtm[rgpos];
        if (Math.abs(df1 - df2) < (1e-4)) {
            print(df1);
            return;
        }
        else {
            if (df1 < df2) lo = mid;
            else hi = mid;
        }
    }
}

var tc = 1;
tc = parseInt(readline())
while (tc--) solv()


;(function () {

	print(function () {
		var n = +readline(), x = +readline(), y = 7 - x;

		while (n--) {
			var a = readline().split(' ').map(Number);
			if (a.indexOf(x) !== -1 || a.indexOf(y) !== -1)
				return 'NO';
		}

		return 'YES';
	}());

}).call(this);

print(function(n, x) {
	var s = '';
	for (var i = 0; i < n; i++)
		s += readline();

	return (new RegExp('[' + x + (7 - x) + ']')).test(s) ? 'NO' : 'YES';

}(+readline(), readline()));

print(function(n, x) {

	for (var i = 0; i < n; i++)
		if (
			readline().split(' ').map(Number).reduce(function(a, b) {
				return a === x || b === x || a === 7 - x || b === 7 - x;
			})
		) {
			return 'NO'
		}

	return 'YES';

}(+readline(), +readline()));

print(function(n, x) {
	var s = ' ';
	for (var i = 0; i < n; i++)
		s += readline();

	return s.indexOf(x) > -1 || s.indexOf(7 - x) > -1 ? 'NO' : 'YES';

}(+readline(), readline()));

print(function(n, x) {

	for (var i = 0; i < n; i++)
		if (readline().split(' ').reduce(function(a, b) {return a == x || b == x || a == 7 - x || b == 7 - x;})) {
			return 'NO'
		}

	return 'YES';

}(+readline(), readline()));

print(function(n, x) {

	var re = new RegExp('[' + x + (7 - x) + ']');

	for (var i = 0; i < n; i++)
		if (re.test(readline()))
			return 'NO'

	return 'YES';

}(+readline(), readline()));

var numberOfDices = Number(readline());
var topFace = Number(readline());
var faces = new Array(6).fill(0);

var isOk = true;
for (var i = 0; i < numberOfDices; i++) {
  faces[topFace - 1] += 1;
  faces[7 - topFace - 1] += 1;
  var numbers = readline()
    .split(' ')
    .map(Number);
  faces[numbers[0] - 1] += 1;
  faces[7 - numbers[0] - 1] += 1;
  faces[numbers[1] - 1] += 1;
  faces[7 - numbers[1] - 1] += 1;

  for (var j = 0; j < 6; j++) {
    if (faces[j] !== 1) {
      isOk = false;
      break;
    }
  }

  if (!isOk) {
    break;
  }

  topFace = 7 - topFace;
  faces = new Array(6).fill(0);
}

if (isOk) {
  print('YES');
} else {
  print('NO');
}

var n = parseInt(readline());
var s = parseInt(readline());

var excluded = 7 - s;
var res = 'YES';

while (n--) {
    var values = readline().split(' ').map(Number);
    if (values[0] === s || values[0] === excluded ||
        values[1] === s || values[1] === excluded) {
            res = 'NO';
        }
}

print(res);

print(function(n, x) {

	for (var i = 0; i < n; i++)
		if (readline().split(' ').reduce(function(a, b) {return a === x || b === x || a === 7 - x || b === 7 - x;}))
			return 'NO'

	return 'YES';

}(+readline(), readline()));

print(function(n, x) {
	var s = ' ';
	for (var i = 0; i < n; i++)
		s += readline();

	return s.indexOf(x) || s.indexOf(7 - x) ? 'NO' : 'YES';

}(+readline(), readline()));

var numberOfDices = Number(readline())
var topFace = Number(readline())
var faces = new Array(6).fill(0)

var isOk = true
for (var i = 0; i < numberOfDices; i++) {
  faces[topFace - 1] += 1
  faces[7 - topFace - 1] += 1
  var numbers = readline().split(' ').map(Number)
  numbers.forEach(n => {
    faces[n - 1] += 1
    faces[7 - n - 1] += 1
  })

  for (var j = 0; j < 6; j++) {
    if (faces[j] !== 1) {
      isOk = false
      break;
    }
  }

  if (!isOk) {
    break;
  }

  topFace = 7 - topFace
  faces = new Array(6).fill(0)
}

;(function () {

	print(function () {
		var n = +readline(), x = +readline(), a = [], b = [false, false, false, false, false, false];
		for (var i = 0; i < n; i++) a.push(readline().split(' ').map(Number).concat(false));
		b[x - 1] = b[a[0][0] - 1] = b[a[0][1] - 1] = true;
		for (var i = 1, _i = n + 1; i < _i; i++)
			if ((b[a[i - 1][0] - 1] || b[a[i - 1][1] - 1]) && !a[i - 1][2])
				i = b[a[i - 1][0] - 1] = b[a[i - 1][1] - 1] = a[i - 1][2] = true;
		return a.reduce(function (p, e) { return p + +(!e[2]); }, 0) ? 'NO' : 'YES';
	}());

}).call(this);


"use strict";

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});

process.stdin.on("end", (_) => {
  inputString = inputString
    .trim()
    .split("\n")
    .map((string) => {
      return string.trim();
    });

  main();
});

function readline() {
  return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  const x = readline().split(" ").map((x) => +x);
  const x2 = readline()
    .split("")
    .map((x) => +x);

  blackSquare(x,x2);
}

function blackSquare(calories, gameLog) {
  console.log(gameLog.reduce((prev, curr) => prev + calories[curr - 1], 0));
}

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

state = 0;
let values;
rl.on('line', line => {
  if (state % 2 == 0) {
    values = line.split(' ').map(Number);
  } else {
    console.log(
      line
        .split('')
        .map(x => {
          return parseInt(x) - 1;
        })
        .reduce((a, b) => {
          return a + values[b];
        }, 0)
    );
  }
  state++;
}).on('close', () => {
  process.exit(0);
});

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function main() {
    const stips = readline().split(' ').map(x => parseInt(x))
    const s = readline();
    let calories =0 ;
    for (let i = 0, c = s.length ; i< c ; i++ ){
        calories += stips[s[i]-1];
    }
    console.log(calories);
}

function main() {
    // write code here:
    var calorie = [];
    var calories=0;
    var touch=stdin[1].split('').map(Number);
    stdin[0].split(' ').map((a, i) => {
        a = Number(a);
        calorie[i] = a;
    });
    for(let i=0;i<touch.length;i++){
        calories+=calorie[touch[i]-1];
    }
    console.log(calories);
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {
    stdin.push(line);
});
rl.on('close', main);

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let caloriesPerStrip;
let blackSquarePosition;
let caloriesCounter = 0;
rl.on("line", (input) => {
    if (!caloriesPerStrip) {
        caloriesPerStrip = input.split(" ").map(Number)
    } else {
        blackSquarePosition = input.split("").map((char) => {
            switch (char) {
                case "1":
                    caloriesCounter += caloriesPerStrip[0]
                    break;
                case "2":
                    caloriesCounter += caloriesPerStrip[1]
                    break;
                case "3":
                    caloriesCounter += caloriesPerStrip[2]
                    break;

                case "4":
                    caloriesCounter += caloriesPerStrip[3]
                    break;

                default:
                    break;
            }
        })

        console.log(caloriesCounter)
        rl.close();
    }

});

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw "ArrayIndexOutOfBoundsException ‚There is no more input";}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var s = next();
  var output = 0;
  for(var i = 0; i < s.length; i++){
    output += one[myconv(s[i], 1) - 1];
  }
  myout(output);
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function print(s) {
  process.stdout.write(`${s}`);
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // input
  const a = readline().split(' ').map(x => parseInt(x));
  const s = readline();
  let sum = 0;
  for (let i = 0; i < s.length; i++) {
    sum += a[s.charAt(i) - 1];
  }
  // output
  print(sum);
}

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;
let calories = [];

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    calories = d.split(' ').map(Number);
    return;
  }

  let ans = 0;
  for (let i = 0; i < d.length; i++) {
    ans += calories[+d[i] - 1];
  }

  console.log(ans);

  c++;
});

let input = [];

const RL = require('readline').createInterface({
   input : process.stdin,
   output : process.stdout
});

RL.on('line', (line) => {
    input.push(line);
});

RL.on('close', () => {
    let answer = 0; let kal = [];
    input[0].split(' ').forEach(i => kal.push(parseInt(i)));
    [...input[1]].forEach(s => {
        answer += kal[parseInt(s)-1];
    });
    console.log(answer);
});

const input = [];

const RL = require('readline').createInterface({
   input : process.stdin,
   output : process.stdout
});

RL.on('line', (line) => {
    input.push(line);
});

RL.on('close', () => {
  const cal = input[0].split(' ').map(x => parseInt(x));
  let answer = 0;
  [...input[1]].map(x => parseInt(x)).forEach(num => {
    answer += cal[num-1];
  });

  console.log(answer);
});

var a = readline().split(" "), s = readline().split(""), sum = 0;

s.forEach(function(string){
	sum += +a[string-1];
});

write(sum);

var str = readline();
var s = readline();
str = str.split(' ');

function solve(a,b,c,d,str) {
  var res = 0;
  var arr = [0,a,b,c,d];
  for (var i = 0; i < str.length; i ++) res += arr[+str[i]];
  return res;
}

print(solve(+str[0], +str[1], +str[2], +str[3], s));

var kInfo = readline().split(' ').map(Number);
var numEdit = readline();
var numK = 0;

for (var i=0; i<numEdit.length; i++) {
    if (numEdit.charAt(i) == "1") {
        numK += kInfo[0];
    }
    else if (numEdit.charAt(i) == "2") {
        numK += kInfo[1];
    }
    else if (numEdit.charAt(i) == "3") {
        numK += kInfo[2];
    }
    else {
        numK += kInfo[3];
    }
}
print(numK);

  var reference = readline().split(' ').map(Number)
  var moves = readline()

  var caloriesBurnt = 0
  for (var i = 0; i < moves.length; ++i) {
    caloriesBurnt += reference[moves[i] - 1]
  }

  print(caloriesBurnt)

var values = readline().split(" ").map(function(n){return Number(n)});

var firstStrip= values[0];
var secondStrip= values[1];
var thirdStrip = values[2];
var fourthStrip = values[3];

var noOfTimes = readline();
var first=0 ;
var second=0 ;
var third=0 ;
var fourth=0;
var number=0;

var totalCalories=0;

for(var i=0;i< noOfTimes.length;i++)
{
	var currentNumber = Number(noOfTimes[i]);
    if(currentNumber==1){first=first+1;}
    else if (currentNumber==2){second = second+1;}
    else if (currentNumber==3){third = third+1;}
    else {fourth=fourth+1;}
}
totalCalories = (first*firstStrip) + (second*secondStrip) + (third*thirdStrip) + (fourth * fourthStrip);

print(totalCalories);

var values = readline().split(" ").map(x => Number(x));
print(readline().split("").reduce((acc, s) => acc + values[Number(s)-1], 0));

var values = readline().split(" ").map(function(n){return Number(n)});

var firstStrip= values[0];
var secondStrip= values[1];
var thirdStrip = values[2];
var fourthStrip = values[3];

var noOfTimes = readline();
var first=0 ;
var second=0 ;
var third=0 ;
var fourth=0;

var totalCalories=0;

for(var i=0;i< noOfTimes.length;i++)
{
	var currentNumber = Number(noOfTimes[i]);
    if(currentNumber==1){first=first+1;}
    else if (currentNumber==2){second = second+1;}
    else if (currentNumber==3){third = third+1;}
    else {fourth=fourth+1;}
}
totalCalories = (first*firstStrip) + (second*secondStrip) + (third*thirdStrip) + (fourth * fourthStrip);

print(totalCalories);

var values = readline().split(" ").map(function(n){return Number(n)});

var strips = readline();
var calories = 0;
for(var i = 0; i < strips.length; i++)
	calories += values[Number(strips[i]) - 1];

print(calories);

var values = readline().split(" ").map(x => Number(x));
var strips = readline();
var calories = strips.split("").reduce((acc, s) => acc + values[Number(s)-1], 0);
print(calories);

;(function () {

	var c = readline().split(' ').map(Number);

	print( readline().split('').reduce(function (p, e) {
		return p + c[+e - 1];
	}, 0) );

}).call(this)

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var energy = tokenizeIntegers(readline()),
		game = trim(readline()),
		calories = 0;
	for (var i = 0; i < game.length; ++i) {
		calories += energy[parseInt(game.charAt(i))-1];
	}
	print(calories);
}

main();

var res = sol(readline(), readline());
print(res);

function sol(line1, line2) {
    var calories = line1.split(" ").map((x) => Number(x));
    var strip = line2.split(" ");

    var total = 0;
    for (var i = 0; i < strip[0].length; i++) {
        total += calories[Number(strip[0].toString().charAt(i)) - 1];
    }

    return total;
}

(function() {
    'use strict';
    let n = readline().split(' ').map(Number);
    let x = readline().split('').map(Number);
    var y = 0;
    for (let i = 0; i < x.length; ++i) {
        if (x[i] === 1) {
            y += n[0];
        } else if (x[i] === 2) {
            y += n[1];
        } else if (x[i] === 3) {
            y += n[2];
        } else if (x[i] === 4) {
            y += n[3];
        }
    }
    print(y);

}());

(function () {
    var kal = readline().split(" "),
        line = readline(),
        i = 0,
        len = line.length,
        sum = 0;
    for (; i < len; i++) {
        sum += parseInt(kal[line[i] - 1]);
    }
    print(sum);
})();

var aaaa = readline();
var s = readline();
aaaa = aaaa.split(" ");
var sum = 0;
for(var i = 0; i < s.length; ++i)
{
    sum += parseInt(aaaa[parseInt(s[i])-1]);
}
print(sum);

var x = readline().split(" "),
	s = readline(),
	t = 0;
for (var i = 0; i < s.length; i++) {
    switch (parseInt(s[i])) {
        case 1: t += parseInt(x[0]);
        break;
        case 2: t += parseInt(x[1]);
        break;
        case 3: t += parseInt(x[2]);
        break;
        case 4: t += parseInt(x[3]);
        break;
	}
}
print(t);

var a = readline().split(" ");//readline();
var str = readline();
var res = 0;
		for (var i=0; i<str.length; i++){
			switch(+str[i]){
				case 1:
				res += +a[0];
				break;
				case 2:
				res += +a[1];
				break;
				case 3:
				res += +a[2];
				break;
				case 4:
				res += +a[3];
				break;
			}
		}
print(res);

var strips = readline().split(' ');
var s = readline();
var cal = 0;

for(var i = 0; i < s.length; i++){
    cal += parseInt(strips[s[i] - 1]);
}

print(cal);

var data = readline().split(' ');
var t = [];
for (var i = 0; i < data.length; ++i)
    t.push(parseInt(data[i]));
var s = readline();
var result = 0;
for (var i = 0; i < s.length; ++i)
    result += t[s[i] - 1];
write(result);

var strip_cal=readline().split(' ').map(Number);
var strips=readline().split('');
var calories=0;

for(var i=0;i<strips.length;i++){
  if(strips[i]==1){
    calories+=strip_cal[0];
  }else if(strips[i]==2){
    calories+=strip_cal[1];
  }else if(strips[i]==3){
    calories+=strip_cal[2];
  }else{
    calories+=strip_cal[3];
  }
}
print(calories);

a = readline().split(' ').map(Number)
print(readline().split('').reduce((r,x) => r + a[x-1], 0))

var tok;
var index=0;

function next(){
    while(tok==null || index==tok.length){
        tok=readline().split(' ');
        index=0;
    }
    var res=tok[index++];
    return res;
}

function nextInt(){
    return parseInt(next());
}

function main(){
    var a=[];
    for(var i=0; i<4; i++){
        a[i]=nextInt();
    }
    var s=next();
    var r=0;
    for(var i=0; i<s.length; i++){
        r+=a[s.charAt(i)-1];
    }
    print(r);
}

main();

function main(){
            var a = readline().split(' ');
            var s = readline(), i, square , cost,  answer = 0;
            for( i = 0 ;  i < s.length ; ++i){
                square = parseInt(s[i]);
                cost = parseInt(a[square-1]);
                answer += cost;
            }
            print(answer)
        }

main();

var a = readline().split(" ").map(x => parseInt(x));

var games = readline();

var calories = 0;

for (var i = 0; i < games.length; i++) {
    calories += a[parseInt(games[i]) - 1];
}

print(calories);

if (!this.readline) print = console.log, readline = require('./readline');

function readNums() {
	return readline().split(' ').map(Number);
}
print(function(a, s) {
	a.unshift(0);
	var ans = 0;

	for (var i = 0; i < s.length; i++) {
		ans += a[s[i]];
	}

	return ans;
}(readNums(), readline().split('')));

var n = readline().split(" ");
var x = 0;
readline().split("").map(function (a) {
    x+= parseInt(n[a-1]);
})
write(x)

line = readline().split(' ').map(Number);
gameStr = readline().split('').map(Number);

a1 = line[0];
a2 = line[1];
a3 = line[2];
a4 = line[3];

var res = 0;

for (var i = 0; i < gameStr.length; i++) {
	if (gameStr[i] == 1) {
		res = res + a1;
	} else if (gameStr[i] == 2) {
		res = res + a2;
	} else if (gameStr[i] == 3) {
		res = res + a3;
	} else if (gameStr[i] == 4) {
		res = res + a4;
	};
};

print(res);

var str = readline();
var s = readline();
str = str.split(' ');

function solve(a,b,c,d,str) {
  var res = 0;
  var arr = [0,a,b,c,d];
  for (var i = 0; i < str.length; i ++) res += arr[+str[i]];
  return res;
}

print(+str[0], +str[1], +str[2], +str[3], readline());

var values = readline().split(" ").map(x => Number(x) - 1);
var strips = readline();
var calories = strips.split("").reduce((acc, s) => acc + Number(s), 0);
print(calories);

var values = readline().split(" ").map(function(n){return Number(n)});

var firstStrip= values[0];
var secondStrip= values[1];
var thirdStrip = values[2];
var fourthStrip = values[3];

var noOfTimes = readline().split("").map(function(v){return Number(v)});
var first=0 ;
var second=0 ;
var third=0 ;
var fourth=0;
var number=0;

var totalCalories=0;

if(firstStrip>=0 && firstStrip <=Math.pow(10,4) && secondStrip >=0 && secondStrip <=Math.pow(10,4) && thirdStrip>=0 &&thirdStrip <=Math.pow(10,4) &&fourthStrip>=0 && fourthStrip<=Math.pow(10,4) )
{
    //take the second string line
    //count the number of repeated elements
    //multiplyit to the stripes
    //print or write it
    if(noOfTimes>=1 && noOfTimes<=Math.pow(10,5))
    {
        for(var i=0;i< noOfTimes.length;i++)
        {
            if(number[i]==1){first=first+1;}
            else if (number[i]==2){second = second+1;}
            else if (number[i]==3){third = third+1;}
            else {fourth=fourth+1;}
        }
        totalCalories = (first*firstStrip) + (second*secondStrip) + (third*thirdStrip) + (fourth * fourthStrip);

    }

}

print(totalCalories);

var values = readline().split(" ").map(function(n){return Number(n)});

var firstStrip= values[0];
var secondStrip= values[1];
var thirdStrip = values[2];
var fourthStrip = values[3];

var noOfTimes =Number(readline());
var first=0 ;
var second=0 ;
var third=0 ;
var fourth=0;
var number=0;

var totalCalories=0;

if(firstStrip>=0 && firstStrip <=Math.pow(10,4) && secondStrip >=0 && secondStrip <=Math.pow(10,4) && thirdStrip>=0 &&thirdStrip <=Math.pow(10,4) &&fourthStrip>=0 && fourthStrip<=Math.pow(10,4) )
{
    //take the second string line
    //count the number of repeated elements
    //multiplyit to the stripes
    //print or write it
    if(noOfTimes>=1 && noOfTimes<=Math.pow(10,5))
    {
        for(var i=0;i< noOfTimes.length;i++)
        {
            if(number[i]==1){first=first+1;}
            else if (number[i]==2){second = second+1;}
            else if (number[i]==3){third = third+1;}
            else {fourth=fourth+1;}
        }
        totalCalories = (first*firstStrip) + (second*secondStrip) + (third*thirdStrip) + (fourth * fourthStrip);

    }

}

print(totalCalories);

var values = readline().split(" ").map(function(n){return Number(n)});

var firstStrip= values[0];
var secondStrip= values[1];
var thirdStrip = values[2];
var fourthStrip = values[3];

var noOfTimes = readline().split(" ").map(function(v){return parseInt(v)});
var first=0 ;
var second=0 ;
var third=0 ;
var fourth=0;
var number=0;

var totalCalories=0;

if(firstStrip>=0 && firstStrip <=Math.pow(10,4) && secondStrip >=0 && secondStrip <=Math.pow(10,4) && thirdStrip>=0 &&thirdStrip <=Math.pow(10,4) &&fourthStrip>=0 && fourthStrip<=Math.pow(10,4) )
{
    //take the second string line
    //count the number of repeated elements
    //multiplyit to the stripes
    //print or write it
    if(noOfTimes>=1 && noOfTimes<=Math.pow(10,5))
    {
        for(var i=0;i< noOfTimes.length;i++)
        {
            if(number[i]==1){first=first+1;}
            else if (number[i]==2){second = second+1;}
            else if (number[i]==3){third = third+1;}
            else {fourth=fourth+1;}
        }
        totalCalories = (first*firstStrip) + (second*secondStrip) + (third*thirdStrip) + (fourth * fourthStrip);

    }

}

print(totalCalories);

var values = readline().split(" ").map(function(n){return Number(n)});

var firstStrip= values[0];
var secondStrip= values[1];
var thirdStrip = values[2];
var fourthStrip = values[3];

var noOfTimes =parseInt( readline());
var first=0 ;
var second=0 ;
var third=0 ;
var fourth=0;
var number=0;

var totalCalories=0;

if(firstStrip>=0 && firstStrip <=Math.pow(10,4) && secondStrip >=0 && secondStrip <=Math.pow(10,4) && thirdStrip>=0 &&thirdStrip <=Math.pow(10,4) &&fourthStrip>=0 && fourthStrip<=Math.pow(10,4) )
{
    //take the second string line
    //count the number of repeated elements
    //multiplyit to the stripes
    //print or write it
    if(noOfTimes>=1 && noOfTimes<=Math.pow(10,5))
    {
        for(var i=0;i< noOfTimes.length;i++)
        {
            if(number[i]==1){first=first+1;}
            else if (number[i]==2){second = second+1;}
            else if (number[i]==3){third = third+1;}
            else {fourth=fourth+1;}
        }
        totalCalories = (first*firstStrip) + (second*secondStrip) + (third*thirdStrip) + (fourth * fourthStrip);

    }

}

print(totalCalories);

var values = readline().split(" ").map(function(n){return Number(n)});

var firstStrip= values[0];
var secondStrip= values[1];
var thirdStrip = values[2];
var fourthStrip = values[3];

var noOfTimes = readline().split("").map(function(v){return parseInt(v,10)});
var first=0 ;
var second=0 ;
var third=0 ;
var fourth=0;
var number=0;

var totalCalories=0;

if(firstStrip>=0 && firstStrip <=Math.pow(10,4) && secondStrip >=0 && secondStrip <=Math.pow(10,4) && thirdStrip>=0 &&thirdStrip <=Math.pow(10,4) &&fourthStrip>=0 && fourthStrip<=Math.pow(10,4) )
{
    //take the second string line
    //count the number of repeated elements
    //multiplyit to the stripes
    //print or write it
    if(noOfTimes>=1 && noOfTimes<=Math.pow(10,5))
    {
        for(var i=0;i< noOfTimes.length;i++)
        {
            if(number[i]==1){first=first+1;}
            else if (number[i]==2){second = second+1;}
            else if (number[i]==3){third = third+1;}
            else {fourth=fourth+1;}
        }
        totalCalories = (first*firstStrip) + (second*secondStrip) + (third*thirdStrip) + (fourth * fourthStrip);

    }

}

print(totalCalories);

(function() {
    'use strict';
    let n = readline().split(' ').map(Number);
    let x = readline().split('').map(Number);
    var y = 0;
    for (let i = 0; i < x.length; ++i) {
        if (x[i] === 1) {
            y += 1;
        } else if (x[i] === 2) {
            y += 2;
        } else if (x[i] === 3) {
            y += 3;
        } else if (x[i] === 4) {
            y += 4;
        }
    }
    print(y);

}());

(function () {
    var kal = readline().split(" "),
        line = readline(),
        i = 0,
        len = line.length,
        sum = 0;
    for (; i < len; i++) {
        sum += kal[line[i] - 1];
    }
    print(sum);
})();


;(function () {

	var s = readline().split(' ').map(Number);
	print( s[0] + s[1] - 1 );

	for (var i = 1; i <= s[0]; i++) print( i + ' ' + 1);

	for (var i = 2; i <= s[1]; i++) print( 1 + ' ' + i);

}).call(this)

print(function(n, m){
	var ans=[n+m-1];
	for(var i=1; i<=m; i++){
		ans.push('1 '+i);
	}
	for(var i=2; i<=n; i++){
		ans.push(i+' '+m);
	}
	return ans.join('\n');
}.apply(0, readline().split(' ').map(Number)));

;(function () {

	var s = readline().split(' ').map(Number);
	print( s[0] + s[1] - 1 );

	for (var i = 1; i <= s[0]; i++) print( 1 + ' ' + i);

	for (var i = 2; i <= s[1]; i++) print( i + ' ' + 1);

}).call(this)


'use strict';
 /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
  rl.on('line', line => {
      lines.push(line);
  });
  rl.on('close', main)
}
let rli = 0;
function readline() {
    return lines[rli++];
}
const L = process.env.DEBUG ? console.log : ()=>{};

module.exports = E;
const ra = ()=>readline().split(' ').map(a=>+a)

const calc = (s, n)=>{
  let bool = new Array(n).fill(0);
  for (let i=0; i<n; i++){
    if (s[i]=='W'){
      bool[i] = 1;
      continue;
    }
    let j = i;
    let has_r, has_b;
    while (s[j]=='R' || s[j]=='B'){
      if (s[j]=='R')
        has_r = true;
      if (s[j]=='B')
        has_b = true;
      j++;
    }
    if (!has_r || !has_b){
      return false;
    }
    i = j;
  }
  return true;
};

function main() {
    let T = +readline()
    while (T--){
      let [n] = ra();
      let s = readline();
      L('Ans:')
      print(calc(s, n) ? 'yes' : 'no');
    }
}

E.calc = calc;

var t = parseInt(readline());

while (t --> 0) {
	readline();
	var s = readline();
	var arr = s.split('W');
	var r = true;

	for (var i = 0; i < arr.length; i++) {
		var cnt = {};
		for (var j = 0; j < arr[i].length; j++) {
			cnt[arr[i][j]] = cnt[arr[i][j]] ? cnt[arr[i][j]] + 1 : 0;
		}

		if ((cnt['R'] == 0 && cnt['B'] != 0) || (cnt['R'] != 0 && cnt['B'] == 0)) {
			r = false;
			break;
		}
	}

	if (r) print("YES");
	else print("NO");
}

var t = +readline()

for(var i = 0; i< t; i ++) {
    var a = readline()
    var arr1 = readline();
    print(MultiColor(arr1));
}

function MultiColor(s) {

   var n = s.length;
   var flag = true;
   for (var i = 0; i < n; i++)
   {
       if (s[i] == 'W')
           continue;
       else
       {
           var j = i, cr = 0, cb = 0;
           while (j < n && s[j] != 'W')
           {
               if (s[j] == 'R')
                   cr++;
               else if (s[j] == 'B')
                   cb++;

               j++;
           }

           if (cr === 0 || cb === 0)
           {
               flag = false;
           }

           i = j - 1;
       }
   }

   if (flag)
       return 'YES';
   else
       return 'No'
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function main() {
    let t = readline();
    while(t--) {

        let [l, s] = [Number(readline()), readline()], arr = [];

        if(l === 1) {
            if(s === "W") console.log("YES");
            else console.log("NO");
        }

        if(l === 2) {
            if(s === "WW" || s === "BR" || s === "RB") console.log("YES");
            else console.log("NO");
        }

        if(2 < l) {
            s = verif(s);
            if(!s) console.log("NO");
            else {
                if(!s[0]) console.log("YES");
                else {
                    arr = createArr(s);
                    arr = arr.map((str, index) => {
                        str = stampFromLtoR(str, s[index]);
                        return stampFromRtoL(str, s[index]).join("");
                    });

                    if(arr.join("") === s.join("")) console.log("YES");
                    else console.log("NO");
                }
            }
        }
    }
}

function verif(str) {

    str = str.replace(/^W+/, '').replace(/W+$/, '');

    const arr = str.split(/W+/g);

    for(const el of arr) {
        if(el.length === 1) return false;
    }

    return arr;

}

function createArr(arr) {
    return arr.map(str => Array(str.length).fill("W"));
}

function stamp(color) {
    return (color === "B") ? "R" : "B";
}

function stampFromLtoR(str, s) {

    for(let i = 0; i < str.length - 1; i++) {
        if(str[i] !== s[i]) {
            str[i] = s[i];
            str[i + 1] = stamp(s[i]);
        }
    }

    return str;
}

function stampFromRtoL(str, s) {

    for(let i = str.length - 1; i > 0; i--) {
        if(str[i] !== s[i]) {
            str[i] = s[i];
            str[i - 1] = stamp(s[i]);
        }
    }

    return str;
}

const solve = (arr,n)=>{
	let res = arr.split("W");
	for(let i=0;i<res.length;i++){
		if((res[i]!=="")&&((res[i].length<1)||(res[i].indexOf("R")===-1)||(res[i].indexOf("B")===-1))){
			return "NO";
		}
	}
	return "YES";
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       let arr = readline().trim();
       console.log(solve(arr,n));
  }
}
main();

/**
 * Author : Fazlul Hoque
 * Node.js version : 12.16.3
 * command : node fileName.js <input.txt >output.txt
 */
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = ""; //An array of  raw inputs (includes 'n,\r , not usable. need to process before use)
let currentLine = 0; //input sequence controller variable.

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main(); // after input
});

/********** Utility Functions Start **********/
/**
 *  read row Input
 * @returns string
 */
function _readRawLine() {
    return inputString[currentLine++];
}
function readLine(){
    // return _readRawLine().replace(/\s+$/g, '');
    return _readRawLine().replace('\r', '');
}

function print(x) {
    console.log(x);
}

function readSingleInt() {
    const p = readLine();
    return parseInt(p);
}

function readIntArray() {
    return readLine().split(" ").map((v) => parseInt(v));
}

function readArray() {
    return readLine().split(" ");
}

function int(n) {
    return parseInt(n);
}
/********** Utility Functions End **********/
/**
 * Don't Touch this fucntion at all , unless you know what are you doing!
 */
function main() {
    solve();
}

// ********** actual Code Starts from here **********

function solve() {
    let t = readSingleInt();
    let n ,st;
    while(t--){
        n = readSingleInt();
        st = readLine();
        let flag = true;
        let nr = st.split('W').filter((v)=> v.length);
        // console.log(nr)
        for(let i=0;i<nr.length;i++){

            let crnt = (nr[i].includes('R') && nr[i].includes('B'));
            if(!crnt){
                flag = false;
                break;
            }

        }
        if(flag){
            console.log("YES");
        }else{
            console.log("NO");
        }
    }

}

/**
 * Author : Fazlul Hoque
 * Node.js version : 12.16.3
 * command : node fileName.js <input.txt >output.txt
 */
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = ""; //An array of  raw inputs (includes 'n,\r , not usable. need to process before use)
let currentLine = 0; //input sequence controller variable.

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main(); // after input
});

/********** Utility Functions Start **********/
/**
 *  read row Input
 * @returns string
 */
function _readRawLine() {
    return inputString[currentLine++];
}
function readLine(){
    // return _readRawLine().replace(/\s+$/g, '');
    return _readRawLine().replace('\r', '');
}

function print(x) {
    console.log(x);
}

function readSingleInt() {
    const p = readLine();
    return parseInt(p);
}

function readIntArray() {
    return readLine().split(" ").map((v) => parseInt(v));
}

function readArray() {
    return readLine().split(" ");
}

function int(n) {
    return parseInt(n);
}
/********** Utility Functions End **********/
/**
 * Don't Touch this fucntion at all , unless you know what are you doing!
 */
function main() {
    solve();
}

// ********** actual Code Starts from here **********

function solve() {
    let t = readSingleInt();
    let n ,st;
    while(t--){
        n = readSingleInt();
        st = readLine();
        let flag = true;
        let nr = st.split('W').filter((v)=> v.length);
        // console.log(nr)
        for(let i=0;i<nr.length;i++){
            // console.log(nr[i]);
            let crnt = (nr[i].includes('R') && nr[i].includes('B'));
            if(!crnt){
                flag = false;
                break;
            }

        }
        if(flag){
            console.log("YES");
        }else{
            console.log("NO");
        }
    }

}

/**
 * Author : Fazlul Hoque
 * Node.js version : 12.16.3
 * command : node fileName.js <input.txt >output.txt
 */
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = ""; //An array of  raw inputs (includes 'n,\r , not usable. need to process before use)
let currentLine = 0; //input sequence controller variable.

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main(); // after input
});

/********** Utility Functions Start **********/
/**
 *  read row Input
 * @returns string
 */
function _readRawLine() {
    return inputString[currentLine++];
}
function readLine(){
    // return _readRawLine().replace(/\s+$/g, '');
    return _readRawLine().replace('\r', '');
}

function print(x) {
    console.log(x);
}

function readSingleInt() {
    const p = readLine();
    return parseInt(p);
}

function readIntArray() {
    return readLine().split(" ").map((v) => parseInt(v));
}

function readArray() {
    return readLine().split(" ");
}

function int(n) {
    return parseInt(n);
}
/********** Utility Functions End **********/
/**
 * Don't Touch this fucntion at all , unless you know what are you doing!
 */
function main() {
    solve();
}

// ********** actual Code Starts from here **********

function solve() {
    let t = readSingleInt();
    let n ,st;
    while(t--){
        n = readSingleInt();
        st = readLine();
        let flag = true;
        let nr = st.split('W').filter((v)=> v.length);
        // console.log(nr)
        for(let i=0;i<nr.length;i++){
            // console.log(nr[i]);
            let crnt = (nr[i].includes('R') && nr[i].includes('B'));
            if(!crnt){
                flag = false;
            }

        }
        if(flag){
            console.log("YES");
        }else{
            console.log("NO");
        }
    }

}

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function solve(n, a) {
  const strs = a.split('W');
  for (let str of strs) {
    let b = 0,
        r = 0;
    for (let char of str) {
      if (char === 'B') b++;else r++;
    }
    if (b !== 0 && r === 0 || b === 0 && r !== 0) {
      console.log('NO');
      return;
    }
  }
  console.log('YES');
}

async function main(read) {
  const t = Number(await read());
  for (let i = 0; i < t; i++) {
    const n = Number(await read());
    const a = await read();
    solve(n, a);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', (inputStdin) => {
  inputString += inputStdin;
});

process.stdin.on('end', (_) => {
  inputString = inputString
    .trim()
    .split('\n')
    .map((string) => {
      return string.trim();
    });

  main();
});

function readline() {
  return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  let _t = parseInt(readline());
  // let _t = 1;
  while (_t--) {
    let n = parseInt(readline());
    let s = readline();
    s = s.split('W').filter((e) => e.length > 0);
    let ans = true;
    s.forEach((e) => {
      ans &= (e.indexOf('B') >= 0) & (e.indexOf('R') >= 0);
    });
    console.log(ans ? 'YES' : 'NO');
  }
}

// cat input.txt | node main.js

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const str = lines[l++]
        output[i] = solve(n, str) ? 'YES' : 'NO'
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, str) {
    let b = 0
    let r = 0
    for (let i = 0; i < str.length; i++) {
        const x = str[i]
        if (x === 'B') {
            b = 1
        } else if (x === 'R') {
            r = 1
        } else {
            if (b && !r) return false
            if (!b && r) return false
            b = 0
            r = 0
        }
    }
            if (b && !r) return false
            if (!b && r) return false
    return true
}

var stdin_input = "";
var stdin_input_itr;
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { stdin_input_itr = stdin_input.split('\n').values(); main(); });

const rl = () => stdin_input_itr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function main () {
	let T = rn();
	while (T--) {
		let n = rn();
		const a = 'W' + rl();
		n++;

		let ok = 1;
		for (let i = 0; i < n; i++) {
			if (a[i] == 'W') {
				let cnt = 0, change = 0;
				for (j = i + 1; j < n && a[j] != 'W'; j++) {
					cnt++;
					change |= j - 1 > i && a[j] != a[j-1];
				}
				if (cnt && !change) ok = 0;
			}
		}

		console.log(ok ? 'YES' : 'NO');
	}
}

const symMap = {
    'R': 0,
    'B': 1
}

const processData = (lines) => {
    let count = +lines[0]
    let cur = 0
    while(count--) {
        cur++
        // let [n] = lines[cur].split(' ').map(x => +x)
        cur++
        let str = lines[cur]

        let isOk = true
        let curSet = [0, 0]
        let isIn = false
        for (let i=0;i <str.length; i++) {
            if (isIn) {
                if (str[i] == 'W') {
                    isIn = false
                    if (curSet[0] == 0 || curSet[1] == 0) {
                        isOk = false
                        break
                    }
                } else {
                    curSet[symMap[str[i]]]++
                }
            } else {
                if (str[i] != 'W') {
                    isIn = true;
                    curSet = [0, 0]
                    curSet[symMap[str[i]]]++
                }
            }
        }
        if (isOk && isIn && (curSet[0] == 0 || curSet[1] == 0)) {
            isOk = false;
        }
        console.log(isOk ? 'YES' : 'NO');
    }
}

let i = []
process.stdin.on('data', c => i.push(c))
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.join('').split(EOL) /*your input text, split by lines*/
    processData(lines)
})

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a);

function div(val, by){
    return (val - val % by) / by;
}

const calc = (n, s)=>{
    let segments = s.split('W');
    // console.log('DEBUG segments', segments);
    for (const seg of segments) {
        if (seg.length === 1) return 'NO';
        if (seg.length === 0) continue;
        let rcount = 0;
        let bcount = 0;
        for (let i = 0; i < seg.length; i++) {
            if (seg[i] === 'R') rcount++;
            if (seg[i] === 'B') bcount++;
        }
        if (rcount === 0 || bcount === 0) return 'NO';
    }

    return "YES";
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let n = +readline();
        let s = readline();
        console.log(`${calc(n, s)}`);
    }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt() + 1;
		var S = next() + "W";
		var R = 0;
		var B = 0;
		var ok = true;
		for(var i = 0; i < N; i++){
			if(S[i] == "W"){
				if((R > 0 && B > 0) || (R == 0 && B == 0)){
					R = 0;
					B = 0;
					continue;
				}else{
					ok = false;
					break;
				}
			}else{
				if(S[i] == "R"){
					R++;
				}else{
					B++;
				}
			}
		}
		if(ok){
			myout("YES");
		}else{
			myout("NO");
		}
	}
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function main() {
    let t = readline();
    while(t--) {

        let [l, s] = [Number(readline()), readline()], arr = [];

        if(l === 1) {
            if(s === "W") console.log("YES");
            else console.log("NO");
        }

        if(l === 2) {
            if(s == "WW") console.log("YES");
            else console.log("NO");
        }

        if(2 < l) {
            s = verif(s);
            if(!s) console.log("NO");
            else {
                if(!s[0]) console.log("YES");
                else {
                    arr = createArr(s);
                    arr = arr.map((str, index) => {
                        str = stampFromLtoR(str, s[index]);
                        return stampFromRtoL(str, s[index]).join("");
                    });

                    if(arr.join("") === s.join("")) console.log("YES");
                    else console.log("NO");
                }
            }
        }
    }
}

function verif(str) {

    str = str.replace(/^W+/, '').replace(/W+$/, '');

    const arr = str.split(/W+/g);

    for(const el of arr) {
        if(el.length === 1) return false;
    }

    return arr;

}

function createArr(arr) {
    return arr.map(str => Array(str.length).fill("W"));
}

function stamp(color) {
    return (color === "B") ? "R" : "B";
}

function stampFromLtoR(str, s) {

    for(let i = 0; i < str.length - 1; i++) {
        if(str[i] !== s[i]) {
            str[i] = s[i];
            str[i + 1] = stamp(s[i]);
        }
    }

    return str;
}

function stampFromRtoL(str, s) {

    for(let i = str.length - 1; i > 0; i--) {
        if(str[i] !== s[i]) {
            str[i] = s[i];
            str[i - 1] = stamp(s[i]);
        }
    }

    return str;
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function main() {
    let t = readline();
    while(t--) {

        let [l, s] = [Number(readline()), readline()], arr = [];

        if(l === 1) {
            if(s === "W") console.log("YES");
            else console.log("NO");
        }

        if(l === 2) {
            if(s == "WW") console.log("YES");
            else console.log("NO");
        }

        if(2 < l) {
            s = verif(s);
            if(!s) console.log("NO");
            else {
                if(!s[0]) console.log("YES");
                else {
                    arr = createArr(s);
                    arr = arr.map((str, index) => {
                        str = stampFromLtoR(str, s[index]);
                        return stampFromRtoL(str, s[index]).join("");
                    });

                    if(arr.join("") === s.join("")) console.log("YES");
                    else console.log("NO");
                }
            }
        }
    }
}

function verif(str) {

    str = str.replace(/^W+/, '').replace(/W+$/, '');

    const arr = str.match(/W+/g);

    if((arr === null) || (arr.indexOf("W") === -1)) return str.split(/W+/g);

    return false;

}

function createArr(arr) {
    return arr.map(str => Array(str.length).fill("W"));
}

function stamp(color) {
    return (color === "B") ? "R" : "B";
}

function stampFromLtoR(str, s) {

    for(let i = 0; i < str.length - 1; i++) {
        if(str[i] !== s[i]) {
            str[i] = s[i];
            str[i + 1] = stamp(s[i]);
        }
    }

    return str;
}

function stampFromRtoL(str, s) {

    for(let i = str.length - 1; i > 0; i--) {
        if(str[i] !== s[i]) {
            str[i] = s[i];
            str[i - 1] = stamp(s[i]);
        }
    }

    return str;
}

const solve = (arr,n)=>{
	let i,j;
	if(arr.length===1) return "NO";
	for(i=0;i<n;i++){
		if(arr[i]==="W"){
			if(i===0) break;
			if(i<2) return "NO";
			break;
		}
	}
	for(j=i+1;j<n;j++){
		if(arr[j]==="W"){
			if((j-i-1)%2===1) return "NO";
			i=j;
		}
	}
	if(j-i-1===1) return "NO";
	return "YES";
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       let arr = readline().trim();
       console.log(solve(arr,n));
  }
}
main();

const solve = (arr,n)=>{
     if(arr.length===1) return "NO";
     if((n>2)&&((arr.indexOf("W")===-1)||arr.indexOf("W")===n-1)) return "YES";
     let res = arr.split("W"),flag = 0;
     for(let i=0;i<res.length;i++){
          if((res[i]!=="")&&((res[i].length)%2===1)) return "NO";
     }
     return "YES";
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       let arr = readline().trim();
       console.log(solve(arr,n));
  }
}
main();

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function solve(a) {
  const map = new Map();
  const get = char => char.charCodeAt(0) - 97;
  let res = 0n;
  for (let [l, r] of a) {
    var _map$get, _map$get2, _map$get3, _map$get4, _map$get5, _map$get6;
    let statel = 1 << get(l),
        stater = 1 << get(r) + 11,
        state = statel | stater;
    res = res + ((_map$get = map.get(statel)) !== null && _map$get !== void 0 ? _map$get : 0n) + ((_map$get2 = map.get(stater)) !== null && _map$get2 !== void 0 ? _map$get2 : 0n) - ((_map$get3 = map.get(state)) !== null && _map$get3 !== void 0 ? _map$get3 : 0n) * 2n;
    map.set(statel, ((_map$get4 = map.get(statel)) !== null && _map$get4 !== void 0 ? _map$get4 : 0n) + 1n);
    map.set(stater, ((_map$get5 = map.get(stater)) !== null && _map$get5 !== void 0 ? _map$get5 : 0n) + 1n);
    map.set(state, ((_map$get6 = map.get(state)) !== null && _map$get6 !== void 0 ? _map$get6 : 0n) + 1n);
  }
  console.log(res.toString());
}

async function main(read) {
  let t = Number(await read());
  while (t--) {
    let n = Number(await read()),
        a = [];
    while (n--) {
      a.push(await read());
    }
    solve(a);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function solve(n, a) {
  if (n < 2) {
    console.log('NO');
    return;
  }
  const strs = a.split('W');
  for (let str of strs) {
    let b = 0,
        r = 0;
    for (let char of str) {
      if (char === 'B') b++;else r++;
    }
    if (b !== 0 && r === 0 || b === 0 && r !== 0) {
      console.log('NO');
      return;
    }
  }
  console.log('YES');
}

async function main(read) {
  const t = Number(await read());
  for (let i = 0; i < t; i++) {
    const n = Number(await read());
    const a = await read();
    solve(n, a);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();