Madoka is a very strange girl, and therefore she suddenly wondered how many pairs of integers $$$(a, b)$$$ exist, where $$$1 \leq a, b \leq n$$$, for which $$$\frac{\operatorname{lcm}(a, b)}{\operatorname{gcd}(a, b)} \leq 3$$$.In this problem, $$$\operatorname{gcd}(a, b)$$$ denotes the greatest common divisor of the numbers $$$a$$$ and $$$b$$$, and $$$\operatorname{lcm}(a, b)$$$ denotes the smallest common multiple of the numbers $$$a$$$ and $$$b$$$.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Description of the test cases follows. The first and the only line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^8$$$).

For each test case output a single integer — the number of pairs of integers satisfying the condition.

NoteFor $$$n = 1$$$ there is exactly one pair of numbers — $$$(1, 1)$$$ and it fits.For $$$n = 2$$$, there are only $$$4$$$ pairs — $$$(1, 1)$$$, $$$(1, 2)$$$, $$$(2, 1)$$$, $$$(2, 2)$$$ and they all fit.For $$$n = 3$$$, all $$$9$$$ pair are suitable, except $$$(2, 3)$$$ and $$$(3, 2)$$$, since their $$$\operatorname{lcm}$$$ is $$$6$$$, and $$$\operatorname{gcd}$$$ is $$$1$$$, which doesn't fit the condition.

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    for(let i=1;i<=t;i++)
    {
        let n=parseInt(line[i]);
        let ans=0;
        ans+=n;
        ans+=2*Math.floor(n/2);
        ans+=2*Math.floor(n/3);
        console.log(ans);
    }
})

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    // console.log(line);
    let t=parseInt(line[0]);
    for(let i=1;i<=t;i++)
    {
        let n=parseInt(line[i]);
        let ans=0;
        ans+=n;
        ans+=2*Math.floor(n/2);
        ans+=2*Math.floor(n/3);
        // ans+=Math.floor(y/3);
        console.log(ans);
    }
})

'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn();
  return n + (Math.floor(n / 2) + Math.floor(n / 3)) * 2;
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn();
    return res;
  };
  const re = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn() - 1;
    return res;
  };
  const rbs = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rb();
    return res;
  };
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  const [rn, rb, rns, re, rbs] = convertInput(r);
  try {
    let t = rn();
    let res = new Array(t);
    let limit = 100;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\s+/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

//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();
	var last = 0;
	var addlist = [0,1,4,7,10,11,16];
	while(hasNext()){
		var N = nextInt();
		var output = Math.floor(N / 6) * 16;
		output += addlist[N % 6];
		myout(output);
	}
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        let n = parseInt(readline(), 10);

        let count = n; //('equals');
        count += Math.floor(n / 2) * 2;
        count += Math.floor(n / 3) * 2;

        output(count);
    }
}

var n = readline();
for(var i=0;i<n;i++){
  var N = parseInt(readline());
  print(N+2*Math.floor(N/2)+2*Math.floor(N/3));
}


You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.

Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).

NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).

const main = (data) => {
  const n = data[0];

  for (let i = 1; i <= n; i++) {
    const str = data[i];
    const lastIndex = str.lastIndexOf('1');
    let result = 0;

    for (let j = str.indexOf('1'); j < lastIndex; j++) {
      if (str[j] === '0') {
        result++;
      }
    };

    console.log(result);
  };
};

let data = '';

process.stdin.on('data', input => data += input);
process.stdin.on('end', () => {
  data = data.split('\n');

  main(data);
});

const readline = require('readline');

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

let state = 0;
rl.on('line', line => {
  if (state > 0) {
    let left = line.indexOf('1');
    let right = line.lastIndexOf('1');
    let match = line.slice(left, right).match(/0/g) || [];
    console.log(match.length);
  }
  state++;
}).on('close', () => {
  process.exit(0);
});

const readline = require('readline');

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

let state = 0;
rl.on('line', line => {
  if (state > 0) {
    let left = line.indexOf('1');
    let right = line.lastIndexOf('1');

    console.log(
      line
        .slice(left, right)
        .split('')
        .reduce((a, b) => {
          return (a += b == '0' ? 1 : 0);
        }, 0)
    );
  }
  state++;
}).on('close', () => {
  process.exit(0);
});

const fs = require("fs");
const input = fs.readFileSync(0, { encoding: "utf-8" });
const lines = input.split("\n");
let cases = Number(lines.shift());

while (cases--) {
  const line = lines.shift();
  let a = 0, b = 0, found1 = false;
  for (let i = 0; i < line.length; i++) {
    if (line[i] === "1") {
      found1 = true;
      b = a;
    } else if (found1) {
      a++;
    }
  }
  console.log(b);
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL);

    function foo (str) {
        const match = str.match(/^0*(.*?)0*$/);
        const trimed = match && match[1];
        if (!trimed) return 0;
        const theros = trimed.match(/0/g);
        if (!theros) return 0;
        return theros.length;
    }

    let testCount = 1;
    let answer = '';
    while(testCount <= +lines[0]) {
        let data = lines[testCount];

        let result = foo(data);
        answer += result +"\n";
        testCount++;
    }
    console.log(answer);
})

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

rl.on('line', (str) => {
  if (c === 0) {
    c++;
    return;
  }

  let ans = 0;
  let headN = str.indexOf('1');
  let tailN = str.lastIndexOf('1');

  for (let i = headN; i < tailN; i++) {
    if (str[i] === '0') {
      ans++;
    }
  }

  console.log(ans);

  c++;
});

const processData = (lines) => {
  const num = +lines[0]

  for (let j=0; j<num; j++){
    const numsLine = lines[j+1].split('')
    let isFindOne = false
    let res = 0
    let acc = 0
    for (const n of numsLine) {
      if (n === '0') {
        if (isFindOne) {
          acc++
        }
      } else {
        isFindOne = true
        res += acc
        acc = 0
      }

    }
    console.log(res)
  }
}

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

process.stdin.resume();
process.stdin.setEncoding('utf8');

var input= '', readline, print;

process.stdin.on('data', function(chunk) {
  input+=chunk;
});

process.stdin.on('end', function() {
  input = input.split('\n');
  print = function(data) {process.stdout.write(data+'\n')};
  var inputLineIndex = 0;
  readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};
  process.exit(main() || 0);
});

function main()
{
  const length = input[0];
  for(let i = 1; i <= length; i++) {
    const str = input[i];
    let count = 0;
    let firstIndex = -1;
    let lastIndex = -1;

    for (let j = 0, j2 = str.length - 1; j < str.length; j++, j2--) {
      if(str[j] === '1' && firstIndex < 0) {
        firstIndex = j;
      }

      if(str[j2] === '1' && lastIndex < 0) {
        lastIndex = j2;
      }
    }

    for(let i = firstIndex; i <= lastIndex; i++) {
      if(str[i] === '0') count++;
    }

    print(count);
  }

  // Your code here
  return 0;
}

var data = "";

process.stdin.on("data", x => data += x);

// process.on("SIGINT", () => {
process.stdin.on("end", () => {

	var lines = data.split("\r\n");

	var n = lines.shift();
	for(let i = 0; i < n; i++) f(lines[i]);

	process.exit(0);
});

function f(line) {

	line = line.replace(/(^0*|0*$)/g, "");

	var ans = 0;

	while(line.length) {

		if(+line[0]) line = line.replace(/^1+/, "");
		else {

			var m = line.match(/^0+/);
			ans += m[0].length;
			line = line.replace(/^0+/, "");
		}
	}
	console.log(ans);
}

let fs = require('fs');
let txt = fs.readFileSync(0, "utf-8").split(/[\r\n]/).filter(data => data.length > 0);

txt.shift();
for (let i = 0; i < txt.length; i++) {
    doit(txt[i].split("").filter(data => data.length > 0));

}

function doit(arr) {
    let shift = 0;
    let current = null;
    arr.forEach((data, index) => {
        if (data == 1) {
            if (current == null) {
                current = index;
            } else {
                shift += index - current - 1;
                current = index;
            }
        }
    });
    console.log(shift);

}

