'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 s =  readline().split('');

        let pot = (i, char) => {
            if ((i === 'L' && i > (s.length / 2)) || (i === 'R' && i < (s.length / 2))) {
                return 0;
            }
            let left = val(i, 'L');
            let right = val(i, 'R');
            if (char === 'L' && left > right) {
                return 0;
            } else if (char === 'R' && right > left) {
                return 0;
            } else if (left === right) {
                return 0;
            }
            let max = Math.max(left, right);
            let min = Math.min(left, right);
            return max - min;
        };

        let val = (i, dir) => {
            if (dir === 'L') {
                return i;
            } else {
                return s.length - i - 1;
            }
        }

        let sum = s.map((char, index) => val(index, char)).reduce((a, b) => a + b, 0);

        let v = s.map((val, i) => ({ diff: pot(i, val), i }));
        v.sort((a, b) => b.diff - a.diff);

        let values = [];
        for (let i = 0; i < n; i++) {
            sum += v[i].diff;
            values.push(sum);
        }

        output(values.join(' '));
    }
}

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

let lines = []

const createReadLine = () => {
  i = 0;
  return () => lines[i++]
}

rl.on('line', line => lines.push(line))

rl.on('close', () => {
  const readLine = createReadLine();
  let t = parseInt(readLine())
  while (t--) {
    const n = parseInt(readLine())
    const people = readLine()

    let ans = 0
    let res = ''
    let values = []
    for (let i = 0; i < n; i++) {
      if (people[i] == 'L') {
        values.push(n - i - 1 - i)
        ans += i
      } else {
        values.push(i - (n - i - 1))
        ans += n - i - 1
      }
    }

    values.sort((a, b) => a - b)

    for (let i = 0; i < n; i++) {
      if (values[n - i - 1] > 0) {
        ans += values[n - i - 1]
      }
      res += `${ans} `
    }
    console.log(res)
  }
})

let fs = require("fs");
let sc = {
    _buf: new Buffer.alloc(1 << 14),
    _bufPos: 0,
    _bufLen: 0,
    _ensure: function ()
    {
        if (this._bufPos === this._bufLen)
        {
            this._bufPos = 0;
            this._bufLen = fs.readSync(0, this._buf, 0, this._buf.length, null);
        }
    },
    _isws: function (ch)
    {
        return ch === 32 || ch === 9 || ch === 10 || ch === 13;
    },
    _islf: function (ch)
    {
        return ch === 10 || ch === 13;
    },
    _peekChar: function ()
    {
        this._ensure();
        return this._bufPos === this._bufLen ? 0 : this._buf[this._bufPos];
    },
    _skipWs: function ()
    {
        while (this._isws(this._peekChar()))
            this._bufPos++;
    },
    _readUntil: function (stop)
    {
        this._ensure();
        if (this._bufPos === this._bufLen)
            throw new Error("eof");
        let start = this._bufPos;
        let before = null;
        for (; ;)
        {
            if (this._bufPos === this._bufLen)
            {
                let len = this._bufPos - start, preLen = (before ? before.length : 0);
                let nbuf = new Buffer(len + preLen);
                if (before)
                    before.copy(nbuf);
                before = nbuf;
                this._buf.copy(before, preLen, start);
                this._ensure();
                start = this._bufPos;
            }
            if (this._bufPos === this._bufLen || stop(this._buf[this._bufPos])) break;
            this._bufPos++;
        }
        if (!before)
            return this._buf.toString("utf8", start, this._bufPos);
        let after = this._buf.slice(start, this._bufPos);
        let res = new Buffer(before.length + after.length);
        before.copy(res);
        after.copy(res, before.length);
        return res.toString();
    },

    nextToken: function ()
    {
        this._skipWs();
        return this._readUntil(this._isws);
    },
    L: function ()
    {
        let line = this._readUntil(this._islf);
        if (this._peekChar() === 13) this._bufPos++;
        if (this._peekChar() === 10) this._bufPos++;
        return line;
    },
    N: function ()
    {
        return +this.nextToken();
    },
    S: function ()
    {
        return this.nextToken();
    }
};

// DO NOT CHANGE TEMPLATE BEFORE

const Def = Number(1e9);

const LowerBound = (arr, val) =>
{
    let ng = -1;
    let ok = arr.length;
    while (ok - ng > 1)
    {
        let med = (ok + ng) / 2 | 0;
        if (arr[med] >= val)
        {
            ok = med;
        }
        else
        {
            ng = med;
        }
    }

    return ok;
}

const ReverseLowerBound = (arr, val) =>
{
    let ng = 0;
    let ok = arr.length;
    while (ok - ng > 1)
    {
        let med = (ok + ng) / 2 | 0;
        if (arr[med] <= val)
        {
            ng = med;
        }
        else
        {
            ok = med;
        }
    }
    // Находит наибольший элемент который меньше или равен val
    return ng;
}

const ReverseUpperBound = (arr, val) =>
{
    let ng = 0;
    let ok = arr.length;
    while (ok - ng > 1)
    {
        let med = (ok + ng) / 2 | 0;
        if (arr[med] < val)
        {
            ng = med;
        }
        else
        {
            ok = med;
        }
    }
    // Находит наибольший элемент который меньше val
    return ng;
}

const UpperBound = (arr, val) =>
{
    let ok = arr.length;
    let ng = -1;
    while (ok - ng > 1)
    {
        let med = (ok + ng) / 2 | 0;
        if (arr[med] > val)
        {
            ok = med;
        }
        else
        {
            ng = med;
        }
    }

    return ok;
}

const Calc = (c, i, n) =>
{
    if (c === 'L')
    {
        return i;
    }
    else return n - i - 1;
}

const R = (c) =>
{
    if (c === 'R') return 'L';
    if (c === 'L') return 'R';
}

class Container
{
    i = -1;
    score = -1;
    constructor(i, score)
    {
        this.i = i;
        this.score = score;
    }
}

const Solve = () =>
{
    let n = +sc.N();
    let arr = [...sc.S()];

    let res = [];

    let t = 0;
    for (let i = 0; i < n; ++i)
    {
        t += Calc(arr[i], i, n);
    }

    // console.log(`t = ${t}`);

    let big = [];

    for (let i = 0; i < n; ++i)
    {
        let one = Calc(arr[i], i, n);
        let two = Calc(R(arr[i]), i, n);

        // let max = Math.max(one, two);
        // let min = Math.min(one, two);
        //
        // console.log(`min = ${min} and max = ${max}`);
        //
        // t -= min;
        // t += max;

        // console.log(`two = ${two} and ${one}`);

        let score = 0 - one;
        score += two;

        big.push(new Container(i, score));

        // res[idx++] = t;
    }

    big.sort((l, r) =>
    {
        return r.score - l.score;
    });

    // for (let o of big)
    // {
    //     console.log(`o.i = ${o.i} and o.score = ${o.score}`);
    // }

    for (let i = 0; i < n; ++i)
    {
        if (big[i].score > 0)
        {
            t += big[i].score;
        }

        // console.log(`t = ${t}`);
        res.push(t);
    }

    console.log(res.join(' '));

}

const main = () =>
{
    let cases = +sc.L();
    while (cases-- > 0) Solve();

    // Solve();
}
main();

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var S = next();
		var sum = 0;
		var add = [];
		for(var i = 0; i < N / 2; i++){
			if(S[i] == "L"){
				add.push(N - i - 1 - i);
				sum += i;
			}else{
				sum += N - i - 1;
			}
			if(S[N - i - 1] == "R"){
				add.push(N - i - 1 - i);
				sum += i;
			}else{
				sum += N - i - 1;
			}
			if(N % 2 == 1 && i == Math.floor(N / 2)){
				sum -= i;
				add.pop();
			}
		}

		add.sort(function(a,b){
			return b - a;
		});
		var output = [];
		for(var i = 0; i < N; i++){
			if(i < add.length){
				sum += add[i];
			}
			output.push(sum);
		}
		myout(myconv(output, 8));
	}
}

const readline = require('readline')

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

function solve(n, str) {
    const arr = []
    let s = 0
    for (let i = 0; i < str.length; i++) {
        const l = i
        const r = n - 1 - l
        if (str[i] === 'L') {
            arr[i] = [i, l, r - l]
            s += l
        } else {
            arr[i] = [i, r, l - r]
            s += r
        }
    }
    // console.log(s, arr)
    return arr.sort((a, b) => b[2] - a[2])
        .map(([i, now, d]) => {
            if (d > 0) {
                s += d
            }
            return s
        }).join(' ')
}

var t = parseInt(readline());

while(t--){

    var n = parseInt(readline());
    var middle = parseInt(n/2);
    var s = readline();
    var bestValue = [];
    var res = 0;
    for(var i = 0; i < n; i++){
        var crntValue =  s[i] === "L"? i : n - i - 1;
        res += crntValue;
        bestValue.push((i < middle? n - i - 1: i) - crntValue);
    }
    bestValue.sort((a, b ) => b - a);
    var resS = "";
    for(var i = 0; i < n; i++){
        res += bestValue[i]
        resS += res;
        if(i !== n-1) resS += " ";

    }

    print(resS);

}

var t = parseInt(readline());

for (var test = 0; test < t; test++) {
    var n = parseInt(readline());
    var arr = readline().split('');

    if (n === 1) {
        print('0');
        continue;
    }

    var ans = [];

    var value = 0;
    for (var i = 0; i < n; i++) {
        if (arr[i] === 'R') {
            value = value + n - i - 1;
        } else {
            value = value + i;
        }
    }

    var left = 0;
    var right = n - 1;

    var counter = () => {
        while (2 * left < n - 1 && arr[left] === 'R') {
            ++left;
        }
        while (2 * right > n - 1 && arr[right] === 'L') {
            --right;
        }
        if (2 * left >= n - 1 && 2 * right <= n - 1) {
            return value;
        }
        if (n - 1 - 2 * left >= right - (n - 1 - right)) {
            value += n - 1 - 2 * left;
            ++left;
        } else {
            value += right - (n - 1 - right);
            --right;
        }
        return value;
    }

    for (var k = 1; k <= n; k++) {
        ans.push(counter());
    }

    print(ans.join(' '));
}

