Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard.You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.

The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.

If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes). Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct. If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair. Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.

var searchWithRecursion = function(el1, el2, arr1, arr2, arrRes)
{
	var indexEl2InArr1, indexEl1InArr2,indexSimilarToEl1, indexSimilarToEl2,  i = 0;
	while (i < arr1.length)
	{

		indexSimilarToEl1 = arr1.indexOf(el1);
		indexSimilarToEl2 = arr2.indexOf(el2);

		while ((indexSimilarToEl1 !== -1) || (indexSimilarToEl2 !== -1))
		{
			indexSimilarToEl1 = arr1.indexOf(el1);
			indexSimilarToEl2 = arr2.indexOf(el2);

			if ((indexSimilarToEl1 === indexSimilarToEl2) && ((indexSimilarToEl2 !== -1) && (indexSimilarToEl2 !== -1)))
				{
					arr1.splice(indexSimilarToEl1, 1);
					arr2.splice(indexSimilarToEl2, 1);
				}
			else if (indexSimilarToEl1 !== indexSimilarToEl2)
				{
					return -1;
				}
			else if ((indexSimilarToEl2 === -1) && (indexSimilarToEl2 === -1)) break;
		}

		indexEl2InArr1 = arr1.indexOf(el2);
		indexEl1InArr2 = arr2.indexOf(el1);

		if ((indexEl1InArr2 === -1) && (indexEl2InArr1 === -1)) break;
		if ((indexEl2InArr1 !== indexEl1InArr2) || ((arr1[indexEl2InArr1] === arr2[indexEl1InArr2]) && (indexEl1InArr2 === indexEl2InArr1))) return -1;
		else
			{
				arr1.splice(indexEl2InArr1, 1);
				arr2.splice(indexEl1InArr2, 1);
			}

	}
	if (el1 !== el2)
		return [el1, el2];
	else return 0;
}

var main = function(arr1, arr2)
{
	var el1,
		el2,
		arrRes = [];
	while (arr1.length !== 0)
	{
		el1 = arr1[0];
		el2 = arr2[0];
		arr1.splice(0, 1);
		arr2.splice(0, 1);
		arrRes.push(searchWithRecursion(el1, el2, arr1, arr2, arrRes));
		if (arrRes[arrRes.length - 1] === -1)
			{
				print(-1);
				return 0;
			}
		else if (arrRes[arrRes.length - 1] === 0) arrRes.splice(arrRes.length - 1, 1);
	}
	print(arrRes.length);
	for (var i = 0; i <= arrRes.length - 1; i++)
	{
		print(arrRes[i].join(' '));
	}
}
{
	var input1 = readline().split(''),
		input2 = readline().split('');
	main(input1, input2);
}

function sa(s1, s2){
        var res = [];
        var data = {};
         for(var i=0;i<s1.length;i++){
             if(s1[i]==s2[i]){
                 if(!data[s1[i]] || data[s1[i]] ==s2[i]){
                     data[s1[i]] = s2[i]
                    continue;
                 } else {
                     return -1;
                 }
             }
             var key = s2[i];
             var val = s1[i];

             if((data[val] && data[val] !== key) || (data[key] && data[key] !== val)){
                 return -1;
             } else {
                 if(!data[key]){
                     res.push([key, val])
                     data[key] = val;
                     data[val] = key;
                 }
             }

         }
         var r = res.length + "\n";
         for(var i=0;i<res.length;i++){
             r += res[i][0] +" " + res[i][1] + "\n";
         }
        return r;
    }

    var s1 = readline();
    var s2 = readline();
    print(sa(s1, s2));