var tests = parseInt(readline())
for (var l = 0; l < tests; l++){
var input = readline()
var res = input.split(/(0+)/)
var start = false, erase = 0, head = 0;
for (var i = 0; i < res.length; i++){
	if (res[i][0] == '1' && !start){
		start = true; head = i
	}
	else if (res[i][0] == '1' && start){
		if (i - head > 1){
			erase += res[i-1].length
			head = i
		}
	}
}
print(erase)
}

'use strict'

const problem = (s) => s.split(/1+/).slice(1, -1).reduce((r, i) => r + i.length, 0);

let t = +readline()
while(t--) print(problem(readline()))

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}
function Main() {
    var t = myconv(next(),1);
    var output = new Array(t);
    for(var i = 0; i < t; i++){
        var list = myconv(next(),6);
        var count = 0;
        var tmpCount = 0;
        var zero = false;
        var one = false;
        for(var j = 0; j < list.length; j++){
            if(list[j] == "1"){
                if(zero){
                    zero = false;
                    count += tmpCount;
                    tmpCount = 0;
                }
                one = true;
            }
            if(list[j] == "0"){
                if(one){
                    tmpCount++;
                }
                zero = true;
            }
        }
        output[i] = count;
    }
    myout(myconv(output,9));
}

function countErasedZeroes(str) {
  var len = str.length,
      start = -1,
      end = -1,
      count = 0
  for (var i = 0; i < len; i++) {
      if (str[i] === '1') {
          start = i
          break
      }
  }
  for (var i = len - 1; i >= 0; i--) {
      if (str[i] === '1') {
          end = i
          break
      }
  }
  for (i = start; i <= end; i++) {
      if (str[i] === '0')
          ++count
  }
  return count
}

var tc = Number(readline())
while (tc--) {
  var str = readline()
  print(countErasedZeroes(str))
}

function countErasedZeroes(str) {
  var len = str.length, start = -1, end = -1, count = 0
  for (var i=0; i<len; i++) {
    if (str[i] === '1') {
        start = i
        break
    }
  }
  for (var i=len-1; i>=0; i--) {
    if (str[i] === '1') {
        end = i
        break
    }
  }
  for (i=start; i<=end; i++) {
    if (str[i] === '0')
        ++count
  }
  return count
}

var tc = Number(readline())
while (tc--) {
  var str = readline()
  print(countErasedZeroes(str))
}

process.stdin.resume();
process.stdin.setEncoding('utf8');

var input= '', readline, print;

process.stdin.on('data', function(chunk) {
  input+=chunk;
});

process.stdin.on('end', function() {
  input = input.split('\n');
  print = function(data) {process.stdout.write(data+'\n')};
  var inputLineIndex = 0;
  readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};
  process.exit(main() || 0);
});

function main()
{
  const length = input[0];
  for(let i = 1; i <= length; i++) {
    const str = input[i];
    let count = 0;
    let firstIndex = null;
    let lastIndex = null;

    for (let j = 0, j2 = str.length - 1; j < str.length; j++, j2--) {
      if(str[j] === '1' && !firstIndex) {
        firstIndex = j;
      }

      if(str[j2] === '1' && !lastIndex) {
        lastIndex = j2;
      }
    }

    for(let i = firstIndex; i <= lastIndex; i++) {
      if(str[i] === '0') count++;
    }

    print(count);
  }

  // Your code here
  return 0;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');

var input= '', readline, print;

process.stdin.on('data', function(chunk) {
  input+=chunk;
});

process.stdin.on('end', function() {
  input = input.split('\n');
  print = function(data) {process.stdout.write(data+'\n')};
  var inputLineIndex = 0;
  readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};
  process.exit(main() || 0);
});

function main()
{
  for(let i = 1; i < input.length - 1; i++) {
    const str = input[i];
    let count = 0;
    let firstIndex = null;
    let lastIndex = null;

    for (let j = 0, j2 = str.length - 1; j < str.length; j++, j2--) {
      if(str[j] === '1' && !firstIndex) {
        firstIndex = j;
      }

      if(str[j2] === '1' && !lastIndex) {
        lastIndex = j2;
      }
    }

    for(let i = firstIndex; i < lastIndex; i++) {
      if(str[i] === '0') count++;
    }

    print(count);
  }

  // Your code here
  return 0;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');

var input= '', readline, print;

process.stdin.on('data', function(chunk) {
  input+=chunk;
});

process.stdin.on('end', function() {
  input = input.split('\n');
  print = function(data) {process.stdout.write(data+'\n')};
  var inputLineIndex = 0;
  readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};
  process.exit(main() || 0);
});

function main()
{
  const length = input[0];
  for(let i = 1; i <= length; i++) {
    const str = input[i];
    let count = 0;
    let firstIndex = null;
    let lastIndex = null;

    for (let j = 0, j2 = str.length - 1; j < str.length; j++, j2--) {
      if(str[j] === '1' && !firstIndex) {
        firstIndex = j;
      }

      if(str[j2] === '1' && !lastIndex) {
        lastIndex = j2;
      }
    }

    for(let i = firstIndex; i < lastIndex; i++) {
      if(str[i] === '0') count++;
    }

    print(count);
  }

  // Your code here
  return 0;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');

var input= '', readline, print;

process.stdin.on('data', function(chunk) {
  input+=chunk;
});

process.stdin.on('end', function() {
  input = input.split('\n');
  print = function(data) {process.stdout.write(data+'\n')};
  var inputLineIndex = 0;
  readline = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};
  process.exit(main() || 0);
});

function main()
{
  for(let i = 1; i < input.length; i++) {
    const str = input[i];
    let count = 0;
    let isRow = false;

    for (let j = 0; j < str.length; j++) {
      if(str[j] === '1' && !isRow) {
        isRow = true;
      } else if(str[j] === '0' && isRow) {
        count++;
      }
    }
    print(count);
  }

  // Your code here
  return 0;
}

let fs=require('fs')
let txt=fs.readFileSync(0,"utf-8").split(/[\r\n]/).filter(data=>data.length>0);

txt.shift()
for (let i = 0; i < txt.length; i++) {
    doit(txt[i].split("").filter(data=>data.length>0));

}

function doit(arr){
    let shift=0;
    let current=null;
    arr.forEach((data,index) => {
        if(data==1){
            if(current==null){current=index}else{
                shift+=index-current-1;
                current=null;
            }
        }
    });
    console.log(shift);

}


Nastia has $$$2$$$ positive integers $$$A$$$ and $$$B$$$. She defines that:  The integer is good if it is divisible by $$$A \cdot B$$$;  Otherwise, the integer is nearly good, if it is divisible by $$$A$$$. For example, if $$$A = 6$$$ and $$$B = 4$$$, the integers $$$24$$$ and $$$72$$$ are good, the integers $$$6$$$, $$$660$$$ and $$$12$$$ are nearly good, the integers $$$16$$$, $$$7$$$ are neither good nor nearly good.Find $$$3$$$ different positive integers $$$x$$$, $$$y$$$, and $$$z$$$ such that exactly one of them is good and the other $$$2$$$ are nearly good, and $$$x + y = z$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) — the number of test cases. The first line of each test case contains two integers $$$A$$$ and $$$B$$$ ($$$1 \le A \le 10^6$$$, $$$1 \le B \le 10^6$$$) — numbers that Nastia has.

For each test case print:    "YES" and $$$3$$$ different positive integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^{18}$$$) such that exactly one of them is good and the other $$$2$$$ are nearly good, and $$$x + y = z$$$.  "NO" if no answer exists.  YES NO If there are multiple answers, print any.

