//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 list = nextIntArray(N);
		var S = next();
		var map = {};
		var ok = true;
		for(var i = 0; i < N; i++){
			if(map[list[i]] == null){
				map[list[i]] = S[i];
			}else if(map[list[i]] != S[i]){
				ok = false;
			}
		}
		myout((ok) ? "YES" : "NO");
	}
}

/*
* auther yeling
*
*
*/
'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
function print(str) {
    console.log(str);
}

// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');
// main();

function begin(n, nums, str) {
    //print(`${n} ${nums} ${str}`);

    let cache = new Map();
    for(let i = 0; i < n; i++) {
        let all = cache.get(nums[i]);
        if(all == null) {
            all = [];
        }
        all.push(i);
        cache.set(nums[i], all);
    }
    let keys =  Array.from(cache.keys());
    let find = true;
    for(let i = 0; i < keys.length; i++) {
        let all = cache.get(keys[i]);
        let dst = str.charAt(all[0]);
        for(let j = 1; j < all.length; j++) {
            if(str.charAt(all[j]) != dst) {
                find = false;
                break;
            }
        }
        if(find == false) {
            break;
        }
    }
    if(find) {
        print('YES');
    } else {
        print('NO');
    }
}
function main() {
    var caseNum = parseInt(readline(), 10);
    for (var i = 0; i < caseNum; i++) {
        var n = parseInt(readline(), 10);
        var x = readline()
            .trim()
            .split(' ')
            .map((y) => parseInt(y, 10));

        var str = readline().trim()
        begin(n, x, str);
    }
}

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

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

/*---------------------------------------------------*/

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

const sumab = (a, b) => {
    if (a > b) return 0;
    let x = (b - a + 1);
    let y = a + b;
    if (x % 2 === 0) {
        x = Math.round(x / 2);
    } else {
        y = Math.round(y / 2);
    }
    return x * y;
}

const calc = (t)=>{
    /* read */
    let n = +readline();
    let a = ra();
    let s = rl();

    let map = {};
    for (let i = 0; i < n; i++) {
        let char = s[i];
        let num = a[i];
        if (typeof map[num] === 'undefined') {
            map[num] = char;
        } else {
            if (char != map[num]) return 'NO';
        }
    }
    return 'YES';
};

function main() {
    let T = +readline();
    let out = [];
    for (let t = 1; t <= T; t++){
        out.push(calc(t));
        // process.stdout.write(`${calc(t)}\n`);
    }
    process.stdout.write(out.join('\n')+'\n');
}

"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 check(input) {
  let dict = {};
  for (let i = 0; i < input.numbers.length; i++) {
    if (
      Object.keys(dict).includes(input.numbers[i]) &&
      input.letters[i] !== dict[input.numbers[i]]
    ) {
      console.log("NO");
      break;
    }

    if (!Object.keys(dict).includes(input.numbers[i])) {
      dict[input.numbers[i]] = input.letters[i];
    }

    if (i === input.numbers.length - 1) {
      console.log("YES");
    }
  }
}

function main() {
  const t = parseInt(readLine().trim());
  const cases = {};
  for (let i = 0; i < t * 3; i++) {
    const inputs = readLine().trim();
    cases[Math.floor(i / 3)] = {
      ...cases[Math.floor(i / 3)],
      ...(i % 3 === 1 && { numbers: inputs.split(" ") }),
      ...(i % 3 === 2 && { letters: inputs.split("") }),
    };
  }

  for (let i = 0; i < Object.keys(cases).length; i++) {
    check(cases[i]);
  }
}

let buf='';

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

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    // let v=[,];
    // console.log(v[1].length);
    for(let _=1;_<=t;_++)
    {
        let n=parseInt(line[3*_-2]);
        let a=line[3*_-1].split(' ').map(x=>{return parseInt(x)});
        let s=line[3*_];
        let v=new Array(55);
        for(let i=1;i<=50;i++) v[i]=new Array(0);
        // console.log(a);
        for(let i=0;i<n;i++)
        {
            // console.log(a[i],i);
            v[a[i]].push(i);
        }
        // console.log(v);
        flag=true;
        for(let i=1;i<=50;i++)
        {
            if(v[i].length>0)
            {
                let c=s[v[i][0]];
                // console.log(c);
                for(let j=0;j<v[i].length;j++) {
                    let x=v[i][j];
                    if(s[x]!==c) flag=false;
                }
                // for(let j=0;j<n;j++) {
                //     if(s[j]===c) {
                //         if(!v[i].includes(j)) {
                //             flag=false;
                //         }
                //     }
                // }
            }
        }
        if(flag) 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', function(inputStdin) {
    inputString += inputStdin;
});

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

    main();
});

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

function main() {

    const firstMultipleInput = readLine();

    const t = parseInt(firstMultipleInput);

    //console.log(t);
    for (let i=0;i<t;i++)
    {
        let map = {}
        const n = parseInt(readLine());

        const arr = readLine().split(" ").map(x=>parseInt(x));

        const s = readLine();

        //console.log(n);
        //console.log(arr);
        //console.log(s);
        let fail=false
        for(let j=0;j<n;j++)
        {
            if(arr[j] in map)
            {
                if(map[arr[j]] != s[j])
                {
                    fail = true
                    console.log("NO")
                    break;
                }
            }
            map[arr[j]] = s[j]
        }
        if (!fail)
            console.log("YES")

    }
}

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

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

const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    let str = stringArr();
    const helper = () => {
      for (let i = 0; i < n; i++) {
        for (let j = i + 1; j < n; j++) {
          if (arr[j] === arr[i] && str[j] !== str[i]) return false;
        }
      }
      return true;
    };
    let ans = helper() === true ? "YES" : "NO";
    console.log(ans);
  }
};
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);

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

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

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 arr = lines[l++].trim().split(' ').map(Number)
        const str = lines[l++]
        output[i] = solve(n, arr, str)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr, str) {
    const m = {}
    for (let i = 0; i < arr.length; i++) {
        const x = arr[i]
        m[x] = m[x] || []
        m[x].push(i)
    }
    for (let x in m) {
        const ch = str[m[x][0]]
        for (let p of m[x]) {
            if (str[p] !== ch) return 'NO'
        }
    }
    return 'YES'
}

var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var caseLength = parseInt(readline());
    var numArray = readline().split(" ");
    var stringArray = readline();
    var caseMap = new Map();
    var result = "YES";
    for (var j = 0; j < caseLength; j++)
    {
        var value = parseInt(numArray[j]);
        if (caseMap.has(value))
        {
            if (caseMap.get(value) !== stringArray[j])
            {
                result = "NO";
                break;
            }
        }
        else caseMap.set(value, stringArray[j]);
    }
    print(result);
}

function foo(size, arr, str) {
  const obj = {}

  for(var i=0; i<size; i++) {
    if(obj[arr[i]] && obj[arr[i]] !== str[i]) return 'NO'
    else obj[arr[i]] = str[i]
  }
  return "YES"
};

var n = +readline();

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

  var size = +readline()
  var arr = readline().split(' ').map(el => +el)
  var str = readline();

  var result = foo(size, arr, str)
  print(result)
}

var t = +readline();
for(var i_=0;i_<t;i_++){
    var n = +readline();
    var arr = readline().split(' ');
    var s = readline();
    var obj={};
    for(var j=0;j<n;j++){
        if(arr[j] in obj){
            obj[arr[j]].push(s[j]);
        }
        else{
            obj[arr[j]] = [s[j]];
        }
    }
    var flag = false;
    for(var i in obj){
        var prev = -1;
        for(var j in obj[i]){
            if(prev===-1){
                prev = obj[i][j];
            }
            else{
                if(prev!==obj[i][j]){
                    print("NO");
                    flag = true;
                    break;
                }
            }
        }
        if(flag===true){
            break;
        }
    }
    if(flag===false){
        print("YES");
    }
}

function func (strNum , strTrans) {
    var strList = strTrans.split('')
    var val = new Map()
        // 2: c, 3: a, 4:t, 1:a
    for (var index = 0; index < strNum.length; index++) {
        if (val.get(strNum[index]) ) {
            if (val.get(strNum[index]) != strList[index]) {
                return 'NO'
            }
        }
        val.set(strNum[index], strList[index])
    }

    return 'YES'
}

var n = +readline();

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

  var size = +readline()
  var arr = readline().split(' ').map(el => +el)
  var str = readline();

  var result = func( arr, str)
  print(result)
}

var n = +readline();
for(var i = 0; i < n; i++) {
  var k = +readline();
  var arr = readline().split(' ');
  var str = readline();
  var obj = {};
  for(var j = 0; j < k; j++) {
    if(obj[arr[j]]) {
      if(obj[arr[j]] !== str[j]) {
        break;
      }
    } else {
      obj[arr[j]] = str[j];
    }
  }
  print(j === k ? 'YES' : 'NO');
}