var searchWithRecursion = function(el1, el2, arr1, arr2, arrRes)
{
	var indexEl2InArr1, indexEl1InArr2,indexSimilarToEl1, indexSimilarToEl2,  i = 0;
	while (i < arr1.length)
	{

		indexSimilarToEl1 = arr1.indexOf(el1);
		indexSimilarToEl2 = arr2.indexOf(el2);

		while ((indexSimilarToEl1 !== -1) || (indexSimilarToEl2 !== -1))
		{
			indexSimilarToEl1 = arr1.indexOf(el1);
			indexSimilarToEl2 = arr2.indexOf(el2);

			if ((indexSimilarToEl1 === indexSimilarToEl2) && ((indexSimilarToEl2 !== -1) && (indexSimilarToEl2 !== -1)))
				{
					arr1.splice(indexSimilarToEl1, 1);
					arr2.splice(indexSimilarToEl2, 1);
				}
			else if (indexSimilarToEl1 !== indexSimilarToEl2)
				{
					return -1;
				}
			else if ((indexSimilarToEl2 === -1) && (indexSimilarToEl2 === -1)) break;
		}

		indexEl2InArr1 = arr1.indexOf(el2);
		indexEl1InArr2 = arr2.indexOf(el1);

		if ((indexEl1InArr2 === -1) && (indexEl2InArr1 === -1)) break;
		if ((indexEl2InArr1 !== indexEl1InArr2)) return -1;
		else
			{
				arr1.splice(indexEl2InArr1, 1);
				arr2.splice(indexEl1InArr2, 1);
			}

	}
	if (el1 !== el2)
		return [el1, el2];
	else return 0;
}

var main = function(arr1, arr2)
{
	var el1,
		el2,
		arrRes = [];
	while (arr1.length !== 0)
	{
		el1 = arr1[0];
		el2 = arr2[0];
		arr1.splice(0, 1);
		arr2.splice(0, 1);
		arrRes.push(searchWithRecursion(el1, el2, arr1, arr2, arrRes));
		if (arrRes[arrRes.length - 1] === -1)
			{
				print(-1);
				return 0;
			}
		else if (arrRes[arrRes.length - 1] === 0) arrRes.splice(arrRes.length - 1, 1);
	}
	print(arrRes.length);
	for (var i = 0; i <= arrRes.length - 1; i++)
	{
		print(arrRes[i].join(' '));
	}
}
{
	var input1 = readline().split(''),
		input2 = readline().split('');
	main(input1, input2);
}

var checking = function(arrRes, el1, el2)
{
	for (var i = 0; i <= arrRes.length - 1; i++)
	{
		if (((arrRes[i][0] === el1) && (arrRes[i][1] === el2)) || ((arrRes[i][0] === el2) && (arrRes[i][1] === el1))) return false;
	}
	return true;
}
var main = function(arr1,arr2)
{
	var arrRes = [], result = 0;
	for (var i = 0 ; i <= arr1.length - 1; i++)
	{
		for (var i1 = i + 1; i1 <= arr2.length - 1; i1++)
		{
			if ((arr1[i] === arr2[i1]) ^ (arr2[i] === arr1[i1])){
				print(-1);
				break;
			}
		}

	}
	i = 0;
	while (i < arr1.length)
	{
		dopIndex = arr1.indexOf(arr2[i]);
		dopIndexAdd = arr2.indexOf(arr1[i]);
		if ((dopIndex === -1) && (dopIndexAdd === -1))
		{
			arrRes.push([arr1[i], arr2[i]]);
		}
		else if ((arr1[i] === arr2[dopIndex]) && (checking(arrRes, arr1[i], arr2[i])) && (arr1[i] !== arr2[i]))
			{
				arrRes.push([arr1[i], arr2[i]]);
			}
		i++;
	}
	print(arrRes.length);
	for (i = 0; i <= arrRes.length - 1; i++)
	{
		print(arrRes[i].join(' '));
	}
}
{
    var input1 = readline().split('');
    var input2 = readline().split('');
    main(input1, input2);
}