NoteIn the first test case: $$$60$$$ — good number; $$$10$$$ and $$$50$$$ — nearly good numbers.In the second test case: $$$208$$$ — good number; $$$169$$$ and $$$39$$$ — nearly good numbers.In the third test case: $$$154$$$ — good number; $$$28$$$ and $$$182$$$ — nearly good numbers.

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg10 = Math.log10;
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// 05/09/21 evening
const solve = (a, b) => {
    if (b == 1) {
        return pr('NO');
    }
    pr('YES');
    pr(a, a * (2 * b - 1), 2 * a * b);
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i][1]);
            i++;
        }
    });
};

main()

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}

const solve = () => {
  const gcd = (a, b) => (a % b === 0 ? b : gcd(b, a % b));
  let t = parseInt(readline());
  while (t--) {
       let [n,k] = readline().trim().split(" ").map(cur=>parseInt(cur));
       if(k===1) console.log("NO");
       else{
            console.log("YES");
            if(k===2) console.log(`${3*n} ${5*n} ${8*n}`);
            else console.log(`${n*(k-1)} ${n*(k+1)} ${n*k*2}`);
       }
  }
};
solve();

#!/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} a
 * @param {Number} b
 * @returns {Number []}
 */
function solve(a, b) {
  if (b <= 1 || a < 1) {
    return [];
  }
  if (b === 2) {
    return [a, 3 * a, 4 * a];
  }
  return [a, (b-1) * a, a * b];
}

async function main() {
  const t = Number(await getLine());
  for (let i = 0; i < t; i++) {
    const [a, b] = (await getLine()).split(' ').map(Number);
    const res = solve(a, b);
    if (res.length === 3) {
      console.log('YES');
      console.log(res.join(' '));
    } else {
      console.log('NO');
    }
  }
}

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

const solve = (a, b) => {
    if (b === 1) {
        console.log('NO');
    } else {
        console.log('YES');
        console.log(a, a * b, a * (b + 1));
    }
};

let line = '';
process.stdin.on('data', c => line += c);
process.stdin.on('end', () => {
    const input = line.trim().split('\n');
    for (let i = 1; i < input.length; i++) {
        const [a, b] = input[i].split(' ').map(item => parseInt(item));
        solve(a, b);
    }
});

process.stdin.setEncoding('utf-8')
const readline = require('readline')

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

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    // max number 2^(53) - 1 ~~ 10^(15)
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        main()
        process.exit(0)
    }
})

function solve([a, b]) {
    if (b === 1) {
        console.log('NO')
        return
    }
    console.log('YES')
    console.log(a * b, a, (a * b) + a)
}

function main() {
    for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])
}

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(d => parseInt(d));
  var a = line1[0];
  var b = line1[1];
  var p = a * b;
  if (a % p) {
    var f = false;
    var k = 1;
    while (!f && k < 10) {
      for (var i = 1; i < b * k && !f; i++) {
        var d = b * k - i;
        if (a * (i + d) === p && i !== d) {
          print('YES');
          print(a * i, a * d, p);
          f = true;
        }
      }
      p += p;
      k++;
    }
  } else
  print('NO');
}

var tt;
tt=parseInt(readline());

while(tt--){
    var a,b,arr;
    arr=readline().split(' ');
    a=parseInt(arr[0]);
    b=parseInt(arr[1]);

    if(b==1){print("NO");}
    else{
         print("YES");
         var z=(a*b);
         var x=a;
         var y=z+a;

         print(x,z,y);
    }
}

var e=readline();
for(var i=0;i<e;i++){
  var s=readline().split(' ');
  var a=parseInt(s[0]);
  var b=parseInt(s[1]);
  if(b==1){
   print("NO");
  }
  else{
  print("YES");
  var p= 2*a*b-a;
  print(a+' '+p+' '+(p+a));
  }
}

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg10 = Math.log10;
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

const MAX = BigInt(10 ** 18);
const solve = (a, b) => {
    let p = a * b;
    // pr(a,b,p);
    if (a == 1) {
        if (b == 1) {
            pr('YES');
            pr(2, 4, 6);
            return;
        } else if (b == 2) {
            pr('YES');
            pr(1, 3, 4);
            return;
        }
    }
    for (let z = p, rz = 1; z <= MAX; z *= p, rz++) {
        // if (rz > 1 && z == p) break;
        // pr(z);
        for (let x = a, rx = 1; x < z; x *= a, rx++) {
            // if (rx > 1 && x == a) break;
            let y = z - x;
            // pr(x, y);
            if (y % a == 0 && (y != x && x != z && y != z)) {
                pr('YES');
                pr(x.toString(), y.toString(), z.toString());
                return;
            }
        }
    }
    pr('NO');
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => BigInt(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i][1]);
            i++;
        }
    });
};

main()

// pr(60 / (5 * 3));
// pr(208 / (13 * 2));
// pr(154 / (7 * 11));

// pr(50 / 5, 10 / 5, 60 / 5);
// pr(169 / 13, 39 / 13, 208 / 13);
// pr(154 / 7, 28 / 7, 182 / 7);

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg10 = Math.log10;
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

const MAX = BigInt(10 ** 18);
const solve = (a, b) => {
    let p = a * b;
    // pr(a,b,p);
    if (a == 1 && b == 1) {
        pr('YES');
        pr(2, 4, 6);
        return;
    }
    for (let z = p, rz = 1; z <= MAX; z *= p, rz++) {
        if (rz > 1 && z == p) break;
        // pr(z);
        for (let x = a, rx = 1; x < z; x *= a, rx++) {
            if (rx > 1 && x == a) break;
            let y = z - x;
            // pr(x, y);
            if (y % a == 0 && (y != x && x != z && y != z)) {
                pr('YES');
                pr(x.toString(), y.toString(), z.toString());
                return;
            }
        }
    }
    pr('NO');
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => BigInt(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i][1]);
            i++;
        }
    });
};

main()

// pr(60 / (5 * 3));
// pr(208 / (13 * 2));
// pr(154 / (7 * 11));

// pr(50 / 5, 10 / 5, 60 / 5);
// pr(169 / 13, 39 / 13, 208 / 13);
// pr(154 / 7, 28 / 7, 182 / 7);

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg10 = Math.log10;
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

const MAX = BigInt(10 ** 18);
const solve = (a, b) => {
    let p = a * b;
    // pr(a,b,p);
    for (let z = p, rz = 1; z <= MAX; z *= p, rz++) {
        if (rz > 1 && z == p) break;
        // pr(z);
        for (let x = a, rx = 1; x < z; x *= a, rx++) {
            if (rx > 1 && x == a) break;
            let y = z - x;
            // pr(x, y);
            if (y % a == 0 && (y != x && x != z && y != z)) {
                pr('YES');
                pr(x.toString(), y.toString(), z.toString());
                return;
            }
        }
    }
    pr('NO');
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => BigInt(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i][1]);
            i++;
        }
    });
};

main()

// pr(60 / (5 * 3));
// pr(208 / (13 * 2));
// pr(154 / (7 * 11));

// pr(50 / 5, 10 / 5, 60 / 5);
// pr(169 / 13, 39 / 13, 208 / 13);
// pr(154 / 7, 28 / 7, 182 / 7);

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg10 = Math.log10;
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

const MAX = BigInt(10 ** 18);
const solve = (a, b) => {
    let p = a * b;
    // if (a == 1 && b == 2) {
    //     pr('YES');
    //     pr(1, 1, 2);
    //     return;
    // }
    // pr(a,b,p);
    for (let z = p, rz = 1; z <= MAX; z *= p, rz++) {
        if (rz > 1 && z == p) break;
        // pr(z);
        for (let x = a, rx = 1; x < z; x *= a, rx++) {
            if (rx > 1 && x == a) break;
            let y = z - x;
            // pr(x, y);
            if (y % a == 0 && (y != x && y > 0)) {
                pr('YES');
                pr(x.toString(), y.toString(), z.toString());
                return;
            }
        }
    }
    pr('NO');
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => BigInt(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i][1]);
            i++;
        }
    });
};

main()

// pr(60 / (5 * 3));
// pr(208 / (13 * 2));
// pr(154 / (7 * 11));