var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var caseLength = parseInt(readline());
    var numArray = readline().split(" ");
    var stringArray = readline();
    var caseMap = new Map();
    var result = "YES";
    for (var j = 0; j < caseLength; j++)
    {
        var value = parseInt(numArray[j]);
        if (caseMap.has(value))
        {
            if (caseMap[value] !== stringArray[j])
            {
                result = "NO";
                break;
            }
        }
        else caseMap.set(value, stringArray[j]);
    }
    print(result);
}

var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var caseLength = parseInt(readline());
    var numArray = readline().split(" ");
    var stringArray = readline();
    var caseMap = new Map();
    var result = "YES";
    for (var j = 0; j < caseLength; j++)
    {
        var value = parseInt(numArray[j]);
        if (caseMap.has(value))
        {
            if (caseMap[value] === stringArray[j])
            {
                result = "NO";
                break;
            }
        }
        else caseMap.set(value, stringArray[j]);
    }
    print(result);
}


let text = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', str => {
    if (str === '\r\n' || str === '\n') {
        process.stdin.emit('end');
    } else {
        text += str;
    }
});

process.stdin.on('end', () => {
    const input = text.trim().replace(/\r/g, '').split('\n');
    const total = +input[0];
    for (let i = 1; i <= total; i++) {
        console.log(solve(input[i * 2]));
    }

    process.exit();
});

function solve(str) {
    const numbers = str.split(' ').map(ele => +ele);
    const len = numbers.length;
    const record = new Array(len + 1).fill(-1);
    const sums = new Array(len).fill(0);
    let current = 0;
    for (let i = 0; i < len; i++) {
        if (record[numbers[i]] < 0) {
            current++;
        }
        sums[i] = current;
        record[numbers[i]] = i;
    }
    const maxs = new Array(len).fill(0);
    maxs[0] = record[numbers[0]];
    for (let i = 1; i < len; i++) {
        maxs[i] = Math.max(maxs[i - 1], record[numbers[i]]);
    }
    let result = -1;
    for (let i = 1; i < len; i++) {
        if (numbers[i] < numbers[i - 1]) {
            let j = i - 1;
            while(maxs[j] !== j) {
                j = maxs[j];
            }
            result = j;
            numbers[j] = 0;
            i = j;
        }
    }
    if (result < 0) {
        return 0;
    } else {
        return sums[result];
    }
}

'use strict';

function solve(n, a) {
  const map = new Map();
  const segTree = new SegTree(n);
  for (let [i, num] of a.entries()) {
    if (!map.has(num)) map.set(num, []);
    map.get(num).push(i);
    segTree.update(i, i, num);
  }
  const keys = [...map.keys()].sort((a, b) => b - a);
  let res = 0;
  for (let key of keys) {
    const i = map.get(key)[0];
    if (i === n - 1) continue;
    const num = segTree.query(i + 1, n - 1);
    if (num < key) {
      res++;
      for (let i of map.get(key)) {
        segTree.update(i, i, 0);
      }
    }
  }
  return res;
}
class SegTree {
  constructor(n) {
    this.n = n;
    this.root = this._newNode();
    this.update = (x, y, z) => {
      x = Math.max(x, 0);
      y = Math.min(y, n);
      this._update(this.root, 0, n, x, y, z);
    };
    this.query = (x, y) => {
      x = Math.max(x, 0);
      y = Math.min(y, n);
      return this._query(this.root, 0, n, x, y);
    };
  }
  _newNode(val = Infinity, left = null, right = null) {
    return {
      val,
      left,
      right
    };
  }
  _up(node) {
    const {
      left,
      right
    } = node;
    if (!left || !right) return;
    node.val = Math.min(left.val, right.val);
  }
  _update(node, l, r, x, y, z) {
    if (!node) return;
    if (l === x && r === y) {
      node.val = Math.min(node.val, z);
      return;
    }
    const mid = Math.floor((l + r) / 2);
    if (!node.left) {
      node.left = this._newNode();
      node.right = this._newNode();
    }
    if (y <= mid) this._update(node.left, l, mid, x, y, z);else if (x > mid) this._update(node.right, mid + 1, r, x, y, z);else this._update(node.left, l, mid, x, mid, z), this._update(node.right, mid + 1, r, mid + 1, y, z);
    this._up(node);
  }
  _query(node, l, r, x, y) {
    if (y < x) return 0;
    if (!node) return 0;
    if (l === x && r === y) return node.val;
    let res = 0,
        mid = Math.floor((l + r) / 2);
    if (!node.left) {
      node.left = this._newNode();
      node.right = this._newNode();
    }
    if (y <= mid) res = this._query(node.left, l, mid, x, y);else if (x > mid) res = this._query(node.right, mid + 1, r, x, y);else res = Math.min(this._query(node.left, l, mid, x, mid), this._query(node.right, mid + 1, r, mid + 1, y));
    this._up(node);
    return res;
  }
}

async function main(r) {
  const rn = async () => Number(await r());
  const rns = async () => {
    return (await r()).split(' ').filter(s => s !== '').map(Number);
  };
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = await rn();
      const a = await rns();
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

var n,a, count;
    var set, toCheck;

    function op(x) {
        set.add(x);
        count++;
        toCheck.delete(x);
        count+=toCheck.size;
        var adds = [...toCheck];
        for (var i = 0; i < adds.length; i++) {
            set.add(adds[i])
        }
        toCheck = new Set();
    }

    var tests = parseInt(readline());
    for (var t=0; t < tests; t++) {
        n = parseInt(readline());
        a = readline().split(' ').map(x=>parseInt(x));
        count = 0;
        set = new Set();
        toCheck = new Set();
        for (var i = 0; i < n-1; i++) {
            var x = set.has(a[i]) ? 0 : a[i];
            var y = set.has(a[i+1]) ? 0 : a[i+1];
            if (x > y) {
                op(x);
            } else {
                if (!set.has(a[i])) {
                    toCheck.add(a[i]);
                }
            }
        }
        print(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 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 i = 0; i < N; i++) {
        const n = parseInt(readline(), 10);
        const arr = readline().split(' ').map(Number);

        function c(num) {
            if (curr === 0) return;
            curr[num] = true;
        }

        function repl() {
            Object.keys(curr).forEach(key => zero[key] = true);
            curr = {};
        }

        function val(i) {
            let num = arr[i];
            return zero[num] ? 0 : num;
        }

        let zero = {};
        let curr = {};

        c(arr[0]);

        for (let i = 1; i < n; i++) {
            if (val(i) < val(i - 1)) {
                repl();
            }
            c(arr[i]);
        }

        output(Object.keys(zero).length);
    }
}


var m = 1001010;
var n = parseInt(readline());
var s = readline();
var a = [];
for (var i = 0; i <= m; i++) a.push(0);
s.split(' ').map(function (x) { a[x]++; });
var res = 0;

for (var i = 0; i < m - 10; i++) {
  a[i + 1] += a[i] >> 1;
  res += a[i] & 1;
}

print(res);

function toi(x){return parseInt(x);}
function countOne(x){
  var res =0;
  while(x > 0){
    rem = x%2;
    res += rem;
    x=(x-rem)/2;
  }
  return res;
}
n = toi(readline());
w = readline().split(" ").map(toi);
m = 1000000;
memo = [];
for(var i=0;i<m+1;i++){
  memo.push(0);
}
for(var i=0;i<w.length;i++){
  memo[w[i]]++;
}
res=0;
pre=0;
for(var i=0;i<m+1;i++){
  s = memo[i] + pre
  rem = s % 2;
  res+= rem;
  pre = (s - rem)/2;
}
print(res+countOne(pre));

var quickSort = (function () {
  function partition(array, left, right) {
    var cmp = array[right - 1],
        minEnd = left,
        maxEnd;
    for (maxEnd = left; maxEnd < right - 1; maxEnd += 1) {
      if (array[maxEnd] <= cmp) {
        swap(array, maxEnd, minEnd);
        minEnd += 1;
      }
    }
    swap(array, minEnd, right - 1);
    return minEnd;
  }

  function swap(array, i, j) {
    var temp = array[i];
    array[i] = array[j];
    array[j] = temp;
    return array;
  }

  function quickSort(array, left, right) {
    if (left < right) {
      var p = partition(array, left, right);
      quickSort(array, left, p);
      quickSort(array, p + 1, right);
    }
    return array;
  }

  return function (array) {
    return quickSort(array, 0, array.length);
  };
}());

var n = parseInt(readline());
var a = quickSort(readline().split(' ').map(function (n) { return parseInt(n); }));
var res = 0;

while (a.length > 1) {
  if (a[0] == a[1]) {
    a.shift();
    a[0]++;
  } else {
    a.shift();
    res++;
  }
}
res++;

print(res);


'use strict'

let t = parseInt(readline())
const readInts = () => readline().split(' ').map(n => parseInt(n))
const readInt = () => readInts[0]
const abc = "abcdefghijklmnopqrstuvwxyz"

while (t --> 0) {
  const params = readInts()
  const n = params[0]
  const m = params[1]
  const s = readline()
  const arr = readInts()
  arr.push(n)

  const pre = {}
  for (let j = 0; j < 26; ++j) {
    pre[abc[j]] = Array(n + 1).fill(0)
  }

  for (let i = 0; i < n; ++i) {
    for (let j = 0; j < 26; ++j) {
      const c = abc[j]
      const last = pre[c][i]
      const val = last + (c === s[i])
      pre[c][i + 1] = val
    }
  }

  const out = {}
  for (let j = 0; j < 26; ++j) {
    out[abc[j]] = 0
  }

  for (let i in arr) {
    for (let j = 0; j < 26; ++j) {
      const c = abc[j]
      out[c] += pre[c][arr[i]]
    }
  }

  let ans = ""
  for (let i in out) {
    ans += " " + out[i]
  }
  print(ans)
}

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, ''))
  main(arr)
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