var main = function(arr1,arr2)
{
	var arrRes = [], result = 0;
	for (var i = 0 ; i <= arr1.length - 1; i++)
	{
		for (var i1 = i + 1; i1 <= arr2.length - 1; i1++)
		{
			if ((arr1[i] === arr2[i1]) ^ (arr2[i] === arr1[i1]))
			{
                print(-1);
				return -1;
			}
		}

	}
	i = 0;
	while (i < arr1.length)
	{
		dopIndex = arr1.indexOf(arr2[i]);
		dopIndexAdd = arr2.indexOf(arr1[i]);
		if ((dopIndex === -1) && (dopIndexAdd === -1))
		{
			arrRes.push([arr1[i], arr2[i]]);
		}
		else if ((arr1[i] === arr2[dopIndex]) && ((arr1[i] !== arr2[i])))
			{
				arrRes.push([arr1[i], arr2[i]]);
			}
		i++;
	}
	for (i = 0; i < arrRes.length - 1; i++)
	{
		for (var i1 = i + 1; i1 <= arrRes.length - 1; i1++)
		{
				if (((arrRes[i][0] === arrRes[i1][0]) && (arrRes[i][1] === arrRes[i1][1])) || ((arrRes[i][0] === arrRes[i1][1]) && (arrRes[i][1] === arrRes[i1][0])))
				{
					arrRes.splice(i1, 1);
					i1--;
				}
		}
	}
	print(arrRes.length);
	for (i = 0; i < arrRes.length; i++)
	{
		print(arrRes[i].join(' '));
	}
}
{
    var input1 = readline().split('');
    var input2 = readline().split('');
    main(input1, input2);
}

var checking = function(arrRes, el1, el2)
{
	for (var i = 0; i <= arrRes.length - 1; i++)
	{
		if (((arrRes[i][0] === el1) && (arrRes[i][1] === el2)) || ((arrRes[i][0] === el2) && (arrRes[i][1] === el1))) return false;
	}
	return true;
}
var main = function(arr1,arr2)
{
	var arrRes = [], result = 0;
	for (var i = 0 ; i <= arr1.length - 1; i++)
	{
		for (var i1 = i + 1; i1 <= arr2.length - 1; i1++)
		{
			if ((arr1[i] === arr2[i1]) ^ (arr2[i] === arr1[i1])){
				print(-1);
				break;
			}
		}

	}
	i = 0;
	while (i < arr1.length)
	{
		dopIndex = arr1.indexOf(arr2[i]);
		dopIndexAdd = arr2.indexOf(arr1[i]);
		if ((dopIndex === -1) && (dopIndexAdd === -1))
		{
			arrRes.push([arr1[i], arr2[i]]);
		}
		else if ((arr1[i] === arr2[dopIndex]) && (checking(arrRes, arr1[i], arr2[i])) && (arr1[i] !== arr2[i]))
			{
				result++;
				arrRes.push([arr1[i], arr2[i]]);
			}
		i++;
	}
	print(result);
	for (i = 0; i <= arrRes.length - 1; i++)
	{
		print(arrRes[i].join(' '));
	}
}
{
    var input1 = readline().split('');
    var input2 = readline().split('');
    main(input1, input2);
}

var checking = function(arrRes, el1, el2)
{
	for (var i = 0; i <= arrRes.length - 1; i++)
	{
		if (((arrRes[i][0] === el1) && (arrRes[i][1] === el2)) || ((arrRes[i][0] === el2) && (arrRes[i][1] === el1))) return false;
	}
	return true;
}
var main = function(arr1,arr2)
{
	var arrRes = [], result = 0;
	for (var i = 0 ; i <= arr1.length - 1; i++)
	{
		for (var i1 = i + 1; i1 <= arr2.length - 1; i1++)
		{
			if ((arr1[i] === arr2[i1]) ^ (arr2[i] === arr1[i1])){
				print(-1);
				return 0;
			}
		}

	}
	i = 0;
	while (i < arr1.length)
	{
		dopIndex = arr1.indexOf(arr2[i]);
		dopIndexAdd = arr2.indexOf(arr1[i]);
		if ((dopIndex === -1) && (dopIndexAdd === -1))
		{
			arrRes.push([arr1[i], arr2[i]]);
		}
		else if ((arr1[i] === arr2[dopIndex]) && (checking(arrRes, arr1[i], arr2[i])) && (arr1[i] !== arr2[i]))
			{
				arrRes.push([arr1[i], arr2[i]]);
			}
		i++;
	}
	print(arrRes.length);
	for (i = 0; i <= arrRes.length - 1; i++)
	{
		print(arrRes[i].join(' '));
	}
}
{
    var input1 = readline().split('');
    var input2 = readline().split('');
    main(input1, input2);
}