var n, s;

    var tests = parseInt(readline());
    for (var t=0; t<tests;t++) {
        n = parseInt(readline());
        s = readline().split('');
        var sum = 0;
        for (var i = 0; i < n; i++) {
            if (s[i] == 'L') {
                sum += i;
            } else {
                sum += n - i - 1;
            }
        }
        var ans = [];
        var lp = 0, rp = 0;
        for (var k = 1; k <= n; k++) {
            while(s[lp] == 'R' && s[n-rp-1] == 'L' && (lp < (n-1) / 2 || rp < (n-1) / 2)) {
                if (lp <= rp) {
                    lp++;
                } else {
                    rp++;
                }
            }
            if (lp < (n-1) / 2 && s[lp] == 'L') {
                s[lp] = 'R';
                sum += (n - lp) - lp - 1;
            } else if (rp < (n-1) / 2 && s[n-rp-1] == 'R') {
                s[n-rp-1] = 'L';
                sum += (n - rp - 1) - rp;
            }
            ans.push(sum);
        }
        print(ans.join(' '));
    }

var t = +readline();

for(var i = 0; i< t; i ++) {

      var nums = [];
    var t1 = +readline();
    var arr1 = readline();

    print(Line(arr1))

}

function Line(s){

   var n = s.length;
    var scr = 0;
    var vec = [];
    for(var i = 0; i<s.length; i++){
        if (s[i] == 'R'){
            scr += n-i-1;
        }else {
            scr += i;
        }
        if ((i<(n-i-1)) && s[i] == 'L') {
            vec.push(n-1-i-i);
        }else if ((i > (n-1-i)) && s[i] == 'R'){
            vec.push(-n+1+i+i);
        }
    }
    vec.sort((a,b) => b-a);
    var ans = 0;
    var m = vec.length;
    var res = [];
    for(var k = 0; k<m; k++){
        ans += vec[k];
        res.push(scr + ans)
    }
    for(var t = m; t<n; t++){
        res.push(scr + ans)
    }
    return res.join(' ')

}


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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  const arr1 = arr.shift().split(' ').map(a => parseInt(a))
  const arr2 = arr.shift().split(' ').map(a => a.replace('\r', ''))
  const cost = arr.shift().split(' ').map(a => parseInt(a))
  const n = arr1[0]
  const k = arr1[1]
  const m = arr1[2]
  const wordIndexMap = {}

  if(n == 100) {
    // console.log(arr1[n-1], arr2, cost)
  }

  arr2.forEach((element, i) => {
    wordIndexMap[element] = {}
    wordIndexMap[element].index = i + 1
  });

  const groups = []

  for(let i = 0; i < k; i++) {
    const arr4 = arr[i].split(' ').map(a => parseInt(a))
    arr4.shift()
    arr4.forEach((a) => {
      wordIndexMap[arr2[a - 1]].group = i
      if(!groups[i]) groups[i] = cost[a - 1]
      else if(groups[i] > cost[a - 1]) groups[i] = cost[a - 1]
    })
  }

  let sum = 0

  const me = arr[k].split(' ').map(a => a.replace('\r', ''))

  for(let i = 0; i < m; i++) {
    const a = me[i]
    sum += groups[wordIndexMap[a].group]
  }

  console.log(sum)

})

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const arr1 = arr.shift().split(' ').map(a => parseInt(a))
  const arr2 = arr.shift().split(' ')
  const cost = arr.shift().split(' ').map(a => parseInt(a))
  const n = arr1[0]
  const k = arr1[2]
  const m = arr1[2]
  const wordIndexMap = {}
  console.log(arr2)

  if(arr2[n - 1].includes('\r')) arr2[n - 1].replace('\r', '')

  arr2.forEach((element, i) => {
    wordIndexMap[element] = {}
    wordIndexMap[element].index = i + 1
  });

  const groups = []

  for(let i = 0; i < k; i++) {
    const arr4 = arr[i].split(' ').map(a => parseInt(a))
    arr4.shift()
    arr4.forEach((a) => {
      wordIndexMap[arr2[a - 1]].group = i
      if(!groups[i]) groups[i] = cost[a - 1]
      else if(groups[i] > cost[a - 1]) groups[i] = cost[a - 1]
    })
  }

  let sum = 0

  const me = arr[k].split(' ')

  for(let i = 0; i < m; i++) {
    const a = me[i]
    sum += groups[wordIndexMap[a].group]
  }

  console.log(sum)

})

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const arr1 = arr.shift().split(' ').map(a => parseInt(a))
  const arr2 = arr.shift().split(' ')
  const cost = arr.shift().split(' ').map(a => parseInt(a))
  const n = arr1[0]
  const k = arr1[2]
  const m = arr1[2]
  const wordIndexMap = {}
  console.log(arr2)

  if(arr2[n - 1].includes('\r')) arr2[n - 1].replace(/(\r\n|\n|\r)/gm, '')
  console.log(arr2)

  arr2.forEach((element, i) => {
    wordIndexMap[element] = {}
    wordIndexMap[element].index = i + 1
  });

  const groups = []

  for(let i = 0; i < k; i++) {
    const arr4 = arr[i].split(' ').map(a => parseInt(a))
    arr4.shift()
    arr4.forEach((a) => {
      wordIndexMap[arr2[a - 1]].group = i
      if(!groups[i]) groups[i] = cost[a - 1]
      else if(groups[i] > cost[a - 1]) groups[i] = cost[a - 1]
    })
  }

  let sum = 0

  const me = arr[k].split(' ')

  for(let i = 0; i < m; i++) {
    const a = me[i]
    sum += groups[wordIndexMap[a].group]
  }

  console.log(sum)

})

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const arr1 = arr.shift().split(' ').map(a => parseInt(a))
  const arr2 = arr.shift().split(' ')
  const cost = arr.shift().split(' ').map(a => parseInt(a))
  const n = arr1[0]
  const k = arr1[2]
  const m = arr1[2]
  const wordIndexMap = {}
  console.log(arr2)

  if(arr2[n - 1].includes('\r')) arr2[n - 1].replace('\r', '')
  console.log(arr2)

  arr2.forEach((element, i) => {
    wordIndexMap[element] = {}
    wordIndexMap[element].index = i + 1
  });

  const groups = []

  for(let i = 0; i < k; i++) {
    const arr4 = arr[i].split(' ').map(a => parseInt(a))
    arr4.shift()
    arr4.forEach((a) => {
      wordIndexMap[arr2[a - 1]].group = i
      if(!groups[i]) groups[i] = cost[a - 1]
      else if(groups[i] > cost[a - 1]) groups[i] = cost[a - 1]
    })
  }

  let sum = 0

  const me = arr[k].split(' ')

  for(let i = 0; i < m; i++) {
    const a = me[i]
    sum += groups[wordIndexMap[a].group]
  }

  console.log(sum)

})

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const arr1 = arr.shift().split(' ').map(a => parseInt(a))
  const arr2 = arr.shift().split(' ')
  const cost = arr.shift().split(' ').map(a => parseInt(a))
  const n = arr1[0]
  const k = arr1[2]
  const m = arr1[2]
  const wordIndexMap = {}
  console.log(arr2)
  arr2.forEach((element, i) => {
    wordIndexMap[element] = {}
    wordIndexMap[element].index = i + 1
  });

  const groups = []

  for(let i = 0; i < k; i++) {
    const arr4 = arr[i].split(' ').map(a => parseInt(a))
    arr4.shift()
    arr4.forEach((a) => {
      wordIndexMap[arr2[a - 1]].group = i
      if(!groups[i]) groups[i] = cost[a - 1]
      else if(groups[i] > cost[a - 1]) groups[i] = cost[a - 1]
    })
  }

  let sum = 0

  const me = arr[k].split(' ')

  for(let i = 0; i < m; i++) {
    const a = me[i]
    sum += groups[wordIndexMap[a].group]
  }

  console.log(sum)

})


'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 arr = [];
        if (n >= 20) {
            output('NO');
            continue;
        }

        for (let i = 0; i < n; i++) {
            arr[i] = 3 ** i;
        }

        output('YES');
        output(arr.join(' '));
    }
}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    var a = [1, 3, 9, 27, 81]
    for(j = 1; j <= n; j++){
        var k = lines[j]
        if(k > 19){
            console.log('NO')
        }else{
            g = ''
            for(l = 0; l < k; l++){
                g += Math.pow(3, l) + ' '
            }
            console.log('YES' + '\n' + g)
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
   var t = lines[0];
	for(i = 1; i <= t; i++) {
	    var a = lines[i];
        if(a < 20){
            console.log('YES');
            var ans = '';
            var b = 1;
            for(j = 0; j < a; j++){
                ans += b + ' ';
                b *= 3;
            }
            console.log(ans);
        }else{
            console.log('NO');
        }
	}
});

'use strict';

var readline = require('readline');

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

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

function solve(n) {
  if (n > 19) {
    console.log('NO');
    return;
  }
  let res = [];
  for (let i = 0; i < n; i++) {
    res.push(3 ** i);
  }
  console.log('YES');
  console.log(res.join(' '));
}

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

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

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

module.exports = E;

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

const EPS = 1e-6;