function main(input) {
  let ptr = 0
  let t = readInt(input, ptr++)
  // const alpha = "abcdefghijklmnopqrstuvwxyz"
  while(t--) {
    const [n,m] = readInts(input, ptr++)
    const s = input[ptr++]
    const ps = readInts(input, ptr++)
    let map = new Array(n)
    for(let i = 0; i < n;i++) map[i] = new Array(26).fill(0)
    map[0][s.charCodeAt(0) - 97] = 1
    for(let i = 1; i < n;i ++) {
      const char = s.charCodeAt(i) - 97
      for(let j = 0;j < 26; j++) {
        map[i][j] = map[i - 1][j]
      }
      map[i][char] = map[i - 1][char] + 1
    }
    // console.log(map)

    let ans = new Array(26).fill(0)
    for(let i = 0; i < m;i ++) {
      let x = map[ps[i] - 1]
      for(let j = 0;j < 26; j++) {
        ans[j] = ans[j] + x[j]
      }
    }
    let x = map[n - 1]
    for(let j = 0;j < 26; j++) {
      ans[j] = ans[j] + x[j]
    }

    wr(ans.join(' '))
  }
}

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

    function foo (a, p) {
        p.push(a.length);
        result = Array(26).fill(0);

        const alph = {a:0,b:1,c:2,d:3,e:4,f:5,g:6,h:7,i:8,j:9,k:10,l:11,m:12,n:13,o:14,p:15,q:16,r:17,s:18,t:19,u:20,v:21,w:22,x:23,y:24,z:25};

        p.sort((a,b) => a - b);

        for (let i = 0; i < p.length; i++) {
            let substr = a.slice(p[i-1] || 0, p[i]);

            for (let k = 0; k < substr.length; k++) {
                let ind = alph[substr[k]];
                result[ind] = result[ind] + p.length - i;
            }
        }
        return result.join(' ');
    }

    let testCount = 1;
    let answer = '';
    while(testCount <= +lines[0]) {
        let p = lines[testCount * 3].split(" ").map(Number);
        let a = lines[testCount * 3 - 1];

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

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]

main()

function main () {
  let t = getInt()
  while (t --> 0) {
    const params = getInts()
    const s = getLine()[0]
    const mistakes = getInts()
    solve(...params, s, mistakes)
  }
}

function solve (n, m, s, mistakes) {
  const freq = Array(n + 1).fill(0)
  const ans = Array(26).fill(0)
  let accumulate = 0

  mistakes.push(n)

  mistakes.map(i => {
    freq[0] ++
    freq[i] --
  })

  for (let i = 0; i < n; ++i) {
    const ind = s[i].charCodeAt() - 'a'.charCodeAt()
    accumulate += freq[i]
    ans[ind] += accumulate
  }

  print(ans.join(' '))
}

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]

main()

function main () {
  let t = getInt()
  while (t --> 0) {
    const params = getInts()
    const s = getLine()[0]
    const mistakes = getInts()
    solve(...params, s, mistakes)
  }
}

function solve (n, m, s, mistakes) {
  const freq = Array(n + 1).fill(0)
  const ans = Array(26).fill(0)
  let accumulate = 0

  mistakes.push(n)

  for (const i of mistakes) {
    freq[0] ++
    freq[i] --
  }

  for (let i = 0; i < n; ++i) {
    const ind = s[i].charCodeAt() - 'a'.charCodeAt()
    accumulate += freq[i]
    ans[ind] += accumulate
  }

  print(ans.join(' '))
}

function generateAlphabets() {
  var alphabets = [];
  var start = 'a'.charCodeAt(0);
  var last  = 'z'.charCodeAt(0);
  for (var i = start; i <= last; ++i) {
    alphabets.push(String.fromCharCode(i));
  }

  return alphabets;
}

const seq = generateAlphabets();

const processData = (lines) => {
  const num = +lines[0]
  for (let j=0; j<num; j++){
    const curAlpha = generateAlphabets().reduce((acc, letter) => {acc[letter] = 0; return acc}, {})
    const row = lines[j*3 + 2]
    const missed = lines[j*3 + 3].split(' ').map(x => x - 1).sort((a, b) => b-a)
    for (let j=0; j<row.length; j++) {
      while (missed.length > 0 && missed[missed.length -1] < j) {
        missed.pop()
      }
      curAlpha[row[j]] += missed.length + 1
    }
    let res = ''
    for (const letter of seq) {
      res += curAlpha[letter] + ' '
    }
    console.log(res)
  }
}

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

var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
function main(input) {
    var lines = input.trim().split("\n").map(function (l) { return l.trim(); });
    var t = parseInt(lines.shift(), 10);
    var _loop_1 = function () {
        var _a = lines.shift(), n = _a[0], m = _a[1];
        var lettersMap = "qwertyuiopasdfghjklzxcvbnm".split("").reduce(function (a, k) {
            var _a;
            return (__assign(__assign({}, a), (_a = {}, _a[k] = 0, _a)));
        }, {});
        var combo = lines.shift().split("");
        var tries = lines.shift().split(" ").map(function (v) { return parseInt(v, 10); });
        var willFail = combo.map(function (v) { return 0; });
        tries.forEach(function (ts) { return willFail[ts - 1]++; });
        var inc = 1;
        for (var i = willFail.length - 1; i >= 0; i--) {
            inc += willFail[i];
            lettersMap[combo[i]] += inc;
        }
        console.log(Object.entries(lettersMap).sort(function (_a, _b) {
            var k = _a[0];
            var l = _b[0];
            return k.charCodeAt(0) - l.charCodeAt(0);
        }).map(function (v) { return v[1]; }).join(" "));
    };
    while (t-- > 0) {
        _loop_1();
    }
}
(function () {
    var d = "";
    process.stdin.on("data", function (v) { return d += v; });
    process.stdin.on("end", function () { return main(d); });
})();

'use strict';

let n = parseInt(readline());

while ( n-- > 0 ) {
  let line = readline().split(' ').map(data => parseInt(data));
  solve(...line);
}

function solve(n, m) {
  const str = readline();
  let freq = Array(n + 1).fill(0);

  const mistakes = readline().split(' ').map(data => parseInt(data));
  mistakes.push(n);

  mistakes.forEach(x => {
    freq[0]++; freq[x]--;
  });

  let answer = Array(26).fill(0);
  let accumulated = 0;

  for ( let i = 0; i < str.length; ++i ) {
    accumulated += freq[i];
    answer[str.charCodeAt(i) - 97] += accumulated;
  }
  print(answer.join(' '));
}

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//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((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
    var alphaToNum = {
        "a" : 0,
        "b" : 1,
        "c" : 2,
        "d" : 3,
        "e" : 4,
        "f" : 5,
        "g" : 6,
        "h" : 7,
        "i" : 8,
        "j" : 9,
        "k" : 10,
        "l" : 11,
        "m" : 12,
        "n" : 13,
        "o" : 14,
        "p" : 15,
        "q" : 16,
        "r" : 17,
        "s" : 18,
        "t" : 19,
        "u" : 20,
        "v" : 21,
        "w" : 22,
        "x" : 23,
        "y" : 24,
        "z" : 25
    }
    var t = myconv(next(),1);
    var output = new Array(t);
    for(var i = 0; i < t; i++){
        var one = myconv(next(),4);
        var n = one[0];
        var m = one[1];
        var nlist = myconv(next(),6);
        var mlist = myconv(next(),4);
        var outAlpha = new Array(26).fill(0);
        var countMap = new Array(n);
        var tmpMap = {
        	"a" : 0,
        "b" : 0,
        "c" : 0,
        "d" : 0,
        "e" : 0,
        "f" : 0,
        "g" : 0,
        "h" : 0,
        "i" : 0,
        "j" : 0,
        "k" : 0,
        "l" : 0,
        "m" : 0,
        "n" : 0,
        "o" : 0,
        "p" : 0,
        "q" : 0,
        "r" : 0,
        "s" : 0,
        "t" : 0,
        "u" : 0,
        "v" : 0,
        "w" : 0,
        "x" : 0,
        "y" : 0,
        "z" : 0
        };
        for(var j = 0; j < n; j++){
          tmpMap[nlist[j]]++;
          	outAlpha[alphaToNum[nlist[j]]]++;
            countMap[j] = JSON.parse(JSON.stringify(tmpMap));
        }
        for(var j = 0; j < m; j++){
            var tmpCountMap = countMap[mlist[j] - 1];
            var tmpKeys = Object.keys(tmpCountMap);
            for(var k = 0; k < tmpKeys.length; k++){
                outAlpha[alphaToNum[tmpKeys[k]]] += tmpCountMap[tmpKeys[k]];
            }
        }
        output[i] = myconv(outAlpha,8);
    }
    myout(myconv(output,9));
}