var searchWithRecursion = function(el1, el2, arr1, arr2, arrRes)
{
	var indexEl2InArr1, indexEl1InArr2,indexSimilarToEl1, indexSimilarToEl2,  i = 0;
	while (i < arr1.length)
	{
		indexSimilarToEl1 = arr1.indexOf(el1);
		indexSimilarToEl2 = arr2.indexOf(el2);

		while ((indexSimilarToEl1 !== -1) && (indexSimilarToEl2 !== -1))
		{
			indexSimilarToEl1 = arr1.indexOf(el1);
			indexSimilarToEl2 = arr2.indexOf(el2);

			if ((indexSimilarToEl1 === indexSimilarToEl2) && ((indexSimilarToEl2 !== -1) && (indexSimilarToEl2 !== -1)))
				{
					arr1.splice(indexSimilarToEl1, 1);
					arr2.splice(indexSimilarToEl2, 1);
				}
			else if (indexSimilarToEl1 !== indexSimilarToEl2)
				{
					return -1;
				}
		}

		indexEl2InArr1 = arr1.indexOf(el2);
		indexEl1InArr2 = arr2.indexOf(el1);

		if ((indexEl1InArr2 === -1) && (indexEl2InArr1 === -1)) break;
		if ((indexEl2InArr1 !== indexEl1InArr2) || ((arr1[indexEl2InArr1] === arr2[indexEl1InArr2]) && (indexEl1InArr2 === indexEl2InArr1))) return -1;
		else
			{
				arr1.splice(indexEl2InArr1, 1);
				arr2.splice(indexEl1InArr2, 1);
			}

	}
	return [el1, el2];
}

var main = function(arr1, arr2)
{
	var el1,
		el2,
		arrRes = [];
	while (arr1.length !== 0)
	{
		el1 = arr1[0];
		el2 = arr2[0];
		arr1.splice(0, 1);
		arr2.splice(0, 1);
		if (el1 !== el2)
			arrRes.push(searchWithRecursion(el1, el2, arr1, arr2, arrRes));
		if (arrRes[arrRes.length - 1] === -1)
			{
				print(-1);
				return 0;
			}
	}
	print(arrRes.length);
	for (var i = 0; i <= arrRes.length - 1; i++)
	{
		print(arrRes[i].join(' '));
	}
}
{
	var input1 = readline().split(''),
		input2 = readline().split('');
	main(input1, input2);
}

function sa(s1, s2){
        var res = [];
        var data = {};
         for(var i=0;i<s1.length;i++){
             if(s1[i]==s2[i]){
                 if(!data[s1[i]] || data[s1[i]] ==s2[i]){
                     data[s1[i]] = s2[i]
                    continue;
                 } else {
                     return -1;
                 }
             }
             var key = s2[i];
             var val = s1[i];

             if(data[key] && data[key] !== val){
                 return -1;
             } else {
                 if(!data[key]){
                     res.push([key, val])
                     data[key] = val;
                     data[val] = key;
                 }
             }

         }
         var r = res.length + "\n";
         for(var i=0;i<res.length;i++){
             r += res[i][0] +" " + res[i][1] + "\n";
         }
        return r;
    }

    var s1 = readline();
    var s2 = readline();
    print(sa(s1, s2));