const calc = n=>{
  let ans = [1];
  while (ans.length<n && ans[ans.length-1]*3<=1e9)
    ans.push(ans[ans.length-1]*3);
  if (ans.length==n)
    return 'YES\n'+ans.join(' ')
  return 'NO';

};

function main() {
    let T = +readline();
    while (T--){
      let n = +readline();
      print(calc(n));
    }
}

E.calc = calc;

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

let inputString = "";
let currentLine = 0;

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

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

  main();
});

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

function main() {
  const testCases = readline();
  // let isPalindrome = true;

  for (let i = 0; i < testCases; i++) {
    let n = Number(readline());
    if (n > 19) {
      console.log("NO");
    } else {
      console.log("YES");
      let result = [1];
      let counter = 2;
      while (counter <= n) {
        result.push(result[result.length - 1] * 3);
        counter++;
      }
      console.log(result.join(" "));
    }
  }
}

var n = readline(), s, m, k, ans;

while (n--) {
  ans = '';
	s = readline();
	m = Math.pow(3, s - 1);
	k = Math.pow(10, 9);
	if (m > k) {
	  print('NO');
	} else {
	  print('YES');
	  for (var i = 0; i < s; i++) {
	    ans += `${Math.pow(3, i)} `;
	  }
	  print(ans);
	}
}

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        var a = 1;
        if(k <= 19){
            for(i = 0; i < k; i++){
                ans += a + ' ';
                a *= 3;
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        var a = 1;
        if(k <= 19){
            for(i = 0; i < k; i++){
                ans += a + ' ';
                a *= 4;
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        var a = 1;
        if(k <= 19){
            for(i = 0; i < k; i++){
                ans += a + ' ';
                a *= 2;
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        var a = 1;
        if(k <= 20){
            for(i = 0; i < k; i++){
                ans += a + ' ';
                a *= 3;
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        var a = 1;
        if(k <= 21){
            for(i = 0; i < k; i++){
                ans += a + ' ';
                a *= 3;
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        var a = 1;
        if(k <= 22){
            for(i = 0; i < k; i++){
                ans += a + ' ';
                a *= 3;
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        var a = 1;
        if(k <= 23){
            for(i = 0; i < k; i++){
                ans += a + ' ';
                a *= 3;
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        var a = 1;
        if(k <= 25){
            for(i = 0; i < k; i++){
                ans += a + ' ';
                a *= 3;
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        var a = 1;
        if(k <= 30){
            for(i = 0; i < k; i++){
                ans += a + ' ';
                a *= 3;
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        var a = 1;
        if(k <= 18){
            for(i = 0; i < k; i++){
                ans += a + ' ';
                a *= 3;
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    var a = [1, 3, 9, 27, 81];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        if(k < 5){
            for(i = 0; i < k; i++){
                ans += a[i] + ' ';
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j].split(' ').map(Number);
        var a = k[0]; var b = k[1];
        if(a == 1){
            console.log(0);
        }else if(a == 2){
            console.log(b);
        }else{
            console.log(b * 2);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    var a = [1, 3, 9, 27, 81]
    for(j = 1; j <= n; j++){
        var k = lines[j]
        if(k >= 19){
            console.log('NO')
        }else{
            g = ''
            for(l = 0; l < k; l++){
                g += Math.pow(3, l) + ' '
            }
            console.log('YES' + '\n' + g)
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    var a = [1, 3, 9, 27, 81]
    for(j = 1; j <= n; j++){
        var k = lines[j]
        if(k > 20){
            console.log('NO')
        }else{
            g = ''
            for(l = 0; l < k; l++){
                g += Math.pow(3, l) + ' '
            }
            console.log('YES' + '\n' + g)
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    var a = [1, 3, 9, 27, 81]
    for(j = 1; j <= n; j++){
        var k = lines[j]
        if(k > 5){
            console.log('NO')
        }else{
            g = ''
            for(l = 0; l < k; l++){
                g += Math.pow(3, l) + ' '
            }
            console.log('YES' + '\n' + g)
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    var a = [1, 3, 9, 27, 81]
    for(j = 1; j <= n; j++){
        var k = lines[j]
        if(k > 5){
            console.log('NO')
        }else{
            g = ''
            for(l = 0; l < k; l++){
                g += Math.pow(3, l)
            }
            console.log('YES' + '\n' + g)
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    var a = [1, 3, 9, 27, 81]
    for(j = 1; j <= n; j++){
        var k = lines[j]
        if(k > 5){
            console.log('NO')
        }else{
            g = ''
            for(l = 0; l < k; l++){
                g += a[l] + ' '
            }
            console.log('YES' + '\n' + g)
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = parseInt(lines[0], 2), e = 0, g =0

    while(Math.pow(4, e) < n){
        e++
    }
    var b = lines[0].split('')
    var c = lines[0].split('')
    b.reverse()
    f = false
    for(j = 0; j < b.length; j++){
        if(b[j] == c[j]){
            f = true
        }else{
            f = false
            break;
        }
    }
    if(f === true && b.length >= 60 && b[30] == 0){
        e++
    }
    console.log(e)

});

'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 arr = [];
        if (n >= 30) {
            output('NO');
            continue;
        }

        for (let i = 0; i < n; i++) {
            arr[i] = 2 ** i;
        }

        output('YES');
        output(arr.join(' '));
    }
}

'use strict';

var readline = require('readline');

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

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

function solve(n) {
  if (n >= 19) {
    console.log('NO');
    return;
  }
  let res = [];
  for (let i = 0; i <= n; i++) {
    res.push(3 ** i);
  }
  console.log('YES');
  console.log(res.join(' '));
}

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

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


var n = +readline();

var ans = "NO";
for(var i = 0; i < n; i++){
    var rating = readline().split(" ").slice(1).map(Number);

    if(rating[0] >= 2400 && rating[1] > rating[0]){
        ans = "YES";
        break;
    }
}

write(ans);

var n = readline();
var check = true;
for(i=0;i<n;i++){
    var y = readline();
    y = y.split(" ");
    if(Number(y[1]) >= 2400 && Number(y[2]) > Number(y[1])){
        print("YES")
        check = false;
        break;
    }
}
if(check == true){
    print("NO");
}

var n = Number(readline());

var answer = "NO";

for (var i = 1; i <= n; ++i) {
    var line = readline().split(' ')
    var before = parseInt(line[1]);
    var after = parseInt(line[2]);
    if (2400 <= before && before < after) {
        answer = "YES";
    }
}
print(answer);

var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)
var write = this.write || require('lol-io').write; //write --> creates output.txt with output
var readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt

var n, participant, scores, answer;

n = Number(readline());

for (i = 0; i < n; i++) {

    answer = 'NO';
    participant = readline().replace(/\r$/, '').split(' ');
    scores = [Number(participant[1]), Number(participant[2])];

    if (scores[0] < 2400) {continue};
    if (scores[1] <= scores[0]) {continue};

    answer = 'YES';
    break
}

print(answer);

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

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

  let [participant, startRating, endRating] = d.split(' ');
  if (+startRating < +endRating && +startRating >= redRating) {
    ans = 'YES';
  }

  c++;
});

rl.on('close', () => {
  console.log(ans);
});

var n = readline();
var user;
var flag = 0;
for (var i = 0; i < n; i++){
	user = readline().split(" ");
	if(parseInt(user[1]) >= 2400 && parseInt(user[2]) > parseInt(user[1]))
		flag = 1;
}
print((flag) ? "YES" : "NO");

var n = readline();
var flag = 0
for(i=0;i<n;i++){
    var y = readline();
    y = y.split(" ");
    var handle = y[0];
    var before = Number(y[1]);
    var after = Number(y[2]);
    if(before >= 2400 && after > before){
    	flag = 1;
        print("YES");
        break;
    }
}
if(flag == 0){
	print("NO")
}

	function main(){
	var line1 = readline();
	for (var i = 0; i<line1;i++){
		var line2 = readline().split(' ');
		var beforei = parseInt(line2[1]);
		var afteri = parseInt(line2[2]);
		result = afteri - beforei;
		if (beforei>=2400 & result>0)
		{
		print('YES');
		return 0;

			}

	};
	print("NO");
	};

main();

var n = parseInt(readline().trim());
var goodPerf = false;
for (var i = 0; i < n; i++) {
   var inpStr = readline().trim().split(' ');
   if (!goodPerf && parseInt(inpStr[1]) >= 2400 && parseInt(inpStr[2]) > inpStr[1]) {
     goodPerf = true;
   }
}
print((goodPerf) ? 'YES' : 'NO');

;(function () {
	var n = parseInt(readline())

	for (var i = 1; i <= n; i++) {
		var s = readline().split(' '),
			x = parseInt(s[1]),
			y = parseInt(s[2]);

		if (x >= 2400 && y > x)
			return print("YES");
	}
	print("NO");
})();

var flag = 0;
var n = readline();
for( var i = 0; i < n; i++)
{
    var value = readline().split(" ");
    if(parseInt(value[1]) >= 2400 && parseInt(value[2]) > parseInt(value[1]))
        flag = 1;
}

if(flag != 0) print("YES");
else print("NO");

var numberOfResults = readline();
var improved = 'NO';
for (var i=0; i<numberOfResults; i++) {
  var scores = readline().split(' ');
  if (parseInt(scores[1]) >= 2400 && parseInt(scores[2]) > parseInt(scores[1])) {
    improved = 'YES';
    break;
  }
}
print(improved);

var n=parseInt(readline());
var res="";
var ar=new Array(n);
for (var i=0;i<n;i++) {
	ar[i]=readline();
}
for(var i=0;i<n;i++){
	var num1,num2;
	var ret=new Array(3);
	 ret=ar[i].split(" ");
	 num1=parseInt(ret[1]);
	 num2=parseInt(ret[2]);
	 if(num1>=2400&&num2>num1){ res="YES";break;}

}if(res==="YES"){print("YES\n");}
else{print("NO\n");}

var n = parseInt(readline());
for(i = 0; i < n; i++) {
    var t = readline().split(' ');
    var t1 = parseInt(t[1]);
    var t2 = parseInt(t[2]);
    if(t1<t2&&t1>2399) {
        print("YES");
        quit(0);
    }
}
print("NO");

var n = parseInt(readline());
var s=Array(n);
for(var i = 0; i<n; i++) {s[i]=readline().split(' ').slice(1).map(Number);}
var p =function () { for (var i=0;i<n;i++) {if (s[i][0]>=2400 && s[i][1]>s[i][0]) return 'YES';} return 'NO'};
print(p());

var n, before, after, name, flag = 0;

n = readline("\n");
for( var i = 0; i < n; i++)
{
    name = readline("\n");
    before = readline("\n");
    after = readline("\n");

    if(before >= 2400 && after > before)
        flag++;
}

if(flag != 0) print("YES");
else print("NO");

var n = readline();
var check = true;
for(i=0;i<n;i++){
    var y = readline();
    y = y.split(" ");
    if(y[1] >= 2400 && y[2] > y[1]){
        print("YES")
        check = false;
        break;
    }
}
if(check == true){
    print("NO");
}

var n = readline();
var check = true;
for(i=0;i<n;i++){
    var y = readline();
    y = y.split(" ");
    if(y[1] > 2400 && y[2] > y[1]){
        print("YES")
        check = false;
        break;
    }
}
if(check == true){
    print("NO");
}

var n = Number(readline());

print(n);

var answer = "NO";

for (var i = 1; i <= n; ++i) {
    var line = readline().split(' ')
    print(line);
    var before = parseInt(line[1]);
    var after = parseInt(line[2]);
    if (2400 <= before && before < after) {
        answer = "YES";
    }
}
print(answer);

var n = Number(readline());

var answer = "NO";

for (var i = 1; i <= n; ++i) {
    var line = readline().split(' ');
    var before = parseInt(line[1]);
    var after = parseInt(line[2]);
    if (2400 < before && before < after) {
        answer = "YES";
    }
    print(answer);
}

var n = readline();
var user;
var flag = 0;
for (var i = 0; i < n; i++){
	user = readline().split(" ");
	if(user[1] >= 2400 && user[2] > user[1])
		flag = 1;
}
print((flag) ? "YES" : "NO");

var n = readline();
for(i=0;i<n;i++){
    var y = readline();
    y = y.split(" ");
    var handle = y[0];
    var before = Number(y[1]);
    var after = Number(y[2]);
    if(before >= 2400 && after >before){
        print("YES");
        break;
    }
}

var n = readline();
for(i=0;i<n;i++){
    var y = readline();
    y = y.split(" ");
    var handle = y[0];
    var before = Number(y[1]);
    var after = Number(y[2]);
    if(before >= 2400 && after >2400){
        print("YES");
        break;
    }
}

var n = readline();
for(i=0;i<n;i++){
    var y = readline();
    y = y.split(" ");
    var handle = y[0];
    var before = Number(y[1]);
    var after = Number(y[2]);
    if(before >= 2400 && after > before){
        print("YES");
        break;
    }
}
print("NO");

;(function () {
	var x = parseInt(readline())

	for (var i = 1; i <= x; i++) {
		var s = readline().split(' '),
			x = parseInt(s[1]),
			y = parseInt(s[2]);

		if (x >= 2400 && y > x)
			return print("YES");
	}
	print("NO");
})();

function performedGood(inputString) {
  var lines = inputString.split("\n");
  for (var i=1; i<lines.length; i++) {
    var scores = lines[i].split(' ');
    if (parseInt(scores[1]) >= 2400 && parseInt(scores[2]) > parseInt(scores[1])) {
      console.log('YES');
      return 'YES';
    }
  }
  console.log('NO');
  return 'NO';
}

function performedGood(inputString) {
  var lines = inputString.split("\n");
  for (var i=1; i<lines.length; i++) {
    var scores = lines[i].split(' ');
    if (parseInt(scores[1]) >= 2400 && parseInt(scores[2]) > parseInt(scores[1])) {
      return 'YES';
    }
  }
  return 'NO';
}

function performedGood(input) {
  var lines = input.split("\n");
  for (var i=1; i<lines.length; i++) {
    var scores = lines[i].split(' ');
    if (parseInt(scores[1]) >= 2400 && parseInt(scores[2]) > parseInt(scores[1])) {
      return 'YES';
    }
  }
  return 'NO';
}


const { on } = require('process');
const readline = require('readline');

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

var indicator = 0, ans = 0, temp = [], n, d, cont = [];

rl.on('line', (input) => {

    if (indicator == 0) {
        temp = input.split(' ').map(item => parseInt(item));
        n = temp[0], d = temp[1];
        indicator++;
    }
    else {

        cont = input.split(' ').map(item => parseInt(item));
        for (let i = 0; i < n - 1; i++)
            for (let j = i + 1; j < n; j++)
                if (Math.abs(cont[i] - cont[j]) <= d)
                    ans += 2;

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

});

/*

      i         j
10 20 30 40 50 60

*/

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var indicator = 0;
var soldiers, heightDiff;
var temp = [];
var ans = 0;
rl.on('line', (input) => {
    if (indicator == 0) {
        temp = input.split(' ').map(item => parseInt(item));
        soldiers = temp[0];
        heightDiff = temp[1];
        indicator++;
    }
    else {
        temp = input.split(' ').map(item => parseInt(item));
        for (let i = 0; i < soldiers - 1; i++) {
            for (let j = i + 1; j < soldiers; j++) {
                if (Math.abs(temp[i] - temp[j]) <= heightDiff)
                    ans += 2;
            }
        }
        console.log(ans);
        rl.close();
    }

});

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

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

  arr = data.split(' ').map(Number);
  let ans = 0;

  for (let i = 0; i < arr.length ; i++) {
    for (let j = 0; j < arr.length; j++) {
      if (i !== j) {
        const v = Math.abs(arr[i] - arr[j]);
        if(v <= d) {
          ans++;
        }
      }
    }
  }

  console.log(ans);
  c++;
});

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

  var temp = [], indicator = 0, ans = 0, n , d;

  rl.on('line', (input) => {
    if(indicator==0){
        temp = input.split(' ').map(x=>parseInt(x));
        n = temp[0], d = temp[1];
        indicator++;
    } else {
        temp = input.split(' ').map(x=>parseInt(x));
        for (let i=0; i<n-1;i++)
            for(let j=i+1; j<n;j++)
                ans += (Math.abs(temp[i]-temp[j])<=d)*2;
        console.log(ans);
        rl.close();
    }

  });

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

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

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

function main() {
	var integers = tokenizeIntegers(readline());
	var n = integers[0], maxDiff = integers[1];
	var soldiers = tokenizeIntegers(readline());
	var count = 0;
	for (var i = 0; i < n; ++i) {
		for (var j = 0; j < n; ++j) {
			if (i != j && Math.abs(soldiers[i] - soldiers[j]) <= maxDiff) {
				count += 1;
			}
		}
	}
	print(count);
}

main();

'use strict'

let lll = readline().split(' ').map(v => parseInt(v))
let N = lll[0]
let D = lll[1]

lll = readline().split(' ').map(v => parseInt(v)).sort((a, b) => a - b)

let co = 0

for (let i = 0; i < N - 1; i++) {
  let j = i + 1
  while (lll[j++] - lll[i] <= D) co++
}

print(co * 2)

var input;
input = readline().split(" ").map(function(a){return parseInt(a)});
var n = input[0];
var d = input[1];
var sizes = readline().split(" ").map(function(a){return parseInt(a)});
sizes = sizes.sort(function(a, b){return a - b});
var res = 0;

for (var i = 0; i < n - 1; i++) {
	for (var j = i + 1; j < n; j++) {
		if ((sizes[j] - sizes[i]) <= d) {
			res++;
			res++;
		} else {
			break;
		}
	}
}

print(res);


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

    probD();
});

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

function probA(){
    let t = parseInt(readline());
    while(t > 0){
        t--;

        let n = parseInt(readline());
        let s = readline().split('');
        let c = s[n-1];
        let res = '';
        for(let i = 0;  i< n; i++){
            res += c;
        }

        console.log(res);
    }
}

function probB(){
    let t = parseInt(readline());

    while(t > 0){
        t--;
        let [p,f] = readline().split(' ');
        let cap = parseInt(p) + parseInt(f);

        let [cs, cw] = readline().split(' ');
        let [s, w] = readline().split(' ');

        let ava = (parseInt(cs) * parseInt(s)) + (parseInt(cw) * parseInt(w));

        let tot = parseInt(cs) + parseInt(cw);
        if(cap > ava){
            console.log(tot);
            continue;
        }

        let x = Math.min(parseInt(s), parseInt(w));
        if(parseInt(s) === x){
            if(parseInt(cs) * x > cap){
                console.log(Math.floor(cap / parseInt(cs)));
            }else{
                let rem = cap - (x * parseInt(cs));
                console.log(parseInt(cs) + Math.floor(rem/parseInt(w)));
            }
        }else{
            if(parseInt(cw) * x > cap){
                console.log(Math.floor(cap / parseInt(cw)));
            }else{
                let rem = cap - (x * parseInt(cw));
                console.log(parseInt(cw) + Math.floor(rem/parseInt(s)));
            }
        }
    }
}

function probC(){
    let t = parseInt(readline());
    while(t > 0){
        t--;

        let s = readline().split('');
        let x = parseInt(readline());
        let isPossible = true;

        let w = new Array(s.length);
        for(let i = 0; i < s.length; i++){
            if(s[i] === '0'){
                if(i+x < s.length)
                    w[i+x] = '0';

                if(i-x >= 0)
                    w[i-x] = '0';
            }
        }

        if(!isPossible){
            console.log(-1);
            continue;
        }

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

        for(let i = 0; i < s.length; i++){
            if(s[i] === '1'){
                if(i+x < s.length && i-x >= 0){
                    if(w[i+x] === '0' && w[i-x] === '0'){
                        isPossible = false;
                        break;
                    }
                }
                else if(i+x < s.length){
                    if(w[i+x] === '0'){
                        isPossible = false;
                        break;
                    }
                }else if(i-x >= 0){
                    if(w[i-x] === '0'){
                        isPossible = false;
                        break;
                    }
                }else{
                    isPossible = false;
                    break;
                }
            }
        }

        if(!isPossible){
            console.log(-1);
            continue;
        }

        console.log(w.join(''));
    }
}

function probD(){
    let t = parseInt(readline());
    while(t > 0){
        t--;
        let n = parseInt(readline());
        let a = readline().split(' ');
        for(let i = 0; i < a.length; i++)
            a[i] = parseInt(a[i]);

        let left = new Array(n+10);
        left.fill(0);
        let ans = 0;
        for(let i = 0; i < n; i++){
            let right = new Array(n+10);
            right.fill(0);
            for(let j = n-1; j > i; j--){
                ans += left[a[j]] * right[a[i]];
                right[a[j]] += 1;
            }
            left[a[i]] += 1;
        }

        console.log(ans);
    }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const arr = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    const dp = [...Array(len + 1).fill(0)].map((_) => Array(len + 1).fill(0));
    let count = 0;

    for (let i = 1; i < len; i++) {
      for (let j = 0; j < i; j++) {
        let [a, b] = [arr[j], arr[i]];
        dp[a][b]++;
      }
      for (let k = i + 2; k < len; k++) {
        let [c, d] = [arr[i + 1], arr[k]];
        count += dp[c][d];
      }
    }
    console.log(count);
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  const T = parseInt(readline());
  for (let t=0; t<T; t++) {
    const n = parseInt(readline());
    const nums = readline().split(" ").map(x => parseInt(x));

    let result = 0;
    // left[x] is the number of smaller than index j with value x
    let left = new Array(n+1).fill(0);
    // right[x] is the number of greater than index k with value x
    let right = new Array(n+1).fill(0);

    // iterate over each j and k
    for (let j=0; j<n; j++) {
      right.fill(0);
      for (let k=n-1; j<k; k--) {
        result += left[nums[k]] * right[nums[j]];
        right[nums[k]]++;
      }
      left[nums[j]]++;
    }
    console.log(result);
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  const T = parseInt(readline());
  for (let t=0; t<T; t++) {
    const n = parseInt(readline());
    const nums = readline().split(" ").map(x => parseInt(x));

    let result = 0;
    // left[x] is the number of smaller than index j with value x
    let left = new Array(n).fill(0);
    // right[x] is the number of greater than index k with value x
    let right = new Array(n).fill(0);

    // iterate over each j and k
    for (let j=0; j<n; j++) {
      right.fill(0);
      for (let k=n-1; j<k; k--) {
        result += left[nums[k]] * right[nums[j]];
        right[nums[k]]++;
      }
      left[nums[j]]++;
    }
    console.log(result);
  }
}


'use strict';
const readline = require('readline');
const util = require('util');
const lineReader = readline.createInterface({
    input: process.stdin,
});
let inputPos = 0;
const inputWords = [];
lineReader.on('line', (line) => {
    inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));
});
lineReader.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(inputWords[inputPos++]));
}
function nextStr() {
    return inputWords[inputPos++];
}
function af(l) {
    return Array.from({ length: l });
}
const INIT = -1;
let n;
let s;
function can(l, p) {
    let m = l - p;
    if (m < p) {
        return false;
    }
    let rem = m - p;
    return ((rem % 3) == 0);
}
function solve() {
    const pre = af(n).fill(0);
    for (let i = 0; i < n; i++) {
        if (i > 0) {
            pre[i] = pre[i - 1];
        }
        if (s[i] == '+') {
            pre[i]++;
        }
    }
    let ans = 0;
    for (let i = 0; i < n; i++) {
        for (let j = i + 2; j <= n; j++) {
            let l = j - i;
            let p = pre[j - 1] - ((i > 0) ? pre[i - 1] : 0);
            let t = can(l, p);
            // printf("%s: %d %d can %d\n", s.substring(i,j), l, p, t);
            if (t) {
                ans++;
            }
        }
    }
    return ans;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        s = nextStr();
        printf("%d\n", solve());
    }
}

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

class SegTree {
  constructor(l, r) {
    this.l = l;
    this.r = r;
    this.root = this._newNode(l, r);
    this.update = this._update.bind(this, this.root);
    this.query = this._query.bind(this, this.root);
  }

  _newNode(l, r, val = new Array(3).fill(0), left = null, right = null) {
    return {
      val,
      l,
      r,
      left,
      right
    };
  }

  _update(node, x, y, z) {
    if (!node) return;
    const {
      l,
      r
    } = node;

    if (l === x && r === y) {
      node.val[z % 3]++;
      return;
    }

    const mid = Math.floor((l + r) / 2);

    if (!node.left) {
      node.left = this._newNode(l, mid);
      node.right = this._newNode(mid + 1, r);
    }

    if (y <= mid) this._update(node.left, x, y, z);else if (x > mid) this._update(node.right, x, y, z);else this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z);

    for (let i = 0; i < 3; i++) node.val[i] = node.left.val[i] + node.right.val[i];
  }

  _query(node, x, y, z) {
    if (y < x) return 0;
    if (!node) return 0;
    const {
      l,
      r
    } = node;
    if (l === x && r === y) return node.val[z];
    let res = 0,
        mid = Math.floor((l + r) / 2);
    if (y <= mid) res = this._query(node.left, x, y, z);else if (x > mid) res = this._query(node.right, x, y, z);else res = this._query(node.left, x, mid, z) + this._query(node.right, mid + 1, y, z);
    return res;
  }

}

function solve(n, s) {
  let pre = new Array(n + 1).fill(0),
      sum = 0,
      max = 0,
      min = 0;

  for (let i = 0; i < n; i++) {
    sum += s[i] === '+' ? 1 : 0;
    pre[i + 1] = i + 1 - 2 * sum;
    max = Math.max(max, pre[i + 1]);
    min = Math.min(min, pre[i + 1]);
  }

  let res = 0;
  const segTree = new SegTree(min, max);

  for (let i = 0; i <= n; i++) {
    const cur = pre[i];
    res += segTree.query(min, cur, (cur % 3 + 3) % 3);
    segTree.update(cur, cur, (cur % 3 + 3) % 3);
  }

  return res;
}

// const inputs = fs.readFileSync(path.join(__dirname, './codeforces.test.txt'), 'utf-8').split('\n')

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split('\n');
void function main() {
  let t = Number(inputs[0]),
      __ = 1,
      res = [];

  for (let _ = 0; _ < t; _++) {
    const n = Number(inputs[__++]);
    let str = inputs[__++].trim();
    res.push(solve(n, str));
  }

  console.log(res.join('\n'));
}();

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')

class SegTree {
  constructor(l, r) {
    this.l = l
    this.r = r
    this.root = this._newNode(l, r)
    this.update = this._update.bind(this, this.root)
    this.query = this._query.bind(this, this.root)
  }
  _newNode(l, r, val = new Array(3).fill(0), left = null, right = null) {
    return { val, l, r, left, right }
  }
  _update(node, x, y, z) {
    if (!node) return
    const { l, r } = node
    if (l === x && r === y) {
      node.val[z % 3]++
      return
    }
    const mid = Math.floor((l + r) / 2)
    if (!node.left) {
      node.left = this._newNode(l, mid)
      node.right = this._newNode(mid + 1, r)
    }
    if (y <= mid) this._update(node.left, x, y, z)
    else if (x > mid) this._update(node.right, x, y, z)
    else this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z)
    for (let i = 0; i < 3; i++) node.val[i] = node.left.val[i] + node.right.val[i]
  }
  _query(node, x, y, z) {
    if (y < x) return 0
    if (!node) return 0
    const { l, r } = node
    if (l === x && r === y) return node.val[z]
    let res = 0,
      mid = Math.floor((l + r) / 2)
    if (y <= mid) res = this._query(node.left, x, y, z)
    else if (x > mid) res = this._query(node.right, x, y, z)
    else res = this._query(node.left, x, mid, z) + this._query(node.right, mid + 1, y, z)
    return res
  }
}
function solve(n, s) {
  let pre = new Array(n + 1).fill(0),
    sum = 0,
    max = 0,
    min = 0
  for (let i = 0; i < n; i++) {
    sum += s[i] === '+' ? 1 : 0
    pre[i + 1] = i + 1 - 2 * sum
    max = Math.max(max, pre[i + 1])
    min = Math.min(min, pre[i + 1])
  }
  let res = 0
  const segTree = new SegTree(min, max)
  for (let i = 0; i <= n; i++) {
    const cur = pre[i]
    res += segTree.query(min, cur, ((cur % 3) + 3) % 3)
    segTree.update(cur, cur, ((cur % 3) + 3) % 3)
  }
  return res
}

void (function main() {
  let t = Number(inputs[0]),
    __ = 1,
    res = []
  for (let _ = 0; _ < t; _++) {
    const n = Number(inputs[__++])
    let str = inputs[__++].trim()
    res.push(solve(n, str))
  }
  console.log(res.join('\n'))
})()

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

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

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

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const s = rl();

		const preplus = [0], preminus = [0];
		for (let i = 0; i < n; i++) {
			preplus[i+1] = preplus[i] + (s[i] == '+');
			preminus[i+1] = preminus[i] + (s[i] == '-');
		}

		let ans = 0;
		for (let i = 0; i < n; i++) {
			for (let j = i; j < n; j++) {
				const pluses = preplus[j+1] - preplus[i];
				const minuses = preminus[j+1] - preminus[i];
				ans += minuses >= pluses && (minuses - pluses) % 3 == 0;
			}
		}

		console.log(ans);
	}
}

const readline = require('readline')

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

function solve(n, str) {
    const sum = []
    const count = [] // of '--'
    let ans = 0
    for (let i = 0; i < n; i++) {
        sum[i] = []
        count[i] = []
        for (let j = i; j < n; j++) {
            const now = str[j] === '+' ? 1 : -1
            sum[i][j] = j > i ? sum[i][j - 1] + now : now
            //
            if (str[j] === '-' && str[j - 1] === '-') {
                count[i][j] = (count[i][j - 2] || 0) + 1
            } else {
                count[i][j] = j > i ? count[i][j - 1] : 0
            }
            //
            if (sum[i][j] === 0) {
                ans++
            } else if (sum[i][j] < 0 && !(sum[i][j] % 3)) {
                if (-sum[i][j] / 3 <= count[i][j]) ans++
            }
        }
    }
// console.log(sum, count)
    return ans
}

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')

class SegTree {
  constructor(l, r) {
    this.l = l
    this.r = r
    this.root = this._newNode(l, r)
    this.update = this._update.bind(this, this.root)
    this.query = this._query.bind(this, this.root)
  }
  _newNode(l, r, val = new Array(3).fill(0), left = null, right = null) {
    return { val, l, r, left, right }
  }
  _update(node, x, y, z) {
    if (!node) return
    const { l, r } = node
    if (l === x && r === y) {
      node.val[z % 3]++
      return
    }
    const mid = Math.floor((l + r) / 2)
    if (!node.left) {
      node.left = this._newNode(l, mid)
      node.right = this._newNode(mid + 1, r)
    }
    if (y <= mid) this._update(node.left, x, y, z)
    else if (x > mid) this._update(node.right, x, y, z)
    else this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z)
    for (let i = 0; i < 3; i++) node.val[i] = node.left.val[i] + node.right.val[i]
  }
  _query(node, x, y, z) {
    if (y < x) return 0
    if (!node) return 0
    const { l, r } = node
    if (l === x && r === y) return node.val[z]
    let res = 0,
      mid = Math.floor((l + r) / 2)
    if (y <= mid) res = this._query(node.left, x, y, z)
    else if (x > mid) res = this._query(node.right, x, y, z)
    else res = this._query(node.left, x, mid, z) + this._query(node.right, mid + 1, y, z)
    return res
  }
}
function solve(n, s) {
  let pre = new Array(n + 1).fill(0),
    sum = 0,
    max = 0,
    min = 0
  for (let i = 0; i < n; i++) {
    sum += s[i] === '+' ? 1 : 0
    pre[i + 1] = i + 1 - 2 * sum
    max = Math.max(max, pre[i + 1])
    min = Math.min(min, pre[i + 1])
  }
  let res = 0
  const segTree = new SegTree(min, max)
  for (let i = 0; i <= n; i++) {
    const cur = pre[i]
    res += segTree.query(min, cur, (cur + 3) % 3)
    segTree.update(cur, cur, (cur + 3) % 3)
  }
  return res
}

void (function main() {
  let t = Number(inputs[0]),
    __ = 1,
    res = []
  for (let _ = 0; _ < t; _++) {
    const n = Number(inputs[__++])
    let str = inputs[__++].trim()
    res.push(solve(n, str))
  }
  console.log(res.join('\n'))
})()


var s = "";
var buf = "";

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

var n = s[0] - 0;
var m = s[1] - 0;
var k = s[2] - 0;

var row = new Array(n + 1);
for (var i = 0; i < n + 1; i++) row[i] = i;

var col = new Array(m + 1);
for (var i = 0; i < m + 1; i++) col[i] = i;

var matrix = new Array(n);
for (var i = 0; i < n; i++) {
    matrix[i] = readline().split(' ');
}

for (var i = 0; i < k; i++) {

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

    var q = s[0];
    var x = s[1] - 0;
    var y = s[2] - 0;

    if (q == 'c') {
        var c = col[x]; col[x] = col[y], col[y] = c;
    } else if (q == 'r') {
        var c = row[x]; row[x] = row[y], row[y] = c;
    } else {
        buf += matrix[row[x] - 1][col[y] - 1] + '\n';
    }
}

print(buf);

var s = "";

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

var n = s[0] - 0;
var m = s[1] - 0;
var k = s[2] - 0;

var row = new Array(n + 1);
for (var i = 0; i < n + 1; i++) row[i] = i;

var col = new Array(m + 1);
for (var i = 0; i < m + 1; i++) col[i] = i;

var matrix = new Array(n);
for (var i = 0; i < n; i++) {
    matrix[i] = readline().split(' ');
}

for (var i = 0; i < k; i++) {

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

    var q = s[0];
    var x = s[1] - 0;
    var y = s[2] - 0;

    if (q == 'c') {
        var c = col[x]; col[x] = col[y], col[y] = c;
    } else if (q == 'r') {
        var c = row[x]; row[x] = row[y], row[y] = c;
    } else {
        print(matrix[row[x] - 1][col[y] - 1]);
    }
}

var s = "";
var buf = "";

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

var n = s[0] - 0;
var m = s[1] - 0;
var k = s[2] - 0;

var row = new Array(n + 1);
for (var i = 0; i < n + 1; i++) row[i] = i;

var col = new Array(m + 1);
for (var i = 0; i < m + 1; i++) col[i] = i;

var matrix = new Array(n);
for (var i = 0; i < n; i++) {
    matrix[i] = readline().split(' ');
}

for (var i = 0; i < k; i++) {

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

    var q = s[0];
    var x = s[1] - 0;
    var y = s[2] - 0;

    if (q == 'c') {
        var c = col[x]; col[x] = col[y], col[y] = c;
    } else if (q == 'r') {
        var c = row[x]; row[x] = row[y], row[y] = c;
    } else {
        buf += matrix[row[x] - 1][col[y] - 1] + '\n';
        if (i % 65536 == 0) {
            print(buf);
            buf = "";
        };
    }
}

print(buf);

(function main() {
    var l = readline().split(' ');
    var nrow = parseInt(l[0]);
    var ncol = parseInt(l[1]);
    var nreq = parseInt(l[2]);
    var rows = new Array(nrow);
    var cols = new Array(ncol);
    var elem = new Array(nrow * ncol);
    var answer = '';
    for (var i = 0; i < nrow; ++i)
        rows[i] = i;
    for (var i = 0; i < ncol; ++i)
        cols[i] = i;
    var q = 0;
    for (var i = 0; i < nrow; ++i) {
        var l = readline().split(' ');
        for (var j = 0; j < ncol; ++j, ++q)
            elem[q] = parseInt(l[j]);
    }
    for (var i = 0; i < nreq; ++i) {
        var l = readline().split(' ');
        var a = l[0];
        var b = parseInt(l[1]) - 1;
        var c = parseInt(l[2]) - 1;
        if (a == 'c') {
            var t = cols[b];
            cols[b] = cols[c];
            cols[c] = t;
        } else if (a == 'r') {
            var t = rows[b];
            rows[b] = rows[c];
            rows[c] = t;
        } else {
            answer += elem[rows[b] * ncol + cols[c]] + '\n';
        }
    }
    print(answer);
})();


// Generated by CoffeeScript 1.4.0
(function() {
  var c, lmom, lsum, op, rdist, rmom, s, _i, _len;

  String.prototype.reverse = function() {
    return this.split("").reverse().join("");
  };

  s = readline();

  lsum = lmom = 0;

  rdist = rmom = 0;

  op = false;

  for (_i = 0, _len = s.length; _i < _len; _i++) {
    c = s[_i];
    if (!op) {
      lmom += lsum;
    } else {
      rdist++;
    }
    if (c === '^') {
      op = true;
      continue;
    }
    if (c === '=') {
      continue;
    }
    if (!op) {
      lsum += c | 0;
    } else {
      rmom += (c | 0) * rdist;
    }
  }

  print(lmom > rmom ? 'left' : rmom > lmom ? 'right' : 'balance');

}).call(this);

print(function(s) {

	var i,
		ans = 0,
		c = s.indexOf('^');

	for (i = 0; i < s.length; i++)
		if (s[i] <= '9') ans += (c - i) * s[i];

	if (ans > 0) return 'left';
	if (ans < 0) return 'right';
	return 'balance';

}(readline()));

var countOnce = function (res,item,position) {
    return res + (position+1)*(item=='='?0:item);
}

var a = readline().split('^'),
    l = a[0].split('').reverse().reduce(countOnce,0),
    r = a[1].split('').reduce(countOnce,0);

if (l==r) {
    print('balance')
} else if (l>r) {
    print('left')
} else {
    print('right')
}

;(function () {
	print(function () {
		var w = readline(),
			n = w.indexOf('^'), r = 0, l = 0;

		for (var i = 0; i < n; i++) {
			var q = w[i];
			if (q !== '=') {
				q = parseInt(q);
				l += (n - i) * q;
			}
		}

		for (var i = n + 1, _i = w.length; i < _i; i++) {
			var q = w[i];
			if (q !== '=') {
				q = parseInt(q);
				r += (i - n) * q;
			}
		}

		return l === r ? 'balance' : (r > l ? 'right' : 'left');
	}());
}).call(this);

var input = readline();
var idx = input.search(/\^/);
var result = 0;

for(var i=0; i<input.length; i++)
{
    if(input[i]!='=' && input[i]!='^') result+=parseInt(input[i])*(idx-i);
}
if(Math.abs(result)<0.001) print('balance');
else if(result>0) print('left');
else print('right');

var lever = readline();

var isLeft = true;
var leftCount = 0;
var rightCount = 0;
var center = 0;

for (var i = 0; i < lever.length; ++i) {
    if (lever.charAt(i) == '^') {
        center = i;
        break;
    }
}

for (var i = 0; i < lever.length; ++i) {
    var value = 0;

    if (lever.charAt(i) == '=') {
        continue;
    }
    else if (lever.charAt(i) == '^') {
        isLeft = false;
    }
    else {
        value = lever.charAt(i) - '0';
    }

    if (isLeft == true) {
        leftCount += value * (center - i);
    } else {
        rightCount += value * (i - center);
    }
}

if (leftCount > rightCount) {
    print("left");
} else if (leftCount < rightCount) {
    print("right");
} else {
    print("balance");
}

// Generated by CoffeeScript 1.4.0
(function() {
  var c, lmom, lsum, op, rdist, rmom, s, _i, _len;

  String.prototype.reverse = function() {
    return this.split("").reverse().join("");
  };

  s = readline();

  lsum = lmom = 0;

  rdist = rmom = 0;

  op = false;

  for (_i = 0, _len = s.length; _i < _len; _i++) {
    c = s[_i];
    if (!op) {
      lmom += lsum;
    } else {
      rdist++;
    }
    if (c === '^') {
      op = true;
      continue;
    }
    if (c === '=') {
      continue;
    }
    if (!op) {
      lsum += c | 0;
    } else {
      rmom += (c | 0) * rdist;
    }
  }

  print(lmom > rmom ? 'left' : rmom < lmom ? 'right' : 'balance');

}).call(this);

// Generated by CoffeeScript 1.4.0
(function() {
  var s, solve;

  String.prototype.reverse = function() {
    return this.split("").reverse().join("");
  };

  s = readline();

  solve = function(s) {
    var c, lmom, lsum, op, rdist, rmom, rsum, _i, _len;
    lsum = lmom = 0;
    rdist = rsum = rmom = 0;
    op = false;
    for (_i = 0, _len = s.length; _i < _len; _i++) {
      c = s[_i];
      if (!op) {
        lmom += lsum;
      } else {
        rdist++;
      }
      if (c === '^') {
        op = true;
        continue;
      }
      if (c === '=') {
        continue;
      }
      if (!op) {
        lsum += c | 0;
      } else {
        rsum += (c | 0) * rdist;
      }
    }
    return lsum > rsum;
  };

  print(solve(s) ? 'left' : solve(s.reverse()) ? 'right' : 'balance');

}).call(this);


function test() {
  assert(task(['9 4']), 'YES\n' +
    '4 1 2 2');
  assert(task(['8 1']), 'YES\n8');
  assert(task(['5 1']), 'NO');
}

function task([input]) {
  let [n, k] = input.split(' ');
  n = Number(n);
  k = Number(k);

  if (k > n) return 'NO';

  let result = [];
  let nBinary = n.toString(2);

  for (let i = 0; i < nBinary.length; i++) {
    if (nBinary[i] === '1') result.push(Math.pow(2, nBinary.length - i - 1));
  }

  let i = 0;
  let count = result.length;

  while (count < k) {
    let item = result[i];
    result[i] = false;
    if (item > 1) {
      result.push(item / 2, item / 2);
      count += 1;
    } else {
      result.push(item);
    }
    i++;
  }

  result = result.filter(Boolean);

  if (result.length !== k) {
    return 'NO';
  }

  return `YES\n${result.join(' ')}`
}

function assert(result, expectation, unordered) {
  if (unordered) {
    result = result.split(' ');
    expectation = expectation.split(' ');

    if (result.sort().join(' ') !== expectation.sort().join(' ')) {
      console.error(`${result}: ${expectation}`);
    }
  } else if (result !== expectation) {
    console.error(`${result}: ${expectation}`);
  }
}

function run() {
  // codeforces uses windows. Really??!
  if (process.platform === 'win32') {
    const readline = require('readline');
    const rl = readline.createInterface({ input: process.stdin });

    const input = [];

    rl.on('line', (line) => input.push(line));
    rl.on('close', () => console.log(task(input)));
  } else {
    test();
  }
}

run();

const read = [];
const M = new Map();

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

RL.on('line', line => {
  read.push(line.trim());
});
RL.on('close', () => {
  const [n, k] = read[0].split(' ').map(Number);
  const obj = {
    pointer: 0,
    counter: 0,
  };

  preCalc(n, obj);

  if (obj.counter > k) {
    console.log('NO');
    return;
  }

  while (obj.counter !== k && obj.pointer !== 1) {
    M.set(obj.pointer, M.get(obj.pointer) - 1);
    obj.counter -= 1;

    M.set(obj.pointer >> 1, M.get(obj.pointer >> 1) + 2);
    obj.counter += 2;

    if (M.get(obj.pointer) === 0) {
      obj.pointer >>= 1;
    }
  }

  if (obj.counter !== k) {
    console.log('NO');
    return;
  }

  const answer = [];
  for (const [key, value] of M.entries()) {
    if (value === 0) {
      continue;
    }

    for (let i = 0; i < value; i += 1) {
      answer.push(key);
    }
  }

  console.log('YES');
  console.log(`${answer.join(' ')}`);
});

function preCalc(n, obj) {
  for (let i = 0; i < 32; i += 1) {
    if (((1 << i) & n) > 0) {
      M.set(1 << i, 1);
      obj.counter += 1;
      obj.pointer = 1 << i;
    } else {
      M.set(1 << i, 0);
    }
  }
}


n = +readline();
for(i=0;i<n;i++){
    t = readline();
    print(Math.round(t/2));
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    for(i = 1; i <= t; i++){
        var a = lines[i];
        console.log(Math.ceil(a / 2));
    }
});

let index = 0;

require('readline').createInterface({
    input: process.stdin
}).on('line', (line) => {
    if(index > 0) {
        console.log(Math.ceil(parseInt(line) / 2));
        return;
    }

    index++;
})

let index = 0;

require('readline').createInterface({
    input: process.stdin
}).on('line', (line) => {
    if(index > 0) {
        console.log(Math.ceil(parseInt(line) / 2))
    }

    index++;
})

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

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

process.stdin.on('end', function() {
    // mb there can be overflow
    const data = input.trim().split('\n').map(Number);

    for (let i = 1; i < data.length; i++) {
        const solution = Math.ceil(data[i] / 2);
        console.log(solution);
    }
});

const fs = require("fs");
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}

var T = readline();
var inf = 1000000000000;
for(var tc=1;tc<=T;tc++) {
	var n = readline();
	var rem = BigInt(n) % BigInt(2);
	console.log(" " + (rem + (BigInt(n) / BigInt(2))))
}

function solve() {
    var n = Number(read());
    write((n + 1) >> 1);
}

function start() {
    var T = 1;
    T = Number(read());
    for (var t = 0; t < T; t++) {
        solve();
    }
    writeAns();
}

function gcd(a, b) {
    if (b === 0) {
        return a;
    }
    return gcd(b, a % b)
}

var MEMORY;
var MEMORY_INDEX = 0;
var ANS = '';

try {
    initInput(start);
} catch (e) {
    console.log(e);
}
function readArray(f) {
    return read().split(' ').map(f);
}

function sortNumbers(a, b) {
    return a - b;
}
function sortNumbersDec(a, b) {
    return b - a;
}
var ANS;
// вывод через ANS быстрее, но ест кучу памяти.
// К тому же, максимальная длина строки - 2097151.
function write(value) {
    // console.log(value);
    ANS += value + '\n';
}
function writeAns() {
    if (ANS) {
        console.log(ANS);
    }
}
function read() {
    return MEMORY[MEMORY_INDEX++];
}
function initInput(callback) {
    var fs = require('fs');
    var isLocalStart = process.argv[2] === 'lorelvate';
    if (!isLocalStart) {
        MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
        callback();
        return;
    }
    var path = require('path');
    fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {
        if (err) {
            write(err);
            return;
        }
        MEMORY = data.split('\r\n');
        callback();
    });
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', function() {
    inputString = inputString.split('\n');

    main();
});

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

function gcd(a,b )
{
    if (!b)
        return a

    return gcd( b , a%b )
}

function main() {

    let t = parseInt(readLine());

    loopwhile:
    while(t--)
    {
        let n = parseInt(readLine());

        //let arr = readLine().trim().split(" ").map(x=>parseInt(x))

        console.log(Math.ceil(n/2))
   }
}

n =readline();
for(i=0;i<n;i++){
    t = readline();
    print(Math.round(t/2));
}

var numOfCases = Number(readline());

for (var testCase = 0; testCase < numOfCases; testCase++) {
    var input = Number(readline());
    var result = process(input);
    print(result)
}

function process(input) {
    var inputVal = input;

    if (inputVal % 2 !== 0) {
        inputVal++
    }

    return inputVal / 2;
}

var line = readline();

for(var i=0; i<line;i++) {
    var number = readline();
    print(Math.round(number/2));
}

var t = readline();
t = parseInt(t);

while(t--){
    var n = readline();
    n = parseInt(n);
   print(Math.ceil(n/2));
}

const fs = require("fs");

// console.log(fs.readdirSync('./'));
// console.log(null);

fs.readFile("./input.fd0138e687.txt", "utf-8", (err, data) => {
  if (err) throw err;
  const tests = data.split("\r\n");
  tests.shift();
  tests.forEach((e) => {
    const ans = (Math.ceil(Number.parseInt(e) / 2));
    if (!Number.isNaN(ans)) console.log(ans);
  });
});

const fs = require("fs");

// console.log(fs.readdirSync('./'));
// console.log(null);

fs.readFile("./input.fd0138e687.txt", "utf-8", (err, data) => {
  if (err) throw err;
  const tests = data.split("\r\n");
  tests.shift();
  tests.forEach((e) => {
    console.log(Math.ceil(Number.parseInt(e) / 2));
  });
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    for(i = 1; i <= t; i++){
        var a = lines[i];
        console.log(Math.ceil(a));
    }
});


const readline = require('readline');

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

let lines = [];
rl.on('line', (line) => {
    lines.push(line.split(' '));
}).on('close', () => {
  lines.map((index, i) => {
    if (i > 0) {
      if ((`${index[0]}` === '2' && `${index[1]}` === '2') ||
        (`${index[0]}` === '1' || `${index[1]}` === '1')) {
        process.stdout.write(`YES\n`);
      } else {
        process.stdout.write(`NO\n`);
      }
    }
  })
});

n = +readline();
while (n-->0){
    num = readline().split(' ').map(Number);
    if (num[0] == 1 || num[1] == 1 || (num[0] == 2 && num[1] == 2)){
        print('YES\n');
    } else {
        print('NO\n');
    }
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var nm = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = nm[0],
    m = nm[1];
  if (n < 2 || m < 2 || (n == 2 && m == 2)) print("Yes");
  else print("No");
}

var inputLength = readline();

for (var i =0; i<inputLength; i++) {
    var input = readline().split(" ");
    var r = input[0], c = input[1];
    if( r * c >= (2*r*c - r - c)) {
        print ("YES");
    } else {
        print ("NO");
    }
}

var inputLength = readline();

for (var i =0; i<inputLength; i++) {
    var input = readline().split(" ");
    var r = input[0], c = input[1];
    if( r * c >= ((2*r - 1) * (c-1) + (r-1))) {
        print ("YES");
    } else {
        print ("NO");
    }
}

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

const input = [];

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

readline.on('close', () => {
  const testCount = parseInt(input[0]);
  const variants = input.slice(1).map(str => str.split(' ').map(item => +item));
  variants.forEach(variant => console.log(calculate(variant)));
})

function calculate([n, m]) {
  if (n === 1 || m === 1) {
    return 'YES';
  } else if (n === 2 && m === 2) {
    return 'YES';
  } else {
    return 'NO';
  }
}

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

//main
function main() {
    var nbOfTestCases = parseInt(readline());

    for (var i=0 ; i<nbOfTestCases ; i++) {
        var [n,m] = readline().split(" ").map(e=>parseInt(e));
        console.log(n*m <= (n+m) ? "YES" : "NO");
    }
}

// Q: https://codeforces.com/contest/1348/problem/A

const readline = require('readline');

let input = [];

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

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

rl.on('close', () => {
	const test = parseInt(input[0]);
	for (let i=0; i < test; i++) {
        let n, m;
		[n, m] = input[i+1].split(' ').map((a) => parseInt(a));
		console.log(solution(n, m));
	}
});

function solution(n, m) {
	return 2*n*m - n - m <= n*m ? 'YES' : 'NO';
}

const readline = require('readline');

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

let lines = [];
rl.on('line', (line) => {
    lines.push(line.split(' '));
}).on('close', () => {
  for(i = 1; i < lines.length; i++) {
    if (
      (lines[i][0] == 1 || lines[i][1] == 1) ||
      (lines[i][0] == 2 && lines[i][1] == 2)
    ) {
      process.stdout.write(`YES\n`);
    } else {
      process.stdout.write(`NO\n`);
    }
  }

});

var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
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;}}
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var N = one[0];
		var M = one[1];
		if(N == 1 || M == 1){
			output[i] = "YES";
		}else if(N == 2 && M == 2){
			output[i] = "YES";
		}else{
			output[i] = "NO";
		}
	}
	myout(myconv(output,9));
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const cases = readline();
    var i;
    for (i = 0; i < cases; i++) {
        const line = readline();
        var a = parseInt(line.split(" ")[0]);
        var b = parseInt(line.split(" ")[1]);

        solve(Math.min(a, b), Math.max(a, b));
    }
}

function solve(a, b) {
    if (a == 1) console.log('YES')
    else if (b < 3) console.log('YES')
    else console.log ('NO');
}

//Puzzle Pieces

const {EOL} = require('os');

let inp = '';

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

process.stdin.on('end', () => {
    let lines = inp.split(EOL);

    let t = +lines[0];

    for(let i = 0; i < t; i++)   {
    	let arr = lines[i + 1].split(' ').map(c => +c);
    	if(arr[0] == 1 || arr[1] == 1 || (arr[0] == 2 && arr[1] == 2))  {
    		process.stdout.write('YES' + EOL);
    	}  else  {
    		process.stdout.write('NO' + EOL);
    	}
    }

    return;
});

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] = d.split(' ').map(Number);

  if (a === 1 || b === 1) {
    console.log('YES');
  }
  else if (a === 2 && b === 2) {
    console.log('YES');
  }
  else {
    console.log('NO');
  }

  c++;
});

const processData = (lines) => {
  const n = +lines[0]
  for (let i=0; i<n; i++) {
    const [a, b] = lines[i+1].split(' ').map(x => +x).sort((a, b) => a-b)

    if (a === 1) {
      console.log('YES')
    } else {
      if (a === 2 && b === 2) {
        console.log('YES')
      } else {
        console.log('NO')
      }
    }
  }
}

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

// node template.js < A-small.in > A-small.out

function main() {
    var tests = 1;
    tests = nextInt();

    for (let t = 1; t <= tests; t++) {
        let N = nextInt(), M = nextInt();

        let result = (ok(N, M) ? "YES" : "NO");

        print(result);
    }
}

function ok(n, m) {
    if (n > m) {
        let tmp = n;
        n = m;
        m = tmp;
    }
    if (n==1) return true;
    if (n==2 && m == 2) return true;
    return false;
}

// ------- Template ------------------
function newTensor(dimensions, value) {
    let res = [];
    let dim = dimensions[0], subdim = dimensions.slice(1);
    if (subdim.length == 0) {
        for(let i = 0; i < dim; i++) {
            res.push(value);
        }
    } else {
        for(let i = 0; i < dim; i++) {
            res.push(newTensor(subdim, value));
        }
    }
    return res;
}

if (!String.prototype.startsWith) {
    Object.defineProperty(String.prototype, 'startsWith', {
        value: function(search, rawPos) {
            var pos = rawPos > 0 ? rawPos|0 : 0;
            return this.substring(pos, pos + search.length) === search;
        }
    });
}
if (!String.prototype.endsWith) {
    String.prototype.endsWith = function(search, this_len) {
        if (this_len === undefined || this_len > this.length) {
            this_len = this.length;
        }
        return this.substring(this_len - search.length, this_len) === search;
    };
}

var curTokens = [], curToken = 0;

function next() {
    while (curToken >= curTokens.length) {
        curTokens = readline().split(/[\s]+/);
        curToken = 0;
    }
    return curTokens[curToken++];
}

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

// code for nodejs
var inputBuffer = '', curLine = 0;

function readline() {
    return inputBuffer[curLine++];
}

function print(data) {
    process.stdout.write(data + '\n');
}

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

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

process.stdin.on('end', function () {
    inputBuffer = inputBuffer.split(/[\s]+/);
    main();
});

'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++];
}
/**
    3
1 3
100000 100000
2 2

**/

function main() {
    var range = readline();

    for(var r=0;r<range;r++) {
        var [x,y] = readline().split(" ").map(Number);

        if(x === 1 || y === 1) {
            console.log("YES");
        } else if(x===2 && y === 2) {
            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++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const cases = readline();
    var i;
    for (i = 0; i < cases; i++) {
        const line = readline();
        var a = parseInt(line.split(" ")[0]);
        var b = parseInt(line.split(" ")[1]);

        solve(a, b);
    }
}

function solve(a, b) {
    if (a == 1) console.log('YES')
    else if (b < 3) console.log('YES')
    else console.log ('NO');
}

const readline = require('readline');

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

let lines = [];
rl.on('line', (line) => {
    lines.push(line.split(' '));
}).on('close', () => {
  console.log(lines);
  lines.map((index, i) => {
    if (i > 0) {
      if ((`${index[0]}` === '2' && `${index[1]}` === '2') ||
        (`${index[0]}` === '1' || `${index[1]}` === '1')) {
        process.stdout.write(`YES\n`);
      } else {
        process.stdout.write(`NO\n`);
      }
    }
  })
});


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 arr = d.split(' ').map(Number);
  arr.sort((a, b) => a - b);
  let ans = 'NO';
  let min = arr[0];

  for (let i = 0; i < arr.length; i++) {
    if (arr[i] !== min) {
      ans = arr[i];
      break;
    }
  }

  console.log(ans);

  c++;
});

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

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

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

function main() {
	var n = parseInt(readline());
	var sequence = tokenizeIntegers(readline());
	sequence.sort(function(a, b) {
		return a-b;
	});

	for (var pos = 1; pos < sequence.length; pos += 1) {
		if (sequence[pos] != sequence[0]) {
			print(sequence[pos]);
			return;
		}
	}

	print("NO");
}

main();

'use strict'

const N = +readline()
let lll = readline().split(' ').map(v => parseInt(v))
lll.sort((a, b) => a - b)

let i = 1
let min = lll[0]
while (lll[i] == min) i++

print(lll[i] == null ? 'NO' : lll[i])