;(function () {

	print(function (n, s, k) {

		for (var i = 1, l = s.length, _i = Math.floor(l / n); i <= _i; i++)
			if (i * n < l && s[i * n - 1] === s[i * n - 2] && s[i * n - 1] === s[i * n - 3]) k++;

		return k;

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

}.call(this));

print(function(n, s) {

	var ans = 0;

	for (var i = n; i < s.length; i += n)
		if (s[i - 1] === s[i - 2] && s[i - 2] === s[i - 3])
			ans++;

	return ans;

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

;(function () {

	print(function (n, s, k) {

		for (var i = 1, _i = Math.floor(s.length / n); i <= _i; i++)
			if (s[i * n - 1] === s[i * n - 2] && s[i * n - 1] === s[i * n - 3]) k++;

		return k;

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

}.call(this));


//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{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
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();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var a = next();
		var b = next();
		var area = [];
		var count = 0;
		var last = 0;
		for(var j = 0; j < N; j++){
			if(a[j] == "0"){
				count++;
			}else{
				count--;
			}
			if(count == 0){
				area.push({
					L : last,
					R : j
				});
				last = j + 1;
			}
		}

		var isOK = true;
		for(var j = last; j < N; j++){
			if(a[j] != b[j]){
				isOK = false;
				break;
			}
		}
		for(var j = 0; j < area.length; j++){
			var obj = area[j];
			var L = a.substring(obj.L, obj.R + 1);
			var R = "";
			for(var k = obj.L; k <= obj.R; k++){
				R += ((a[k] == "0") ? "1" : "0");
			}

			if(b.substring(obj.L, obj.R + 1) != L && b.substring(obj.L, obj.R + 1) != R){
				isOK = false;
				break;
			}
		}
		if(isOK){
			myout("YES");
		}else{
			myout("NO");
		}
	}

}

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

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

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

		a = a.split('');
		const dp = [];
		dp[-1] = 0;
		for (let i = 0; i < n; i++)
			dp[i] = dp[i-1] + (a[i] == '1') - (a[i] == '0');

		let ok = true;
		for (let i = n - 1, flpd = false; ok && i >= 0; i--) {
			if (flpd)
				a[i] = '10'[a[i]];

			if (a[i] != b[i]) {
				if (dp[i] != 0)
					ok = false;
				else
					flpd = !flpd;
			}
		}

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

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}
function getValue() {
  return parseInt(readline());
}
let mod = BigInt(1e9 + 7);
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let str = stringArr();
    let str1 = stringArr();
    let oarr = [],
      cnt0 = 0,
      cnt1 = 0,
      r = [];
    for (let i = 0; i < n; i++) {
      if (str[i] === "0") {
        cnt0++;
        r.push("1");
      } else {
        cnt1++;
        r.push("0");
      }
      oarr.push({ z: cnt0, o: cnt1 });
    }
    let i = str.length - 1,
      ans = true,
      l = str,
      k = 1;
    while (i >= 0) {
      let j = i;
      while (j >= 0 && l[j] !== str1[j]) j--;
      if (i !== j) {
        if (oarr[i].z !== oarr[i].o) {
          ans = false;
          break;
        }
        if (k) l = r;
        else l = str;
        k = !k;
        i = j;
      } else i--;
    }
    console.log(`${ans ? "YES" : "NO"}`);
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}
function getValue() {
  return parseInt(readline());
}
let mod = BigInt(1e9 + 7);
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let str = stringArr();
    let str1 = stringArr();
    const check = (st, ed) => {
      if (st === ed) return false;
      let cnt1 = 0,
        cnt2 = 0;
      for (let i = st; i <= ed; i++) {
        if (str[i] === "0") cnt1++;
        else cnt2++;
      }
      if (cnt1 === cnt2) return true;
      else return false;
    };
    let ans = true,
      i = 0;
    while (i < n) {
      let j = i;
      while (j < n && str[j] !== str1[j]) {
        j++;
      }
      if (i !== j) {
        if (j - 1 === i) {
          ans = false;
          break;
        }
        if (!check(0, j - 1)) {
          ans = false;
          break;
        }
        i = j;
      } else i++;
    }
    console.log(`${ans === true ? "YES" : "NO"}`);
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}
function getValue() {
  return parseInt(readline());
}
let mod = BigInt(1e9 + 7);
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let str = stringArr();
    let str1 = stringArr();
    const check = (st, ed) => {
      if (st === ed) return false;
      let cnt1 = 0,
        cnt2 = 0;
      for (let i = st; i <= ed; i++) {
        if (str[i] === "0") cnt1++;
        else cnt2++;
      }
      if (cnt1 === cnt2) return true;
      else return false;
    };
    let ans = true,
      i = 0;
    while (i < n) {
      let j = i;
      while (j < n && str[j] !== str1[j]) {
        j++;
      }
      if (i !== j) {
        if (!check(0, j - 1)) {
          ans = false;
          break;
        }
        i = j;
      } else i++;
    }
    console.log(`${ans === true ? "YES" : "NO"}`);
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}
function getValue() {
  return parseInt(readline());
}
let mod = BigInt(1e9 + 7);
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let str = stringArr();
    let str1 = stringArr();
    const check = (st, ed) => {
      if (st === ed) return false;
      let cnt1 = 0,
        cnt2 = 0;
      for (let i = st; i <= ed; i++) {
        if (str[i] === "0") cnt1++;
        else cnt2++;
      }
      if (cnt1 === cnt2) return true;
      else return false;
    };
    let ans = true,
      i = 0;
    while (i < n) {
      let j = i;
      while (j < n && str[j] !== str1[j]) {
        j++;
      }
      if (i !== j) {
        if (!check(i, j - 1)) {
          ans = false;
          break;
        }
        i = j;
      } else i++;
    }
    console.log(`${ans === true ? "YES" : "NO"}`);
  }
};
solve();


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

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

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

		let ans = -1;
		if (s.includes('aa')) ans = 2;
		else if (s.includes('aba') || s.includes('aca')) ans = 3;
		else if (s.includes('abca') || s.includes('acba')) ans = 4;
		else if (s.includes('abbacca') || s.includes('accabba')) ans = 7;

		console.log(ans);
	}
}

function getMin(arr) {
    var len = arr.length;
    var min = Infinity;

    while (len--) {
        min = arr[len] < min ? arr[len] : min;
    }
    return min;
}

function dominant_character(n,s){
  var ans = [];
  for (var i=0; i<n; i++){
    if(s[i]=='a'){
      for (var j=i+1; j<n; j++){

        var substring = s.substring(i,j+1);
        if(substring.length>7){
          break;
        }
        var c_a = (substring.match(/a/g) || []).length;
        var c_b = (substring.match(/b/g) || []).length;
        var c_c = (substring.match(/c/g) || []).length;
        if(c_a>c_c && c_a>c_b){
          ans.push(substring.length);
          break;
        }
      }
    }
  }
  if(ans.length>0){
    var result = getMin(ans);
  }
  else{
    var result = -1;
  }
  return result;
}

t = parseInt(readline());
for(var i=0; i<t; i++){
    var n = parseInt(readline());
    var s = readline();
    var ans = dominant_character(n,s);
    print(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) {
    if (contains(str, ['aa'])) return 2
    if (contains(str, ['aba', 'aca'])) return 3
    if (contains(str, ['abca', 'acba'])) return 4
    if (contains(str, ['abbacca', 'accabba'])) return 7
    return -1
}
function contains(str, ps) {
    return ps.some(p => str.indexOf(p) >= 0)
}

function dominant_character(n,s){
  var ans = [];
  for (var i=0; i<n; i++){
    if(s[i]=='a'){
      for (var j=i+1; j<n; j++){

        var substring = s.substring(i,j+1);
        if(substring.length>7){
          break;
        }
        var c_a = (substring.match(/a/g) || []).length;
        var c_b = (substring.match(/b/g) || []).length;
        var c_c = (substring.match(/c/g) || []).length;
        if(c_a>c_c && c_a>c_b){
          ans.push(substring.length);
          break;
        }
      }
    }
  }
  print(ans);
  if(ans.length>0){
    var result = Math.min(...ans);
  }
  else{
    var result = -1;
  }
  return result;
}

t = parseInt(readline());
for(var i=0; i<t; i++){
    var n = parseInt(readline());
    var s = readline();
    var ans = dominant_character(n,s);
    print(ans);
}

function dominant_character(n,s){
  var ans = [];
  for (var i=0; i<n; i++){
    if(s[i]=='a'){
      for (var j=i+1; j<n; j++){

        var substring = s.substring(i,j+1);
        if(substring.length>7){
          break;
        }
        var c_a = (substring.match(/a/g) || []).length;
        var c_b = (substring.match(/b/g) || []).length;
        var c_c = (substring.match(/c/g) || []).length;
        if(c_a>c_c && c_a>c_b){
          ans.push(substring.length);
          break;
        }
      }
    }
  }
  if(ans!=[]){
    var result = Math.min(...ans);
  }
  else{
    var result = -1;
  }
  return result;
}

t = parseInt(readline());
for(var i=0; i<t; i++){
    var n = parseInt(readline());
    var s = readline();
    var ans = dominant_character(n,s);
    print(ans);
}

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

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

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

		let ans = -1;
		if (s.includes('aa')) ans = 2;
		else if (s.includes('aba') || s.includes('aca')) ans = 3;
		else if (s.includes('abca') || s.includes('acba')) ans = 4;

		console.log(ans);
	}
}

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

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

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

		let ans = -1;
		if (s.includes('aa')) ans = 2;
		else if (s.includes('aba') || s.includes('aca')) ans = 3;

		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) {
    if (contains(str, ['aa'])) return 2
    if (contains(str, ['aba', 'aca'])) return 3
    if (contains(str, ['abca', 'abba', 'acca', 'acba'])) return 4
    return -1
}
function contains(str, ps) {
    return ps.some(p => str.indexOf(p) >= 0)
}