function sa(s1, s2){
        var res = [];
        var data = {};
         for(var i=0;i<s1.length;i++){
             if(s1[i]==s2[i]){
                 if(!data[s1[i]] || data[s1[i]] ==s2[i]){
                     data[s1[i]] = s2[i]
                    continue;
                 } else {
                     return -1;
                 }
             }
             var key = s1[i];
             var val = s2[i];
             if(s2[i]< s1[i]){
                key = s2[i];
                val = s1[i];
             }

             if(data[key] && data[key] !== val){
                 return -1;
             } else {
                 if(!data[key]){
                     res.push([key, val])
                     data[key] = val;
                 }
             }

         }
         var r = res.length + "\n";
         for(var i=0;i<res.length;i++){
             r += res[i][0] +" " + res[i][1] + "\n";
         }
        return r;
    }

    var s1 = readline();
    var s2 = readline();
    print(sa(s1, s2));

function sa(s1, s2){
        var res = [];
        var data = {};
         for(var i=0;i<s1.length;i++){
             if(s1[i]==s2[i]){
                 if(!data[s1[i]]){
                    continue;
                 } else {
                     return -1;
                 }
             }
             var key = s1[i];
             var val = s2[i];
             if(s2[i]< s1[i]){
                key = s2[i];
                val = s1[i];
             }

             if(data[key] && data[key] !== val){
                 return -1;
             } else {
                 if(!data[key]){
                     res.push([key, val])
                     data[key] = val;
                 }
             }

         }
         var r = res.length + "\n";
         for(var i=0;i<res.length;i++){
             r += res[i][0] +" " + res[i][1] + "\n";
         }
        return r;
    }

    var s1 = readline();
    var s2 = readline();
    print(sa(s1, s2));

function sa(s1, s2){
        var res = [];
        var data = {};
         for(var i=0;i<s1.length;i++){
             if(s1[i]==s2[i]){
                 if(!data[s1[i]] || data[s1[i]] ==s2[i]){
                     data[s1[i]] = s2[i]
                    continue;
                 } else {
                     return -1;
                 }
             }
             var key = s1[i];
             var val = s2[i];
             if(s2[i]< s1[i]){
                key = s2[i];
                val = s1[i];
             }

             if(data[key] && data[key] !== val){
                 return -1;
             } else {
                 if(!data[key]){
                     res.push([key, val])
                     data[key] = val;
                     data[val] = key;
                 }
             }

         }
         var r = res.length + "\n";
         for(var i=0;i<res.length;i++){
             r += res[i][0] +" " + res[i][1] + "\n";
         }
        return r;
    }

    var s1 = readline();
    var s2 = readline();
    print(sa(s1, s2));

function sa(s1, s2){
        var res = [];
        var data = {};
         for(var i=0;i<s1.length;i++){
             if(s1[i]==s2[i]){
                 if(!data[s1[i]]){
                     data[s1[i]] = s2[i]
                    continue;
                 } else {
                     return -1;
                 }
             }
             var key = s1[i];
             var val = s2[i];
             if(s2[i]< s1[i]){
                key = s2[i];
                val = s1[i];
             }

             if(data[key] && data[key] !== val){
                 return -1;
             } else {
                 if(!data[key]){
                     res.push([key, val])
                     data[key] = val;
                 }
             }

         }
         var r = res.length + "\n";
         for(var i=0;i<res.length;i++){
             r += res[i][0] +" " + res[i][1] + "\n";
         }
        return r;
    }

    var s1 = readline();
    var s2 = readline();
    print(sa(s1, s2));

function sa(s1, s2){
        var res = [];
        var data = {};
         for(var i=0;i<s1.length;i++){
             if(s1[i]==s2[i]){
                 continue;
             }
             var key = s1[i];
             var val = s2[i];
             if(s2[i]< s1[i]){
                key = s2[i];
                val = s1[i];
             }

             if(data[key] && data[key] !== val){
                 return -1;
             } else {
                 if(!data[key]){
                     res.push([key, val])
                     data[key] = val;
                 }
             }

         }
         var r = res.length + "\n";
         for(var i=0;i<res.length;i++){
             r += res[i][0] +" " + res[i][1] + "\n";
         }
        return r;
    }

    var s1 = readline();
    var s2 = readline();
    print(sa(s1, s2));