// pr(50 / 5, 10 / 5, 60 / 5);
// pr(169 / 13, 39 / 13, 208 / 13);
// pr(154 / 7, 28 / 7, 182 / 7);

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg10 = Math.log10;
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

const MAX = BigInt(10 ** 18);
const solve = (a, b) => {
    let p = a * b;
    // if (a == 1 && b == 2) {
    //     pr('YES');
    //     pr(1, 1, 2);
    //     return;
    // }
    // pr(a,b,p);
    for (let z = p, rz = 1; z <= MAX; z *= p, rz++) {
        if (rz > 1 && z == p) break;
        pr(z);
        for (let x = a, rx = 1; x < z; x *= a, rx++) {
            if (rx > 1 && x == a) break;
            let y = z - x;
            pr(x, y);
            if (y % a == 0 && (y != x && x != z)) {
                pr('YES');
                pr(x.toString(), y.toString(), z.toString());
                return;
            }
        }
    }
    pr('NO');
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => BigInt(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i][1]);
            i++;
        }
    });
};

main()

// pr(60 / (5 * 3));
// pr(208 / (13 * 2));
// pr(154 / (7 * 11));

// pr(50 / 5, 10 / 5, 60 / 5);
// pr(169 / 13, 39 / 13, 208 / 13);
// pr(154 / 7, 28 / 7, 182 / 7);

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg10 = Math.log10;
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

const MAX = BigInt(10 ** 18);
const solve = (a, b) => {
    let p = a * b;
    // if (a == 1 && b == 2) {
    //     pr('YES');
    //     pr(1, 1, 2);
    //     return;
    // }
    // pr(a,b,p);
    for (let z = p, rz = 1; z <= MAX; z *= p, rz++) {
        if (rz > 1 && z == p) break;
        // pr(z);
        for (let x = a, rx = 1; x < z; x *= a, rx++) {
            if (rx > 1 && x == a) break;
            let y = z - x;
            // pr(x, y);
            if (y % a == 0 && (y != x)) {
                pr('YES');
                pr(x.toString(), y.toString(), z.toString());
                return;
            }
        }
    }
    pr('NO');
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => BigInt(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i][1]);
            i++;
        }
    });
};

main()

// pr(60 / (5 * 3));
// pr(208 / (13 * 2));
// pr(154 / (7 * 11));

// pr(50 / 5, 10 / 5, 60 / 5);
// pr(169 / 13, 39 / 13, 208 / 13);
// pr(154 / 7, 28 / 7, 182 / 7);

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg10 = Math.log10;
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

const MAX = BigInt(10 ** 18);
const solve = (a, b) => {
    let p = a * b;
    if (a == 1 && b == 2) {
        pr('YES');
        pr(1, 1, 2);
        return;
    }
    // pr(a,b,p);
    for (let z = p; z <= MAX && p != 1; z *= p) {
        // pr(z);
        for (let x = a; x < z && a != 1; x *= a) {
            let y = z - x;
            // pr(x, y);
            if (y % a == 0 && (y != x)) {
                pr('YES');
                pr(x.toString(), y.toString(), z.toString());
                return;
            }
        }
    }
    pr('NO');
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => BigInt(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i][1]);
            i++;
        }
    });
};

main()

// pr(60 / (5 * 3));
// pr(208 / (13 * 2));
// pr(154 / (7 * 11));

// pr(50 / 5, 10 / 5, 60 / 5);
// pr(169 / 13, 39 / 13, 208 / 13);
// pr(154 / 7, 28 / 7, 182 / 7);

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg10 = Math.log10;
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

const MAX = BigInt(10 ** 18);
const solve = (a, b) => {
    let p = a * b;
    // pr(a,b,p);
    for (let z = p; z <= MAX && p != 1; z *= p) {
        // pr(z);
        for (let x = a; x < z && a != 1; x *= a) {
            let y = z - x;
            // pr(x, y);
            if (y % a == 0 && (y != x)) {
                pr('YES');
                pr(x.toString(), y.toString(), z.toString());
                return;
            }
        }
    }
    pr('NO');
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => BigInt(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i][1]);
            i++;
        }
    });
};

main()

// pr(60 / (5 * 3));
// pr(208 / (13 * 2));
// pr(154 / (7 * 11));

// pr(50 / 5, 10 / 5, 60 / 5);
// pr(169 / 13, 39 / 13, 208 / 13);
// pr(154 / 7, 28 / 7, 182 / 7);

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg10 = Math.log10;
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

const MAX = BigInt(10 ** 18);
const solve = (a, b) => {
    let p = a * b;
    for (let z = p; z <= MAX; z *= p) {
        for (let x = a; x < z; x *= a) {
            let y = z - x;
            if (y % a == 0) {
                flag = 1;
                pr('YES');
                pr(x.toString(), y.toString(), z.toString());
                return;
            }
        }
    }
    pr('NO');
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => BigInt(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i][1]);
            i++;
        }
    });
};

main()

// pr(60 / (5 * 3));
// pr(208 / (13 * 2));
// pr(154 / (7 * 11));

// pr(50 / 5, 10 / 5, 60 / 5);
// pr(169 / 13, 39 / 13, 208 / 13);
// pr(154 / 7, 28 / 7, 182 / 7);

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}

const solve = () => {
  const gcd = (a, b) => (a % b === 0 ? b : gcd(b, a % b));
  let t = parseInt(readline());
  while (t--) {
       let [n,k] = readline().trim().split(" ").map(cur=>parseInt(cur));
       if(k===1) console.log("NO");
       else{
            console.log("YES");
            if(k===2) console.log(`${3*n} ${5*n} ${8*13}`);
            else console.log(`${n*(k-1)} ${n*(k+1)} ${n*k*2}`);
       }
  }
};
solve();

#!/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} a
 * @param {Number} b
 * @returns {Number []}
 */
function solve(a, b) {
  if (b <= 1 || a < 1) {
    return [];
  }
  if (b === 2) {
    return [4 * a, a, 3 * a];
  }
  return [a * b, a, (b-1) * a];
}

async function main() {
  const t = Number(await getLine());
  for (let i = 0; i < t; i++) {
    const [a, b] = (await getLine()).split(' ').map(Number);
    const res = solve(a, b);
    if (res.length === 3) {
      console.log('YES');
      console.log(res.join(' '));
    } else {
      console.log('NO');
    }
  }
}

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

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(d => parseInt(d));
  var a = line1[0];
  var b = line1[1];
  var p = a * b;
  if (a % b) {
    var f = false;
    var k = 1;
    while (!f && k < 10) {
      for (var i = 1; i < b * k && !f; i++) {
        var d = b * k - i;
        if (a * (i + d) === p && i !== d) {
          print('YES');
          print(a * i, a * d, p);
          f = true;
        }
      }
      p += p;
      k++;
    }
  } else
  print('NO');
}

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(d => parseInt(d));
  var a = line1[0];
  var b = line1[1];
  var p = a * b;
  if (a % b) {
    var f = false;
    for (var i = 1; i < b && !f; i++) {
      var d = b - i;
      if (a * (i + d) === p && i !== d) {
        print('YES');
        print(a * i, a * d, p);
        f = true;
      }
    }
  } else
  print('NO');
}

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(d => parseInt(d));
  var a = line1[0];
  var b = line1[1];
  if (a % b) {
    var p = a * b;
    for (var i = 1; true; i++) {
      var test = i * p - a;
      if (a !== test && !(test % a) && test % p) {
        print('YES');
        print(a, test, i * p);
        break;
      }
    }
  } else
    print('NO');
}

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(d => parseInt(d));
  var a = line1[0];
  var b = line1[1];
  if (a % b) {
    var p = a * b;
    for (var i = 1; true; i++) {
      var test = i * p - a;
      if (!(test % a) && test % p) {
        print('YES');
        print(a, test, i * p);
        break;
      }
    }
  } else
    print('NO');
}

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(d => parseInt(d));
  var a = line1[0];
  var b = line1[1];
  if (a > 1 || b > 1) {
    var p = a * b;
    print('YES');
    print(p - a, p * 3 + a, p * 4);
  } else
    print('NO');
}

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(d => parseInt(d));
  var a = line1[0];
  var b = line1[1];
  var p = a * b;
  print('YES');
  print(p - a, p * 3 + a, p * 4);
}

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(d => parseInt(d));
  var a = line1[0];
  var b = line1[1];
  var p = a * b;
  print('YES');
  print(p, p * 3, p * 4);
}

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(d => parseInt(d));
  var a = line1[0];
  var b = line1[1];
  var p = a * b;
  print(p, p * 3, p * 4);
}