function solve() {
  var n = +readline();
  var a = readline().split(' ');
  //n = 100000;
  //a = [];
  //for (var i = 0; i < n; i++) {
    //a.push(i + 1);
 // }
  var need = 0;
  for (var i = 0; i < n; i++) {
    a[i] = +a[i];
    need += a[i];
  }
  if (need % 2 !== 0) {
    print("NO");
    return;
  }
  need /= 2;

  var was = new Set;

  var sum = 0;

  for (var i = 0; i < n; i++) {
    sum += a[i];
    was.add(a[i]);
    var val = sum - need;
    if (was.has(val)) {
      print("YES");
      return;
    }
  }

  was = new Set;

  sum = 0;

  a = a.reverse();

  for (var i = 0; i < n; i++) {
    sum += a[i];
    was.add(a[i]);
    var val = sum - need;
    if (was.has(val)) {
      print("YES");
      return;
    }
  }

  print("NO");

}
solve();

function foo(array) {
  var length = array.length;

  var need = 0;
  for (var i=0; i<length; i++) {
    need += array[i];
  }

  if (need%2 === 1) {
    print('NO');
    return;
  }

  need /= 2;

  var res = new Set();
  var sum = 0;

  for (i=0; i<length; i++) {
    var n = array[i];

    sum += n;
    res.add(n);

    if (res.has(sum - need)) {
      print('YES');
      return;
    }
  }

  var res2 = new Set();
  sum = 0;

  array = array.reverse();

  for (i=0; i<length; i++) {
    var n = array[i];

    sum += n;
    res2.add(n);

    if (res2.has(sum - need)) {
      print('YES');
      return;
    }
  }

  print("NO");
}

var l = readline();
var arr = readline().split(" ").map(function(x) { return parseInt(x); });

foo(arr);

function solve() {
  var n = +readline();
  var a = readline().split(' ');
  var need = 0;
  for (var i = 0; i < n; i++) {
    a[i] = +a[i];
    need += a[i];
  }
  if (need % 2 !== 0) {
    print("NO");
    return;
  }
  need /= 2;

  var was = {};

  var sum = 0;

  for (var i = 0; i < n; i++) {
    sum += a[i];
    was[a[i]] = true;
    var val = sum - need;
    if (was[val]) {
      print("YES");
      return;
    }
  }

  print("NO");

}
solve();

function solve() {
  var n = +readline();
  var a = readline().split(' ');
  //n = 100000;
  //a = [];
  //for (var i = 0; i < n; i++) {
    //a.push(i + 1);
 // }
  var need = 0;
  for (var i = 0; i < n; i++) {
    a[i] = +a[i];
    need += a[i];
  }
  if (need % 2 !== 0) {
    print("NO");
    return;
  }
  need /= 2;

  var was = new Set;

  var sum = 0;

  for (var i = 0; i < n; i++) {
    sum += a[i];
    was.add(a[i]);
    var val = sum - need;
    if (was.has(val)) {
      print("YES");
      return;
    }
  }

  print("NO");

}
solve();

function solve() {
  var n = +readline();
  var a = readline().split(' ');
  //n = 100000;
  //a = [];
  //for (var i = 0; i < n; i++) {
    //a.push(i + 1);
 // }
  var need = 0;
  for (var i = 0; i < n; i++) {
    a[i] = +a[i];
    need += a[i];
  }
  if (need % 2 !== 0) {
    print("NO");
    return;
  }
  need /= 2;

  var was = [];

  var sum = 0;

  for (var i = 0; i < n; i++) {
    sum += a[i];
    was[a[i]] = true;
    var val = sum - need;
    if (val > 1000000000 || val <= 0) {
      continue;
    }
    if (was[val]) {
      print("YES");
      return;
    }
  }

  print("NO");

}
solve();


// s of n
// power two
let lines = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', input => lines += input)
process.stdin.on('end', () => {
  const { EOL } = require('os')
  lines = lines.split(EOL)

  main()
})

function main() {
  const q = lines[0]

  for(let i = 1; i <= q * 2; i+=2) {
    const n = lines[i]
    const s = lines[i + 1].split(/\s/)
    const m = {}
    let result = false

    s.some(v => {
      if(!m[v]) m[v] = []

      m[v].push(Number(v))

      if(m[v].length === 2) {
        const sum = makeSum(m, v)

        if(sum === 2048) {
          result = true
          return result
        }
      } else {
        if(v === '2048') {
          result = true
          return result
        }
      }
    })

    console.log(result ? 'YES' : 'NO')
  }
}

function makeSum(m, v) {
  const sum = Number(v) + Number(v)

  if(!m[sum]) m[sum] = []

  m[sum].push(sum)
  m[v] = []

  if(m[sum].length === 2) {
    return makeSum(m, sum)
  } else {
    return sum
  }
}

q=+readline()
while (q--){
    a=new Array(2049)
    for (i=0;i<=2048;i++)
        a[i]=0
    n=+readline()
    s=readline().split(' ').map(function(x){a[+x]++;return undefined})
    for (i=2;i<=2048;i*=2){
        a[i]+=a[i/2]>>1
    }
    if (a[2048])
    print("YES")
    else
    print("NO")
}

"use strict";

String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

var gamesAmount = parseInt(readline());
var answers = [];
var nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048];

var _loop = function _loop(game) {
  var n = parseInt(readline());
  var s = readline().getNumArray();
  var obj = {
    1: 0,
    2: 0,
    4: 0,
    8: 0,
    16: 0,
    32: 0,
    64: 0,
    128: 0,
    256: 0,
    512: 0,
    1024: 0,
    2048: 0
  };
  var answer = 'YES';

  for (var i = 0; i < n; i++) {
    if (s[i] === 2048) {
      obj[2048] = 1;
      break;
    }

    if (s[i] < 2048) {
      obj[s[i]] += 1;
    }
  }

  if (obj[2048]) {
    answers.push(answer);
    return "continue";
  } else {
    nums.forEach(function (_n) {
      var nextN = _n * 2;
      var nextNAmount = Math.floor((obj[_n] || 0) / 2);
      obj[nextN] += nextNAmount;
    });

    if (!obj[2048]) {
      answer = 'NO';
    }

    answers.push(answer);
  }
};

for (var game = 0; game < gamesAmount; game++) {
  var _ret = _loop(game);

  if (_ret === "continue") continue;
}

write(answers.join('\n'));

// s of n
// power two
let lines = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', input => lines += input)
process.stdin.on('end', () => {
  const { EOL } = require('os')
  lines = lines.split(EOL)

  main()
})

function main() {
  const q = lines[0]

  for(let i = 1; i <= q * 2; i+=2) {
    const n = lines[i]
    const s = lines[i + 1].split(/\s/).map(Number).sort((a, b) => a - b)
    let result = false
    let p = s[0]
    let sum = p

    s.slice(1).some(v => {
      if(sum === 2048) {
        return true
      } else if(v === 2048) {
        sum = v
        return true
      }

      if(p === v) {
        sum = p + v
        p = sum
      } else {
        p = v
      }
    })

    if(sum === 2048) {
      result = true
    }

    console.log(result ? 'YES' : 'NO')
  }
}

"use strict";

String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

var gamesAmount = parseInt(readline());
var answers = [];
var nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048];

var _loop = function _loop(game) {
  var n = parseInt(readline());
  var s = readline().getNumArray();
  var obj = {
    1: 0,
    2: 0,
    4: 0,
    8: 0,
    16: 0,
    32: 0,
    64: 0,
    128: 0,
    256: 0,
    512: 0,
    1024: 0,
    2048: 0
  };
  var answer = 'YES';

  for (var i = 0; i < n; i++) {
    if (s[i] === 2048) {
      obj[2048] = 1;
      break;
    }

    if (s[i] < 2048) {
      obj[s[i]] += 1;
    }

    nums.forEach(function (_n) {
      var nextN = _n * 2;
      var nextNAmount = Math.floor((obj[_n] || 0) / 2);
      obj[nextN] += nextNAmount;
    });
  }

  if (!obj[2048]) {
    answer = 'NO';
  }

  answers.push(answer);
};