There is a road with length $$$l$$$ meters. The start of the road has coordinate $$$0$$$, the end of the road has coordinate $$$l$$$.There are two cars, the first standing at the start of the road and the second standing at the end of the road. They will start driving simultaneously. The first car will drive from the start to the end and the second car will drive from the end to the start.Initially, they will drive with a speed of $$$1$$$ meter per second. There are $$$n$$$ flags at different coordinates $$$a_1, a_2, \ldots, a_n$$$. Each time when any of two cars drives through a flag, the speed of that car increases by $$$1$$$ meter per second.Find how long will it take for cars to meet (to reach the same coordinate).

The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$): the number of test cases. The first line of each test case contains two integers $$$n$$$, $$$l$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq l \leq 10^9$$$): the number of flags and the length of the road. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ in the increasing order ($$$1 \leq a_1 < a_2 < \ldots < a_n < l$$$). It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$10^5$$$.

For each test case print a single real number: the time required for cars to meet. Your answer will be considered correct, if its absolute or relative error does not exceed $$$10^{-6}$$$. More formally, if your answer is $$$a$$$ and jury's answer is $$$b$$$, your answer will be considered correct if $$$\frac{|a-b|}{\max{(1, b)}} \leq 10^{-6}$$$.

NoteIn the first test case cars will meet in the coordinate $$$5$$$.The first car will be in the coordinate $$$1$$$ in $$$1$$$ second and after that its speed will increase by $$$1$$$ and will be equal to $$$2$$$ meters per second. After $$$2$$$ more seconds it will be in the coordinate $$$5$$$. So, it will be in the coordinate $$$5$$$ in $$$3$$$ seconds.The second car will be in the coordinate $$$9$$$ in $$$1$$$ second and after that its speed will increase by $$$1$$$ and will be equal to $$$2$$$ meters per second. After $$$2$$$ more seconds it will be in the coordinate $$$5$$$. So, it will be in the coordinate $$$5$$$ in $$$3$$$ seconds.In the second test case after $$$1$$$ second the first car will be in the coordinate $$$1$$$ and will have the speed equal to $$$2$$$ meters per second, the second car will be in the coordinate $$$9$$$ and will have the speed equal to $$$1$$$ meter per second. So, they will meet after $$$\frac{9-1}{2+1} = \frac{8}{3}$$$ seconds. So, the answer is equal to $$$1 + \frac{8}{3} = \frac{11}{3}$$$.

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)
  }
}

#!/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();
}

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-5)) {
            print(df1);
            return;
        }
        else {
            if (df1 < df2) lo = mid;
            else hi = mid;
        }
    }
}

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

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()


A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).  Alice and Bob play dice. Alice has built a tower from n dice. We know that in this tower the adjacent dice contact with faces with distinct numbers. Bob wants to uniquely identify the numbers written on the faces of all dice, from which the tower is built. Unfortunately, Bob is looking at the tower from the face, and so he does not see all the numbers on the faces. Bob sees the number on the top of the tower and the numbers on the two adjacent sides (on the right side of the picture shown what Bob sees).Help Bob, tell whether it is possible to uniquely identify the numbers on the faces of all the dice in the tower, or not.

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of dice in the tower. The second line contains an integer x (1 ≤ x ≤ 6) — the number Bob sees at the top of the tower. Next n lines contain two space-separated integers each: the i-th line contains numbers ai, bi (1 ≤ ai, bi ≤ 6; ai ≠ bi) — the numbers Bob sees on the two sidelong faces of the i-th dice in the tower. Consider the dice in the tower indexed from top to bottom from 1 to n. That is, the topmost dice has index 1 (the dice whose top face Bob can see). It is guaranteed that it is possible to make a dice tower that will look as described in the input.

Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes).

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');
}

;(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);

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);


Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?

The first line contains four space-separated integers a1, a2, a3, a4 (0 ≤ a1, a2, a3, a4 ≤ 104). The second line contains string s (1 ≤ |s| ≤ 105), where the і-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.

Print a single integer — the total number of calories that Jury wastes.

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)

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();
    }

});

"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));
}