var tt;
tt=parseInt(readline());

while(tt--){
    var a,b,arr;
    arr=readline().split(' ');
    a=parseInt(arr[0]);
    b=parseInt(arr[1]);

    if(b==1){print("NO");}
    else{
         print("YES");
         var z=(a*b);
         var x=a;
         var y=z+a;

         print(x,y,z);
    }
}


You are given an array of integers $$$a$$$ of length $$$n$$$. The elements of the array can be either different or the same. Each element of the array is colored either blue or red. There are no unpainted elements in the array. One of the two operations described below can be applied to an array in a single step:  either you can select any blue element and decrease its value by $$$1$$$;  or you can select any red element and increase its value by $$$1$$$. Situations in which there are no elements of some color at all are also possible. For example, if the whole array is colored blue or red, one of the operations becomes unavailable.Determine whether it is possible to make $$$0$$$ or more steps such that the resulting array is a permutation of numbers from $$$1$$$ to $$$n$$$?In other words, check whether there exists a sequence of steps (possibly empty) such that after applying it, the array $$$a$$$ contains in some order all numbers from $$$1$$$ to $$$n$$$ (inclusive), each exactly once.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of input data sets in the test. The description of each set of input data consists of three lines. The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the length of the original array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — the array elements themselves. The third line has length $$$n$$$ and consists exclusively of the letters 'B' and/or 'R': $$$i$$$th character is 'B' if $$$a_i$$$ is colored blue, and is 'R' if colored red. It is guaranteed that the sum of $$$n$$$ over all input sets does not exceed $$$2 \cdot 10^5$$$.

Print $$$t$$$ lines, each of which contains the answer to the corresponding test case of the input. Print YES as an answer if the corresponding array can be transformed into a permutation, and NO otherwise. You can print the answer in any case (for example, the strings yEs, yes, Yes, and YES will be recognized as a positive answer).

NoteIn the first test case of the example, the following sequence of moves can be performed:  choose $$$i=3$$$, element $$$a_3=5$$$ is blue, so we decrease it, we get $$$a=[1,2,4,2]$$$;  choose $$$i=2$$$, element $$$a_2=2$$$ is red, so we increase it, we get $$$a=[1,3,4,2]$$$;  choose $$$i=3$$$, element $$$a_3=4$$$ is blue, so we decrease it, we get $$$a=[1,3,3,2]$$$;  choose $$$i=2$$$, element $$$a_2=2$$$ is red, so we increase it, we get $$$a=[1,4,3,2]$$$. We got that $$$a$$$ is a permutation. Hence the answer is YES.

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

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

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();
		const c = rl().split('');

		const inc = [], dec = [];
		for (let i = 0; i < n; i++) {
			if (c[i] == 'B') {
				dec.push(a[i]);
			} else {
				inc.push(a[i]);
			}
		}

		inc.sort((x, y) => x - y);
		dec.sort((x, y) => x - y);

		let ans = true;
		for (let i = 0; ans && i < dec.length; i++) {
			if (dec[i] < i+1)
				ans = false;
		}

		for (let i = 0; ans && i < inc.length; i++) {
			if (inc[i] > dec.length + i + 1) {
				ans = false;
			}
		}

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

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

const readLine = () => dataitr.next().value.trim();
function rl () {
	let ans = readLine().split(' ');
	if (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));
	return ans.length == 1 ? ans[0] : ans;
}

function main () {
	let t = rl();
	while (t--) {
		let n = rl();
		let a = readLine().split(' ').map(x => Number(x));
		let s = rl();

		let b = [], r = [];
		for (let i = 0; i < n; i++) {
			(s[i] == 'B' ? b : r).push(a[i]);
		}

		b.sort((x, y) => x - y);
		r.sort((x, y) => x - y);

		ok = true;
		for (let i = 0; ok && i < b.length; i++)
			if (b[i] < i + 1) ok = false;

		for (let i = b.length; ok && i < n; i++)
			if (r[i - b.length] > i + 1) ok = false;

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

'use strict';
const readline = require('readline');
const util = require('util');
const rl = readline.createInterface({
    input: process.stdin,
});
let pos = 0;
const words = [];
rl.on('line', (line) => {
    words.push.apply(words, line.split(' ').filter(s => s != ''));
});
rl.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(words[pos++]));
}
function nextStr() {
    return words[pos++];
}
function af(l) {
    return Array.from({ length: l });
}
const INF = Number.MAX_SAFE_INTEGER;
const INIT = -1;
let n;
let a;
let s;
function can() {
    const up = [];
    const down = [];
    for (let i = 0; i < n; i++) {
        if (s[i] == 'B') {
            down.push(a[i]);
        }
        else {
            up.push(a[i]);
        }
    }
    up.sort((a, b) => a - b);
    down.sort((a, b) => a - b);
    let l = 0;
    let r = 0;
    //  printf("%j\n", up);
    //  printf("%j\n", down);
    for (let i = 1; i <= n; i++) {
        while (l < down.length && down[l] < i) {
            l++;
        }
        if (l < down.length && down[l] >= i) {
            l++;
            continue;
        }
        if (r < up.length && up[r] <= i) {
            r++;
            continue;
        }
        return false;
    }
    return true;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        a = af(n);
        for (let i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        s = nextStr();
        //    printf("%j\n", a);
        if (can()) {
            printf("YES\n");
        }
        else {
            printf("NO\n");
        }
    }
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};