for (var game = 0; game < gamesAmount; game++) {
  _loop(game);
}

write(answers.join('\n'));


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

//Don't have to see. end------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array(t);
  for(var i = 0; i < t; i++){
    var N = nextInt();
    var list = nextIntArray();
    var tmp = [];
    for(var j = 0; j < N; j++){
      tmp.push(list.pop());
    }
    output[i] = myconv(tmp, 8);
  }
  myout(myconv(output, 9));
}

let input = '';
let inputResolve;
let inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => inputResolve());

function For(a, b, cb) {
  let res;
  if (a < b) {
    for (let i = a; i <= b; i++) {
      if ((res = cb(i)) !== undefined) return res;
    }
  } else {
    for (let i = a; i >= b; i--) {
      if ((res = cb(i)) !== undefined) return res;
    }
  }
}

function Arr(a, b, cb, prev) {
  let p = prev || 0;
  if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb ? (p = cb(a + i, p)) : a + i);
  return Array(a - b + 1).fill(0).map((v, i) => cb ? (p = cb(a - i, p)) : a - i);
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex(v => v == min);
  return [this[i], i, min];
}
Array.prototype.max = function (fn) {
  let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex(v => v == max);
  return [this[i], i, max];
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}

(async () => {
  await inputPromise;
  let inp = input.split(/\s+/).map(v => +v); r = 0;
  t = inp[r++];
  while (t--) {
    let n = inp[r++];
    let a = inp.slice(r, r = r + n);
    console.log(a.reverse().join(' '))
  }
})();

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

    A();
});

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

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

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

    return a;
}

function A(){
    let t = pi(readline());

    while(t > 0){
        t--;
        let n = pi(readline());
        let a = ti(readline().split(' '));
        for(let i = 0; i < Math.floor(n/2); i++){
            let temp = a[i];
            a[i] = a[n-i-1];
            a[n-i-1] = temp;
        }

        for(let num of a)
            console.log(num);
    }
}

function F(){
    let [n,x] = ti(readline().split(' '));
    let s = readline();
    let t = readline();

    let dp = new Array(n);
    for(let i = 0; i < n; i++){
        dp[i] = new Array(x+1);
        for(let j = 0; j <= x; j++){
            dp[i][j] = new Array(n);
            dp[i][j].fill(0);
        }
    }

    for(let i = 1; i < n; i++){
        for(let j = 0; j <= x; j++){
            for(let k = 0; k <= n; k++){
                dp[i][j][k] = Math.max(dp[i][j][k], dp[i-1][j][k-1] + (s.charAt(i) === t.charAt(1) ? k-1 : 0));
                if(j !== 0){
                    dp[i][j][k] = Math.max(dp[i][j][k], dp[i-1][j-1][k-1] + (t.charAt(0) === t.charAt(1) ? k-1 : 0));
                    dp[i][j][k] = Math.max(dp[i][j][k], dp[i-1][j-1][k-1] + k-1);
                }
            }
        }
    }

    let max = 0;
    for(let i = 0; i < x; i++)
        for(let j = 0; j < n; j++)
            max = Math.max(max, dp[n-1][i][j]);

    console.log(max);
}

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const arr = readLine()
      .split(" ")
      .map((n) => parseInt(n));

    arr.reverse();
    console.log(arr.join(" "));
  }
}

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

//Don't have to see. end------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array(t);
  for(var i = 0; i < t; i++){
    var N = nextInt();
    var list = nextIntArray();
    list.sort(function(){
      return 1;
    });
    output[i] = myconv(list, 8);
  }
  myout(myconv(output, 9));
}

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

    A();
});

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

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

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

    return a;
}

function A(){
    let t = pi(readline());

    while(t > 0){
        t--;
        let n = pi(readline());
        let a = ti(readline().split(' '));
        if(n % 2 === 0){
            for(let i = 1; i < n; i += 2){
                let temp = a[i-1];
                a[i-1] = a[i];
                a[i] = temp;
            }
        }else{
            for(let i = 0; i < Math.floor(n/2); i++){
                let temp = a[i];
                a[i] = a[n-i-1];
                a[n-i-1] = temp;
            }
        }

        for(let num of a)
            console.log(num);
    }
}

function F(){
    let [n,x] = ti(readline().split(' '));
    let s = readline();
    let t = readline();

    let dp = new Array(n);
    for(let i = 0; i < n; i++){
        dp[i] = new Array(x+1);
        for(let j = 0; j <= x; j++){
            dp[i][j] = new Array(n);
            dp[i][j].fill(0);
        }
    }

    for(let i = 1; i < n; i++){
        for(let j = 0; j <= x; j++){
            for(let k = 0; k <= n; k++){
                dp[i][j][k] = Math.max(dp[i][j][k], dp[i-1][j][k-1] + (s.charAt(i) === t.charAt(1) ? k-1 : 0));
                if(j !== 0){
                    dp[i][j][k] = Math.max(dp[i][j][k], dp[i-1][j-1][k-1] + (t.charAt(0) === t.charAt(1) ? k-1 : 0));
                    dp[i][j][k] = Math.max(dp[i][j][k], dp[i-1][j-1][k-1] + k-1);
                }
            }
        }
    }

    let max = 0;
    for(let i = 0; i < x; i++)
        for(let j = 0; j < n; j++)
            max = Math.max(max, dp[n-1][i][j]);

    console.log(max);
}


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

const getLine = (function () {
    const getLineGen = (async function* () {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async () => {
        let next;
        do {
            next = (await getLineGen.next());
        } while (!next.done && next.value === '');
        return next.value;
    };
})();

let solve = async () => {
    const nsc = parseInt(await getLine());
    for(let sc = 0; sc < nsc; sc++) {
        const n = parseInt(await getLine());
        const ar = (await getLine()).split(' ').map(num => parseInt(num));
        ar.sort((a,b) => (a-b));
        let sum = BigInt(ar[n-1]);
        for(let i = 1; i < n; i++) {
            sum -= BigInt(ar[i] - ar[i-1]) * BigInt(i) * BigInt(n - i);
        }
        console.log(sum.toString());
    }
}

solve();

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
// import * as readline from 'readline'
// const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
// const ask = (query: string) => new Promise<string>((resolve) => rl.question(query, resolve))
// // Don't forget `rl.close()`.
const INT = Math.floor;
Array.prototype.last = function () {
    return this.length === 0 ? undefined : this[this.length - 1];
};
Array.prototype.isEmpty = function () {
    return this.length === 0;
};
const less = (a, b) => (a == b ? 0 : a < b ? -1 : 1);
const greater = (a, b) => (a == b ? 0 : a < b ? 1 : -1);
const bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));
const bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));
const bigIntAbs = (arg) => (arg < 0 ? -arg : arg);
function read_stdin() {
    return fs.readFileSync(process.env.NODE_ENV === 'debug' ? stdin : process.stdin.fd, 'utf8');
}
class Input {
    constructor(str) {
        this.index = 0;
        this.inputs = (str ? str : read_stdin()).split(/\s+/);
    }
    number() {
        return Number(this.inputs[this.index++]);
    }
    numbers(n) {
        return this.inputs.slice(this.index, (this.index += n)).map(Number);
    }
    bigint() {
        return BigInt(this.inputs[this.index++]);
    }
    bigints(n) {
        return this.inputs.slice(this.index, (this.index += n)).map(BigInt);
    }
    word() {
        return this.inputs[this.index++];
    }
    words(n) {
        return this.inputs.slice(this.index, (this.index += n));
    }
}
function array(len, init) {
    return Array(len).fill(init);
}
function array2(h, w, init) {
    return array(h, 0).map(() => array(w, init));
}
function main() {
    const input = new Input();
    const T = input.number();
    const ans = Array(T);
    for (let k = 0; k < T; k++) {
        const N = input.number();
        const A = input.numbers(N);
        A.sort((a, b) => a - b);
        let sum = 0n;
        let acc = 0;
        for (let [i, j] = [N - 1, 0]; i >= 1; i--, j++) {
            acc += i - j;
            sum -= BigInt(acc - 1) * BigInt(A[j + 1] - A[j]);
        }
        ans[k] = sum;
    }
    console.log(ans.join('\n'));
}
main();
//# sourceMappingURL=aoj.js.map

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = +lines[0]
    var l = 1;
    for (var i = 0; i < t; i++) {
        var n = +lines[l++]
        var arr = lines[l++].split(' ').map(Number)
        console.log(solve(n, arr));
    }
});