//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);

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);
})();


Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule:  either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before);  or the girl in the dancing pair must dance for the first time. Help Fox Ciel to make a schedule that they can dance as many songs as possible.

The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of boys and girls in the dancing room.

In the first line print k — the number of songs during which they can dance. Then in the following k lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to n, and the girls are indexed from 1 to m.

NoteIn test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).And in test case 2, we have 2 boys with 2 girls, the answer is 3.

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( i + ' ' + 1);

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

}).call(this)

;(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)


A row of $$$n$$$ cells is given, all initially white. Using a stamp, you can stamp any two neighboring cells such that one becomes red and the other becomes blue. A stamp can be rotated, i.e. it can be used in both ways: as $$$\color{blue}{\texttt{B}}\color{red}{\texttt{R}}$$$ and as $$$\color{red}{\texttt{R}}\color{blue}{\texttt{B}}$$$.During use, the stamp must completely fit on the given $$$n$$$ cells (it cannot be partially outside the cells). The stamp can be applied multiple times to the same cell. Each usage of the stamp recolors both cells that are under the stamp.For example, one possible sequence of stamps to make the picture $$$\color{blue}{\texttt{B}}\color{red}{\texttt{R}}\color{blue}{\texttt{B}}\color{blue}{\texttt{B}}\texttt{W}$$$ could be $$$\texttt{WWWWW} \to \texttt{WW}\color{brown}{\underline{\color{red}{\texttt{R}}\color{blue}{\texttt{B}}}}\texttt{W} \to \color{brown}{\underline{\color{blue}{\texttt{B}}\color{red}{\texttt{R}}}}\color{red}{\texttt{R}}\color{blue}{\texttt{B}}\texttt{W} \to \color{blue}{\texttt{B}}\color{brown}{\underline{\color{red}{\texttt{R}}\color{blue}{\texttt{B}}}}\color{blue}{\texttt{B}}\texttt{W}$$$. Here $$$\texttt{W}$$$, $$$\color{red}{\texttt{R}}$$$, and $$$\color{blue}{\texttt{B}}$$$ represent a white, red, or blue cell, respectively, and the cells that the stamp is used on are marked with an underline.Given a final picture, is it possible to make it using the stamp zero or more times?

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of the picture. The second line of each test case contains a string $$$s$$$ — the picture you need to make. It is guaranteed that the length of $$$s$$$ is $$$n$$$ and that $$$s$$$ only consists of the characters $$$\texttt{W}$$$, $$$\texttt{R}$$$, and $$$\texttt{B}$$$, representing a white, red, or blue cell, respectively. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

Output $$$t$$$ lines, each of which contains the answer to the corresponding test case. As an answer, output "YES" if it possible to make the picture using the stamp zero or more times, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

12
5
BRBBW
1
B
2
WB
2
RW
3
BRB
3
RBB
7
WWWWWWW
9
RBWBWRRBW
10
BRBRBRBRRB
12
BBBRWWRRRWBR
10
BRBRBRBRBW
5
RBWBW

YES
NO
NO
NO
YES
YES
YES
NO
YES
NO
YES
NO

NoteThe first test case is explained in the statement.For the second, third, and fourth test cases, it is not possible to stamp a single cell, so the answer is "NO".For the fifth test case, you can use the stamp as follows: $$$\texttt{WWW} \to \texttt{W}\color{brown}{\underline{\color{red}{\texttt{R}}\color{blue}{\texttt{B}}}} \to \color{brown}{\underline{\color{blue}{\texttt{B}}\color{red}{\texttt{R}}}}\color{blue}{\texttt{B}}$$$.For the sixth test case, you can use the stamp as follows: $$$\texttt{WWW} \to \texttt{W}\color{brown}{\underline{\color{red}{\texttt{R}}\color{blue}{\texttt{B}}}} \to \color{brown}{\underline{\color{red}{\texttt{R}}\color{blue}{\texttt{B}}}}\color{blue}{\texttt{B}}$$$.For the seventh test case, you don't need to use the stamp at all.

'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';
 /*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") 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);
}();