const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    let arr1 = stringArr();
    let b = [],
      r = [];
    for (let i = 0; i < n; i++)
      arr1[i] === "B" ? b.push(arr[i]) : r.push(arr[i]);
    const helper = () => {
      let res = 1;
      if (b.length >= 2) b.sort((a, b) => a - b);
      for (let i = 0; i < b.length; i++) {
        if (b[i] < res) return "NO";
        res++;
      }

      if (r.length >= 2) if (r.length >= 2) r.sort((a, b) => a - b);
      for (let i = 0; i < r.length; i++) {
        if (r[i] > res) return "NO";
        res++;
      }

      return "YES";
    };
    console.log(helper());
  }
};
solve();

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

        solve();
    });
    function readLine() {
        return inputString[currentLine++];
    }
}
/*
*solve here
*/
function solve() {
    let t = parseInt(readLine());
    while (t--) {
        let n = readLine();
        let a = readLine().split(" ");
        let c = readLine().split("");
        let l = [], r = [];
        for (let i = 0; i < a.length; i++) {
            (c[i] === 'B' ? l : r).push(a[i])
        }
        l.sort((a, b) => a - b);
        r.sort((a, b) => b - a);
        let flag = true;
        for (let i = 0; i < l.length; i++) {
            if (l[i] < (i + 1)) {
                flag = false;
            }
        }
        for (let i = 0; i < r.length; i++) {
            if (r[i] > (n - i)) {
                flag = false;
            }
        }
        console.log(flag ? "YES" : "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 = Number(readline())
    for (let j = 1; j <= t; j++) {
        let n = Number(readline())
        let a = readline().split(' ').map(Number);
        let s = readline();
        let ok = 1;
        let D = [];
        let I = [];
        for (let i = 0; i < n; i++)
            if (s[i] == 'B')
                D.push(a[i]);
            else
                I.push(a[i]);
        D.sort((a, b) => a - b)
        I.sort((a, b) => a - b)
        let pd = 0, pi = 0;
        let ld = D.length;
        let li = I.length;
        for (let i = 1; i <= n; i++) {
            if (pd < ld && D[pd] >= i)
                pd++;
            else if (pi < li && I[pi] <= i)
                pi++;
            else
                ok = 0;
        }
        if (ok)
            console.log("YES");
        else
            console.log("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 gcd(a, b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
// let a=readline().split(' ').map(Number)
// a.sort((a,b)=>a-b)

function main() {
    let t = Number(readline())
    for (let j = 1; j <= t; j++) {
        let n = Number(readline())
        let a = readline().split(' ').map(Number);
        let s = readline();
        let ok = 1;
        let D = [];
        let I = [];
        for (let i = 0; i < n; i++)
            if (s[i] == 'B')
                D.push(a[i]);
            else
                I.push(a[i]);
        D.sort((a, b) => a - b)
        I.sort((a, b) => a - b)
        let pd = 0, pi = 0;
        let ld = D.length;
        let li = I.length;
        for (let i = 1; i <= n; i++) {
            if (pd < ld && D[pd] >= i)
                pd++;
            else if (pi < li && I[pi] <= i)
                pi++;
            else
                ok = 0;
        }
        if (ok)
            console.log("YES");
        else
            console.log("NO");
    }
}

var a=readline();
function mergeSort(array) {
        if (array == null) {
            return;
        }

        if (array.length > 1) {
            var mid = parseInt(array.length / 2);

            // Split left part
            var left = Array(mid).fill(0);
            for (i = 0; i < mid; i++) {
                left[i] = array[i];
            }

            // Split right part
            var right = Array(array.length - mid).fill(0);
            for (i = mid; i < array.length; i++) {
                right[i - mid] = array[i];
            }
            mergeSort(left);
            mergeSort(right);

            var i = 0;
            var j = 0;
            var k = 0;

            // Merge left and right arrays
            while (i < left.length && j < right.length) {
                if (left[i] < right[j]) {
                    array[k] = left[i];
                    i++;
                } else {
                    array[k] = right[j];
                    j++;
                }
                k++;
            }
            // Collect remaining elements
            while (i < left.length) {
                array[k] = left[i];
                i++;
                k++;
            }
            while (j < right.length) {
                array[k] = right[j];
                j++;
                k++;
            }
        }
        return array;
}

function getObj(arr,str) {
	var red=[];
	var blue=[];
	for (var i = 0; i < arr.length; i++) {
		if(str[i]=="B"){
			blue.push(arr[i]);
		}else{
			red.push(arr[i]);
		}
	}
	red=mergeSort(red);
	blue=mergeSort(blue);
	var isTrue=true;
	for (var i = 1; i < arr.length+1; i++) {
		if(i<=blue.length){
			if(i>blue[i-1]){
				isTrue=false;
				break;
			}
		}else{
			if((i)<red[i-1-blue.length]){
				isTrue=false;
				break;
			}
		}
	}
	if(isTrue){
		return "yes";
	}else{
		return "no";
	}
}

for(var q=0;q<a;q++){
    var b=readline();
    var c=readline().split(" ").map(Number);
    var d=readline();

    print(getObj(c,d));

}

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

const readLine = () => dataitr.next().value.trim();
function rl () {
	let ans = readLine().split(' ');
	if (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));
	return ans.length == 1 ? ans[0] : ans;
}

function main () {
	let t = rl();
	while (t--) {
		let n = rl();
		let a = readLine().split(' ').map(x => Number(x));
		let s = rl();

		let b = [], r = [];
		for (let i = 0; i < n; i++) {
			(s[i] == 'B' ? b : r).push(a[i]);
		}

		b.sort((x, y) => x - y);
		r.sort((x, y) => x - y);

		ok = true;
		console.log(b, r, a, s)
		for (let i = 0; ok && i < b.length; i++)
			if (b[i] < i + 1) ok = false;

		for (let i = b.length; ok && i < n; i++)
			if (r[i - b.length] > i + 1) ok = false;

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

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

const readLine = () => dataitr.next().value.trim();
function rl () {
	let ans = readLine().split(' ');
	if (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));
	return ans.length == 1 ? ans[0] : ans;
}

function main () {
	let t = rl();
	while (t--) {
		let n = rl();
		let a = rl();
		let s = rl();

		let b = [], r = [];
		for (let i = 0; i < n; i++) {
			(s[i] == 'B' ? b : r).push(a[i]);
		}

		b.sort((x, y) => x - y);
		r.sort((x, y) => x - y);

		ok = true;
		for (let i = 0; ok && i < b.length; i++)
			if (b[i] < i + 1) ok = false;

		for (let i = b.length; ok && i < n; i++)
			if (r[i - b.length] > i + 1) ok = false;

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

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

const readLine = () => dataitr.next().value.trim();
function rl () {
	let ans = readLine().split(' ');
	if (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));
	return ans.length == 1 ? ans[0] : ans;
}

function main () {
	let t = rl();
	while (t--) {
		let n = rl();
		let a = rl();
		let s = rl();

		let b = [], r = [];
		for (let i = 0; i < n; i++) {
			if (s[i] == 'B' )
				b.push(a[i]);
			else r.push(a[i]);
		}

		b.sort((x, y) => x - y);
		r.sort((x, y) => x - y);

		ok = true;
		for (let i = 0; ok && i < b.length; i++)
			if (b[i] < i + 1) ok = false;

		for (let i = b.length; ok && i < n; i++)
			if (r[i - b.length] > i + 1) ok = false;

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

'use strict';
const readline = require('readline');
const util = require('util');
const rl = readline.createInterface({
    input: process.stdin,
});
let pos = 0;
const words = [];
rl.on('line', (line) => {
    words.push.apply(words, line.split(' ').filter(s => s != ''));
});
rl.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(words[pos++]));
}
function nextStr() {
    return words[pos++];
}
function af(l) {
    return Array.from({ length: l });
}
const INF = Number.MAX_SAFE_INTEGER;
const INIT = -1;
let n;
let a;
let s;
function can() {
    const up = [];
    const down = [];
    for (let i = 0; i < n; i++) {
        if (s[i] == 'B') {
            down.push(a[i]);
        }
        else {
            up.push(a[i]);
        }
    }
    up.sort();
    down.sort();
    let l = 0;
    let r = 0;
    for (let i = 1; i <= n; i++) {
        while (l < down.length && down[l] < i) {
            l++;
        }
        if (l < down.length && down[l] >= i) {
            l++;
            continue;
        }
        if (r < up.length && up[r] <= i) {
            r++;
            continue;
        }
        return false;
    }
    return true;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        a = af(n);
        for (let i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        s = nextStr();
        if (can()) {
            printf("YES\n");
        }
        else {
            printf("NO\n");
        }
    }
}

'use strict';
const readline = require('readline');
const util = require('util');
const rl = readline.createInterface({
    input: process.stdin,
});
let pos = 0;
const words = [];
rl.on('line', (line) => {
    words.push.apply(words, line.split(' ').filter(s => s != ''));
});
rl.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(words[pos++]));
}
function nextStr() {
    return words[pos++];
}
function af(l) {
    return Array.from({ length: l });
}
const INF = Number.MAX_SAFE_INTEGER;
const INIT = -1;
let n;
let a;
let s;
function can() {
    const up = [];
    const down = [];
    for (let i = 0; i < n; i++) {
        if (s[i] == 'B') {
            down.push(a[i]);
        }
        else {
            up.push(a[i]);
        }
    }
    up.sort();
    down.sort();
    let l = 0;
    let r = 0;
    for (let i = 1; i <= n; i++) {
        while (down[l] < i) {
            l++;
        }
        if (down[l] >= i) {
            l++;
            continue;
        }
        if (up[r] <= i) {
            r++;
            continue;
        }
        return false;
    }
    return true;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        a = af(n);
        for (let i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        s = nextStr();
        if (can()) {
            printf("YES\n");
        }
        else {
            printf("NO\n");
        }
    }
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};

const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    let arr1 = stringArr();
    let b = [],
      r = [];
    for (let i = 0; i < n; i++)
      arr1[i] === "B" ? b.push(arr[i]) : r.push(arr[i]);
    const helper = () => {
      let res = 1;
      if (b.length >= 2) {
        b.sort((a, b) => a - b);
        for (let i = 0; i < b.length; i++) {
          if (b[i] < res) return "NO";
          res++;
        }
      }
      if (r.length >= 2) {
        if (r.length >= 2) r.sort((a, b) => a - b);
        for (let i = 0; i < r.length; i++) {
          if (r[i] > res) return "NO";
          res++;
        }
      }
      return "YES";
    };
    console.log(helper());
  }
};
solve();

var a=readline();
function mergeSort(array) {
        if (array == null) {
            return;
        }

        if (array.length > 1) {
            var mid = parseInt(array.length / 2);

            // Split left part
            var left = Array(mid).fill(0);
            for (i = 0; i < mid; i++) {
                left[i] = array[i];
            }

            // Split right part
            var right = Array(array.length - mid).fill(0);
            for (i = mid; i < array.length; i++) {
                right[i - mid] = array[i];
            }
            mergeSort(left);
            mergeSort(right);

            var i = 0;
            var j = 0;
            var k = 0;

            // Merge left and right arrays
            while (i < left.length && j < right.length) {
                if (left[i] < right[j]) {
                    array[k] = left[i];
                    i++;
                } else {
                    array[k] = right[j];
                    j++;
                }
                k++;
            }
            // Collect remaining elements
            while (i < left.length) {
                array[k] = left[i];
                i++;
                k++;
            }
            while (j < right.length) {
                array[k] = right[j];
                j++;
                k++;
            }
        }
        return array;
}

function getObj(arr,str) {
	var red=[];
	var blue=[];
	for (var i = 0; i < arr.length; i++) {
		if(str[i]=="B"){
			blue.push(arr[i]);
		}else{
			red.push(arr[i]);
		}
	}
	red=mergeSort(red);
	blue=mergeSort(blue);
	var isTrue=true;
	for (var i = 1; i < arr.length+1; i++) {
		if(i<=blue.length){
			if(i>blue[i-1]){
				isTrue=false;
				break;
			}
		}else{
			if((i)<red[i-1-blue.length]){
				isTrue=false;
				break;
			}
		}
	}
	if(isTrue){
		return "yes";
	}else{
		return "no";
	}
}

for(var q=0;q<a;q++){
    var b=readline();
    var c=readline().split(" ");
    var d=readline();

    print(getObj(c,d));

}


Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows:   $$$f(0) = a$$$;  $$$f(1) = b$$$;  $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n > 1$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. You are given three integers $$$a$$$, $$$b$$$, and $$$n$$$, calculate $$$f(n)$$$.You have to answer for $$$T$$$ independent test cases.

The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively.

NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$.

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

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

  const [a, b, n] = d.split(' ').map(Number);
  const ans = [a, b, a ^ b];
  console.log(ans[n % 3]);

  c++;
});