function solve(n, arr) {
    if (n === 1) return 0

    arr.sort((a, b) => a - b)
    // let ans = 0
    // let s = 0
    // for (let i = 0; i < n; ++i) {
    //     ans -= arr[i] * i;
    //     ans += s;
    //     s += arr[i];
    // }
    // ans += arr[n - 1];
    // return ans

    const segs = []
    arr.forEach((a, i) => {
        let val
        if (i) {
            val = arr[i] - arr[i - 1]
        } else {
            val = arr[i]
        }
        // filter the first
        if (i) {
            segs.push(BigInt(val))
        }
    })
    // console.log(segs)

    const dp = []
    let count = 0n
    let sum = 0n // sum of those end with i
    segs.forEach((a, i) => {
        sum += count * a + a
        count++
        if (i) {
            dp[i] = dp[i - 1] + sum
        } else {
            dp[i] = a
        }
    })
    // console.log(dp)
    const result = calSum(segs) - dp[segs.length - 1]
    return result.toString()
}

function calSum(arr) {
    return arr.reduce((s, x) => s + x, 0n)
}

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = +lines[0]
    var l = 1;
    for (var i = 0; i < t; i++) {
        var n = +lines[l++]
        var arr = lines[l++].split(' ').map(Number)
        console.log(solve(n, arr));
    }
});

function solve(n, arr) {
    if (n === 1) return 0

    arr.sort((a, b) => a - b)
    // let ans = 0
    // let s = 0
    // for (let i = 0; i < n; ++i) {
    //     ans -= arr[i] * i;
    //     ans += s;
    //     s += arr[i];
    // }
    // ans += arr[n - 1];
    // return ans

    const segs = []
    arr.forEach((a, i) => {
        let val
        if (i) {
            val = arr[i] - arr[i - 1]
        } else {
            val = arr[i]
        }
        // filter the first
        if (i) {
            segs.push(val)
        }
    })
    // console.log(segs)

    const dp = []
    let count = 0
    let sum = 0 // sum of those end with i
    segs.forEach((a, i) => {
        sum += count * a + a
        count++
        if (i) {
            dp[i] = dp[i - 1] + sum
        } else {
            dp[i] = a
        }
    })
    // console.log(dp)
    return calSum(segs) - dp[segs.length - 1]
}

function calSum(arr) {
    return arr.reduce((s, x) => s + x, 0)
}

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = +lines[0]
    var l = 1;
    for (var i = 0; i < t; i++) {
        var n = +lines[l++]
        var arr = lines[l++].split(' ').map(Number)
        console.log(solve(n, arr));
    }
});

function solve(n, arr) {
    if (n === 1) return 0

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

    const segs = []
    arr.forEach((a, i) => {
        let val
        if (i) {
            val = arr[i] - arr[i - 1]
        } else {
            val = arr[i]
        }
        // filter 0
        if (val) {
            segs.push(val)
        }
    })
    // console.log(segs)

    const dp = []
    segs.forEach((a, i) => {
        if (i) {
            dp[i] = dp[i - 1] + a + a + dp[i - 1]
        } else {
            dp[i] = a
        }
    })
    return calSum(segs) - dp[segs.length - 1]
}

function calSum(arr) {
    return arr.reduce((s, x) => s + x, 0)
}

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

const getLine = (function () {
    const getLineGen = (async function* () {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async () => {
        let next;
        do {
            next = (await getLineGen.next());
        } while (!next.done && next.value === '');
        return next.value;
    };
})();

let solve = async () => {
    const nsc = parseInt(await getLine());
    for(let sc = 0; sc < nsc; sc++) {
        const n = parseInt(await getLine());
        const ar = (await getLine()).split(' ').map(num => parseInt(num));
        ar.sort((a,b) => (a-b));
        let sum = ar[n-1];
        for(let i = 1; i < n; i++) {
            sum -= (ar[i] - ar[i-1]) * (i) * (n - i);
        }
        console.log(sum);
    }
}

solve();


var n = +readline(),
    dims = [],
    dim, i, h, s, pair, min = +Infinity;
for (i = 0; i < n; i++) {
    pair = readline().split(' ');
    dims[i] = [];
    dims[i][0] = +pair[0];
    dims[i][1] = +pair[1];
}
for (h = 1000; h > 0; h--) {
    s = 0;
    for (i = 0; i < n; i++) {
        dim = dims[i].sort(function(a,b) {
            return a - b;
        });
        if (h < dim[0]) {
            h = 0;
            break;
        } else {
            s += h*dim[h < dim[1] ? 1 : 0];
        }
    }
    h == 0 || (min = Math.min(min, s));
}
print(min);

var n = readline();
var sizes = [];

for (var i = 0; i < n; i++) {
	var line = readline().split(' ').map((v) => {
		return Number(v);
	});
	sizes[i] = {};
	sizes[i].width = line[0];
	sizes[i].height = line[1];
}

var result;
for (var i = 0; i < n; i++) {
	var height = sizes[i].height;
	var width = compare(i, height);
	if (width != -1) {
		var size = (width + sizes[i].width) * height;
		if (result) {
			if (result > size) {
				result = size;
			}
		} else {
			result = size;
		}
	}
	height = sizes[i].width;
	width = compare(i, height);
	if (width != -1) {
		var size = (width + sizes[i].height) * height;
		if (result) {
			if (result > size) {
				result = size;
			}
		} else {
			result = size;
		}
	}
}

function compare(i, height) {
	var width = 0;
	for (var j = 0; j < n; j++) {
		if (j != i) {
			if (sizes[j].height <= height || sizes[j].width <= height) {
				if (sizes[j].height <= height && sizes[j].width <= height) {
					if (sizes[j].height <= sizes[j].width) {
						width += sizes[j].height;
					} else {
						width += sizes[j].width;
					}
				} else if (sizes[j].width <= height) {
					width += sizes[j].height;
				} else {
					width += sizes[j].width;
				}
			} else {
				return -1;
			}
		}
	}
	if (width != undefined) {
		return width;
	} else {
		return -1;
	}
}

print(result)

var n = readline();
var sizes = [];

for (var i = 0; i < n; i++) {
	var line = readline().split(' ').map((v) => {return Number(v);});
	sizes[i] = {};
	sizes[i].width = line[0];
	sizes[i].height = line[1];
}

var result;
for (var i = 0; i < n; i++) {
	var height = sizes[i].height;
	var width = compare(i, height);
	if (width) {
		width = (width + sizes[i].width) * height;
		if (result) {
			if (result > width) {
				result = width;
			}
		} else {
			result = width;
		}
	}
	height = sizes[i].width;
	width = compare(i, height);
	if (width) {
		width = (width + sizes[i].height) * height;
		if (result) {
			if (result > width) {
				result = width;
			}
		} else {
			result = width;
		}
	}
}

function compare(i, height) {
	var width = 0;
	for (var j = 0; j < n; j++) {
		if (j != i) {
			if (sizes[j].height < height || sizes[j].width < height) {
				if (sizes[j].height < height && sizes[j].width < height) {
					if (sizes[j].height < sizes[j].width) {
						width += sizes[j].height;
					} else {
						width += sizes[j].width;
					}
				} else if (sizes[j].width <= height) {
					width += sizes[j].height;
				} else {
					width += sizes[j].width;
				}
			} else {
				return 0;
			}
		}
	}
	if (width) {
		print(width + sizes[i].height, height)
		return width;
	}
}

print(result)

var n = readline();
var sizes = [];

for (var i = 0; i < n; i++) {
	var line = readline().split(' ').map((v) => {return Number(v);});
	sizes[i] = {};
	sizes[i].width = line[0];
	sizes[i].height = line[1];
}

var result;
for (var i = 0; i < n; i++) {
	var height = sizes[i].height;
	var width = compare(i, height);
	if (width) {
		width = (width + sizes[i].width) * height;
		if (result) {
			if (result > width) {
				result = width;
			}
		} else {
			result = width;
		}
	}
	height = sizes[i].width;
	width = compare(i, height);
	if (width) {
		width = (width + sizes[i].height) * height;
		if (result) {
			if (result > width) {
				result = width;
			}
		} else {
			result = width;
		}
	}
}

function compare(i, height) {
	var width = 0;
	for (var j = 0; j < n; j++) {
		if (j != i) {
			if (sizes[j].height < height || sizes[j].width < height) {
				if (sizes[j].height < height && sizes[j].width < height) {
					if (sizes[j].height < sizes[j].width) {
						width += sizes[j].height;
					} else {
						width += sizes[j].width;
					}
				} else if (sizes[j].width <= height) {
					width += sizes[j].height;
				} else {
					width += sizes[j].width;
				}
			} else {
				return 0;
			}
		}
	}
	if (width) {
		return width;
	}
}

print(result)

var n = readline();
var sizes = [];

for (var i = 0; i < n; i++) {
	var line = readline().split(' ').map((v) => {return Number(v);});
	sizes[i] = {};
	sizes[i].width = line[0];
	sizes[i].height = line[1];
}

var result;
for (var i = 0; i < n; i++) {
	var height = sizes[i].height;
	var width = compare(i, height);
	if (width) {
		width = (width + sizes[i].width) * height;
		if (result) {
			if (result > width) {
				result = width;
			}
		} else {
			result = width;
		}
	}
	height = sizes[i].width;
	var width = compare(i, height);
	if (width) {
		width = (width + sizes[i].width) * height;
		if (result) {
			if (result > width) {
				result = width;
			}
		} else {
			result = width;
		}
	}
}

function compare(i, height) {
	var width = 0;
	for (var j = 0; j < n; j++) {
		if (j != i) {
			if (sizes[j].height < height || sizes[j].width < height) {
				if (sizes[j].height < height && sizes[j].width < height) {
					if (sizes[j].height < sizes[j].width) {
						width += sizes[j].height;
					} else {
						width += sizes[j].width;
					}
				} else if (sizes[j].width < height) {
					width += sizes[j].height;
				} else {
					width += sizes[j].width;
				}
			} else {
				return 0;
			}
		}
	}
	if (width) {
		return width;
	}
}

print(result)

var n = readline();
var sizes = [];

for (var i = 0; i < n; i++) {
	var line = readline().split(' ').map((v) => {
		return Number(v);
	});
	sizes[i] = {};
	sizes[i].width = line[0];
	sizes[i].height = line[1];
}

var result;
for (var i = 0; i < n; i++) {
	var height = sizes[i].height;
	var width = compare(i, height);
	if (width != -1) {
		var size = (width + sizes[i].width) * height;
		if (result) {
			if (result > size) {
				result = size;
			}
		} else {
			result = size;
		}
	}
	height = sizes[i].width;
	width = compare(i, height);
	if (width != -1) {
		var size = (width + sizes[i].height) * height;
		if (result) {
			if (result > size) {
				result = size;
			}
		} else {
			result = size;
		}
	}
}

function compare(i, height) {
	var width = 0;
	for (var j = 0; j < n; j++) {
		if (j != i) {
			if (sizes[j].height <= height || sizes[j].width <= height) {
				if (sizes[j].height <= height && sizes[j].width <= height) {
					if (sizes[j].height <= sizes[j].width) {
						width += sizes[j].height;
					} else {
						width += sizes[j].width;
					}
				} else if (sizes[j].width <= height) {
					width += sizes[j].height;
				} else {
					width += sizes[j].width;
				}
			} else {
				return -1;
			}
		}
	}
	if (width) {
		return width;
	} else {
		return -1;
	}
}

print(result)

var n = readline();
var sizes = [];

for (var i = 0; i < n; i++) {
	var line = readline().split(' ').map((v) => {return Number(v);});
	sizes[i] = {};
	sizes[i].width = line[0];
	sizes[i].height = line[1];
}

var result;
for (var i = 0; i < n; i++) {
	var height = sizes[i].height;
	var width = compare(i, height);
	width = (width + sizes[i].width) * height;
	if (result) {
		if (result > width) {
			result = width;
		}
	} else {
		result = width;
	}
	height = sizes[i].width;
	width = compare(i, height);
	width = (width + sizes[i].height) * height;
	if (result) {
		if (result > width) {
			result = width;
		}
	} else {
		result = width;
	}
}

function compare(i, height) {
	var width = 0;
	for (var j = 0; j < n; j++) {
		if (j != i) {
			if (sizes[j].height <= height || sizes[j].width <= height) {
				if (sizes[j].height < height && sizes[j].width < height) {
					if (sizes[j].height < sizes[j].width) {
						width += sizes[j].height;
					} else {
						width += sizes[j].width;
					}
				} else if (sizes[j].width <= height) {
					width += sizes[j].height;
				} else {
					width += sizes[j].width;
				}
			} else {
				return 0;
			}
		}
	}
	if (width) {
		return width;
	} else {
		return 0;
	}
}

print(result)


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 => string.trim());

    main();
});

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