let data = '';
process.stdin.on('data', c => data += c);

const sol = () => {
	let line = data.split('\n');
	let n = parseInt(line[0], 10);
	let result = [];
	for(let i = 0; i < n; i++){
		let [a, b, k] = line[i+1].split(' ').map(v => parseInt(v,10));
		result.push([a, b, a ^ b][k%3]);
	}
	console.log(result.join('\n'));
};
process.stdin.on('end', sol);

function input() {
  var n = parseInt(readline().trim());
  return Array(n)
    .fill(0)
    .map(function() {
      return readline()
        .trim()
        .split(" ")
        .map(function(i) {
          return parseInt(i);
        });
    });
}

function solve(a, b, n) {
  if (n % 3 === 0) return a;
  if (n % 3 === 1) return b;
  return a ^ b;
}

function main() {
  // get input
  var read = input();

  for (var i = 0; i < read.length; i++) {
    print(solve(read[i][0], read[i][1], read[i][2]));
  }
}

main();

var q = readline();

for(var i = 0; i < q; i++) {
    var x = readline().split(" ");
    var a = x[0];
    var b = x[1];
    var n = x[2];

    if(n % 3 === 0) print(a);
    else if(n % 3 == 1) print(b);
    else print(a ^ b);

}

(function() {
var INPUT = ``;
var OUTPUT = ``;

var main = function() {"use strict";
    // TODO
    var T = rdN();
    while (T --> 0) {
        var input = rdArN();
        var a = input[0].toString(2).split('').reverse();
        var b = input[1].toString(2).split('').reverse();
        var n = input[2]%3;

        var res = [];
        var F = [
            [
                [0, 0],
                [1, 1]
            ],
            [
                [0, 1],
                [0, 1]
            ],
            [
                [0, 1],
                [1, 0]
            ],
        ]
        for (var i = 0; i < a.length || i < b.length; ++i) {
            var f0 = a[i] || 0;
            var f1 = b[i] || 0;
            var fn = F[n][f0][f1];

            res.push(fn);
        }
        pr(parseInt(res.reverse().join(''), 2));
    }
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const
rdS=readline,
rdN=()=>+rdS(),
rdArS=()=>rdS().split(' '),
rdArN=()=>rdArS().map(v=>+v),
wr=write,
pr=print,
prAr=(a)=>pr(...a),
prOb=(o)=>pr(JSON.stringify(o,null,4)),
crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},
getPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;},
getPrimeFactors=function(n){var primes=getPrimes(Math.floor(Math.sqrt(n))),last=primes.push(n)-1,factors=[],i,p;for(i=0,p=primes[0];primes[last]>1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},
defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});
defineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});

main();
return OUTPUT;
})();

process.stdin.resume()
process.stdin.setEncoding('utf8')
let arr = "";
let numbers = []
process.stdin.on('data', function(chunk) {
  arr += chunk;
});

process.stdin.on('end', () => {
  arr = arr.split("\n");
  var n = parseInt(arr.shift())
  for(let i=0;i<n;i++){
    var c = arr[i].split(" ")
    var a = parseInt(c[0])
    var b = parseInt(c[1])
    var no = parseInt(c[2])
    var term = [a, b, a ^ b]
    numbers.push(term[no % 3])
  }
  for(let i = 0; i < numbers.length; i++){
    console.log(numbers[i])
  }
})

process.stdin.resume()
process.stdin.setEncoding('utf8')
let arr = "";
let numbers = []
process.stdin.on('data', function(chunk) {
  arr += chunk;
});

process.stdin.on('end', () => {
  arr = arr.split("\n");
  var n = parseInt(arr.shift())
  console.log(n)
  for(let i=0;i<n;i++){
    var c = arr[i].split(" ")
    var a = parseInt(c[0])
    var b = parseInt(c[1])
    var no = parseInt(c[2])
    var term = [a, b, a ^ b]
    console.log(term)
    numbers.push(term[no % 3])
  }
  console.log(n, numbers)
  for(let i = 0; i < numbers.length; i++){
    console.log(numbers[i])
  }
})

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

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

  let [a, b, n] = d.split(' ').map(Number);

  if (n === 0) {
    console.log(a);
    return;
  }
  else if (n === 1) {
    console.log(b);
    return;
  }

  console.log(a ^ b);

  c++;
});

function input() {
  var n = parseInt(readline().trim());
  return Array(n)
    .fill(0)
    .map(function() {
      return readline()
        .trim()
        .split(" ")
        .map(function(i) {
          return parseInt(i);
        });
    });
}

function solve(a, b, n) {
  if (n == 0) return a;
  if (n == 1) return b;

  var check = {
    [a]: 0,
    [b]: 1
  };

  var reverse = {
    0: a,
    1: b
  };

  var count = 2;

  while (true) {
    var next = a ^ b;
    if (check[next] !== undefined) {
      return reverse[n % count];
    }
    check[next] = count;
    reverse[count] = next;
    a = b;
    b = next;
    count += 1;
  }
}

function main() {
  // get input
  var read = input();

  for (var i = 0; i < read.length; i++) {
    print(solve(read[i][0], read[i][1], read[i][2]));
  }
}

main();

process.stdin.resume()
process.stdin.setEncoding('utf8')
let arr = "";
let numbers = []
process.stdin.on('data', function(chunk) {
  arr += chunk;
});

process.stdin.on('end', () => {
  arr = arr.split("\n");
  var n = parseInt(arr.shift())
  for(let i=0;i<n;i++){
    var c = arr[i].split(" ")
    var a = parseInt(c[0])
    var b = parseInt(c[1])
    var term = [a, b, a ^ b]
    numbers.push(term[c[2] % 3])
  }
})
for(let i = 0; i < numbers.length; i++){
  console.log(numbers[i])
}

process.stdin.resume()
process.stdin.setEncoding('utf8')
let arr = "";
let numbers = []
process.stdin.on('data', function(chunk) {
  arr += chunk;
});

process.stdin.on('end', () => {
  arr = arr.split("\n");
  var n = parseInt(arr.shift())
  for(let i=0;i<n;i++){
    var c = arr[i].split(" ")
    var a = parseInt(c[0])
    var b = parseInt(c[1])
    var n = parseInt(c[2])
    var term = [a, b, a ^ b]
    numbers.push(term[n % 3])
  }
  for(let i = 0; i < numbers.length; i++){
    console.log(numbers[i])
  }
})


A sequence of $$$n$$$ non-negative integers ($$$n \ge 2$$$) $$$a_1, a_2, \dots, a_n$$$ is called good if for all $$$i$$$ from $$$1$$$ to $$$n-1$$$ the following condition holds true: $$$$$$a_1 \: \& \: a_2 \: \& \: \dots \: \& \: a_i = a_{i+1} \: \& \: a_{i+2} \: \& \: \dots \: \& \: a_n,$$$$$$ where $$$\&$$$ denotes the bitwise AND operation.You are given an array $$$a$$$ of size $$$n$$$ ($$$n \geq 2$$$). Find the number of permutations $$$p$$$ of numbers ranging from $$$1$$$ to $$$n$$$, for which the sequence $$$a_{p_1}$$$, $$$a_{p_2}$$$, ... ,$$$a_{p_n}$$$ is good. Since this number can be large, output it modulo $$$10^9+7$$$.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$), denoting the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the size of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

Output $$$t$$$ lines, where the $$$i$$$-th line contains the number of good permutations in the $$$i$$$-th test case modulo $$$10^9 + 7$$$.

NoteIn the first test case, since all the numbers are equal, whatever permutation we take, the sequence is good. There are a total of $$$6$$$ permutations possible with numbers from $$$1$$$ to $$$3$$$: $$$[1,2,3]$$$, $$$[1,3,2]$$$, $$$[2,1,3]$$$, $$$[2,3,1]$$$, $$$[3,1,2]$$$, $$$[3,2,1]$$$.In the second test case, it can be proved that no permutation exists for which the sequence is good.In the third test case, there are a total of $$$36$$$ permutations for which the sequence is good. One of them is the permutation $$$[1,5,4,2,3]$$$ which results in the sequence $$$s=[0,0,3,2,0]$$$. This is a good sequence because   $$$ s_1 = s_2 \: \& \: s_3 \: \& \: s_4 \: \& \: s_5 = 0$$$,  $$$ s_1 \: \& \: s_2 = s_3 \: \& \: s_4 \: \& \: s_5 = 0$$$,  $$$ s_1 \: \& \: s_2 \: \& \: s_3 = s_4 \: \& \: s_5 = 0$$$,  $$$ s_1 \: \& \: s_2 \: \& \: s_3 \: \& \: s_4 = s_5 = 0$$$.

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

const MOD = 1e9+7;

const B = n => BigInt(n);

function fact (n) {
	let res = 1;
	for (let i = 1; i <= n; i++) res = res * i % MOD;
	return res;
}

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		let and = ~0;
		for (let i = 0; i < n; i++) and &= a[i];

		let cnt = 0;
		for (let i = 0; i < n; i++) cnt += a[i] == and;

		const ans = B(cnt*(cnt-1)) * B(fact(n-2)) % B(MOD);
		console.log(ans.toString());
	}
}

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

const MOD = BigInt(1e9+7);

function fact (n) {
	let res = 1n;
	for (let i = 1n; i <= n; i++) res = res * i % MOD;
	return res;
}

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		let and = a[0];
		for (let i = 0; i < n; i++) and &= a[i];

		let cnt = 0;
		for (let i = 0; i < n; i++) cnt += a[i] == and;

		const ans = BigInt(cnt*(cnt-1))*fact(n-2)%MOD;
		console.log(ans.toString());
	}
}

'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++];
}

var maxN = 2 * 1e5 + 10
var mod = BigInt(1e9 + 7)

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  const xx = readline();
  Array(Number(xx)).fill(1).map((t, i) => {
    var n = parseInt(readline());
    // var [n, m] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // })
    // var [x, y] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // });
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    })
    var x = a[0]
    for (let j = 0; j < n; j++) {
      x = x & a[j]
    }

    var cmt = 0
    for (let j = 0; j < n; j++) {
      cmt = cmt + (a[j] === x ? 1 : 0)
    }
    var ans = 1n
    ans = ((BigInt(cmt) * BigInt(cmt - 1)) / 2n * 2n) % mod

    for (let j = 1; j <= n - 2; j++) {
      ans = (ans * BigInt(j)) % mod
    }

    console.log(ans.toString())

  })
}

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

const MOD = 1e9+7;

function fact (n) {
	let res = 1;
	for (let i = 1; i <= n; i++) res = res * i % MOD;
	return res;
}

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		let and = a[0];
		for (let i = 0; i < n; i++) and &= a[i];

		let cnt = 0;
		for (let i = 0; i < n; i++) cnt += a[i] == and;

		console.log(cnt*(cnt-1)*fact(n-2)%MOD+0);
	}
}


String s of length n is called k-palindrome, if it is a palindrome itself, and its prefix and suffix of length  are (k - 1)-palindromes. By definition, any string (even empty) is 0-palindrome.Let's call the palindrome degree of string s such a maximum number k, for which s is k-palindrome. For example, "abaaba" has degree equals to 3.You are given a string. Your task is to find the sum of the palindrome degrees of all its prefixes.

The first line of the input data contains a non-empty string, consisting of Latin letters and digits. The length of the string does not exceed 5·106. The string is case-sensitive.

Output the only number — the sum of the polindrome degrees of all the string's prefixes.

s = readline();
front = 0;
back = 0;
order = 1;
var tmp = Array(s.length + 1).fill(0);
result = 0;
var mod = (1 << 31) - 1
primary = 131;
for (var i = 0; i < s.length; i++) {
    front = (front + order * s[i].charCodeAt(0)) & mod;
    back = (back * primary + s[i].charCodeAt(0)) & mod;
    order = (order * primary) & mod;
    if (front == back) {
        tmp[i+1] = tmp[(i+1) >> 1] + 1;
        result += tmp[i+1];
    }
}
write(result)

s = readline();
front = 0;
back = 0;
order = 1;
var tmp = Array(s.length + 1).fill(0);
result = 0;
var mod = (1 << 31) - 1
primary = 131;
for (var i = 0; i < s.length; i++) {
    front = (front + order * s[i].charCodeAt(0)) & mod;
    back = (back * primary + s[i].charCodeAt(0)) & mod;
    order *= primary;
    if (front == back) {
        tmp[i+1] = tmp[(i+1) >> 1] + 1;
        result += tmp[i+1];
    }
}
write(result)

s = readline();
front = 0;
back = 0;
order = 1;
var tmp = Array(s.length + 1).fill(0);
result = 0;
primary = 131;
for (var i = 0; i < s.length; i++) {
    front = front + order * s[i].charCodeAt(0);
    back = back * primary + s[i].charCodeAt(0);
    order *= primary;
    if (front == back) {
        tmp[i+1] = tmp[(i+1) >> 1] + 1;
        result += tmp[i+1];
    }
}
write(result)