const s2i = s => parseInt(s, 10);

function main() {
  let T = s2i(readLine());
  let a, b, c, r1, r2;
  while (T--) {
    [a, b, c] = readLine().split(' ').map(s2i);

    if (a < c) {
      r1 = 1;
    } else {
      r1 = -1;
    }

    if (c/b < a) {
      r2 = b;
    } else {
      r2 = -1;
    }

    console.log(r1 + ' ' + r2);
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStd) => {
  inputString += inputStd;
});
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--) {
    let [a, b, c] = readLine()
      .split(" ")
      .map((num) => parseInt(num));
    let [l, r] = [-1, -1];
    if (a < c) l = 1;

    if (a * b > c) r = b;

    console.log(`${l} ${r}`);
  }
}

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

let stdinInput = '';

process.stdin.on('data', input => {
  stdinInput += input;
});

process.stdin.on('end', () => {
  main(stdinInput);
});

function main(data) {
  data = data.split('\n');
  const testCases = data[0] * 1;
  let i = 1;
  while (i <= testCases) {
    let str = data[i].split(' ');
    let a = +str[0];
    let b = +str[1];
    let c = +str[2];
    if ((a == c && a == b) || a > c) {
      console.log(-1, b);
      i += 1;
      continue;
    }
    if (a == c) {
      console.log(-1, b);
      i += 1;
      continue;
    }
    if (a * b <= c) {
      console.log(1, -1);
      i += 1;
      continue;
    }
    console.log(1, b);
    i += 1;
  }
}

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

let stdinInput = '';

process.stdin.on('data', input => {
  stdinInput += input;
})

process.stdin.on('end', () => {
  main(stdinInput);
})

function main(data) {
    data = data.split(/\r?\n/);
    const testCases = data[0] * 1;
    let numAnswered = 0
    let i = 1;
    while (i <= testCases) {
        let split = data[i].split(" ")
        let a = split[0] * 1
        let b = split[1] * 1
        let c = split[2] * 1

        let shop1Cheaper = 0
        let x = 1
        let curDiff = Number.MAX_VALUE
        while (shop1Cheaper === 0) {
            let tempDiff = a * x - Math.ceil(x/b) * c
            let endIfNotAnswer = tempDiff > curDiff
            curDiff = tempDiff
            shop1Cheaper = curDiff < 0 ? x : (endIfNotAnswer ? -1 : 0)
            x++
        }

        let shop2Cheaper = 0
        x = b
        curDiff = Number.NEGATIVE_INFINITY
        while (shop2Cheaper === 0) {
            let tempDiff = a * x - Math.ceil(x/b) * c
            let endIfNotAnswer = tempDiff < curDiff
            curDiff = tempDiff
            shop2Cheaper = curDiff > 0 ? x : (endIfNotAnswer ? -1 : 0)
            x++
        }
        console.log(`${shop1Cheaper} ${shop2Cheaper}`)
        i++
    }
}

var n = readline();
var mapping =[];

for (var i = 0; i<n;i++){
    mapping.push(readline().split(" ").map(function (x) {
        return parseInt(x);
    }));
}

for (var i = 0; i<n;i++) {
    if (mapping[i][0]>=mapping[i][2]){
        write(-1 + " ");
    }else{
        var ni = 1;
        while (true){
            if (mapping[i][0] * ni < mapping[i][2] * Math.ceil(parseFloat(ni/mapping[i][1]))){
                break;
            }
            ni++;
        }
        write(ni + " ");
    }

    if (parseFloat(mapping[i][0]) <= parseFloat(mapping[i][2] / mapping[i][1])){
        write(-1 + "\n");
    }else{
        var ni = 1;
        while (true){
            if (parseInt(mapping[i][2] * ni) < parseInt(mapping[i][0] * mapping[i][1] * ni)){
                break;
            }
            ni++;
        }
        write(ni *mapping[i][1]  + "\n");
    }

}

function solve() {
   var T = Number(read());
   var ans = [-1, -1];
   for (var t = 0; t < T; t++) {
      var abc = read().split(' ').map(BigInt);
      var a = abc[0];
      var b = abc[1];
      var c = abc[2];
      ans[0] = a < c ? 1 : -1;
      ans[1] = a * b > c ? b : -1;
      write(ans.join(' '));
   }
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         solve();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

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

      RL.on('close', solve);
   }
} else {
   solve();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStd) => {
  inputString += inputStd;
});
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--) {
    let [single, totalItem, totalValue] = readLine()
      .split(" ")
      .map((num) => parseInt(num));
    let [left, right] = [-1, -1];
    if (single - totalValue < 0) {
      left = 1;
      if (+(totalValue / totalItem).toFixed(2) < single) right = 1;
      console.log(`${left} ${right}`);
    } else {
      console.log(`${left} ${1}`);
    }
  }
}

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

let stdinInput = '';

process.stdin.on('data', input => {
  stdinInput += input;
});

process.stdin.on('end', () => {
  main(stdinInput);
});

function main(data) {
    data = data.split('\n');
    const testCases = data[0] * 1;
    let i = 1;
    while (i <= testCases) {
      let str = data[i].split(' ');
      let a = +str[0];
      let b = +str[1];
      let c = +str[2];
      if ((a == c && a == b) || a > c) {
        console.log(-1, b);
        i += 1;
        continue;
      }
      if (a * b <= c) {
        console.log(1, -1);
        i += 1;
        continue;
      }
      console.log(1, b);
      i += 1;
    }
  }