In order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game.Tzuyu gave Sana two integers $$$a$$$ and $$$b$$$ and a really important quest.In order to complete the quest, Sana has to output the smallest possible value of ($$$a \oplus x$$$) + ($$$b \oplus x$$$) for any given $$$x$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^{4}$$$). Description of the test cases follows. The only line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^{9}$$$).

For each testcase, output the smallest possible value of the given expression.

NoteFor the first test case Sana can choose $$$x=4$$$ and the value will be ($$$6 \oplus 4$$$) + ($$$12 \oplus 4$$$) = $$$2 + 8$$$ = $$$10$$$. It can be shown that this is the smallest possible value.

const solve = (a, b) => {
    let x = selectX(a, b)
    return (a ^ x) + (b ^ x);
};

const selectX = (A, B) => {
    let j = 0;
    let x = 0;
    while (A || B) {
        if ((A & 1) && (B & 1)) {
            x += (1 << j);
        }
        A >>= 1;
        B >>= 1;
        j += 1;
    }
    return x;
};

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

main()

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));
const sub = (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 pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const [a, b] = readLine().split(" ").map(Number);
    console.log(a ^ (0 + b) ^ 0);
  }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	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 one = nextIntArray();
		var a = one[0];
		var b = one[1];
		output[i] = a ^ b;
	}
	myout(myconv(output, 9));
}

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

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

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

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
function inv(b, m) {
  for (var a = m, u = 0, v = 1, t; b; v = t)
    (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
  return (u + m) % m;
}

// let MOD = 1e9 + 7
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

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

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

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }
// az = "abcdefghijklmnopqrstuvwxyz"

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2, hypot } = Math,
    bi = BigInt, rand = n => Math.random() * n | 0;

  let t = $()
  while (t--) {
    let [a, b] = $(2)
    log(a^b)
  }
}

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

let values = [];

readline.on('line', line => {
  values.push(line.split` `)
  // var [a,b] = line.split` `
  // console.log( a ^ b )
})
.on('close', () => {
  values = values.slice(1)
  for( var val in values ){
    console.log(values[val][0] ^ values[val][1])
  }
})

var tc = parseInt(readline());
while(tc--){
    var A1 = readline().split(' ').map(x => parseInt(x));

    var n = A1[0];
    var m = A1[1];
    print(n ^ m);
}

var c = +readline() + 1;
for (var i = 1; i < c; i++) {
    var line = readline().split(" ");
    print(line[0] ^ line[1]);
}

var tc = parseInt(readline());
for(; tc--; ){
    var Ar = readline().split(' ').map(x => parseInt(x));
    var a = Ar[0], b = Ar[1];
    print(a ^ b);
}

//gets the x needed for smallest value
var findX = (a, b) => ((a + b) - (a ^ b)) / 2;

//note: I noticed the smallest value is the same as A and B varaibles xored
//computes the eqation
var result = (a, b, x) => (a ^ x) + (b ^ x);

function problem(a, b) {
    //same as a ^ b lol
    return result(a, b, findX(a, b));
}


You have a garland consisting of $$$n$$$ lamps. Each lamp is colored red, green or blue. The color of the $$$i$$$-th lamp is $$$s_i$$$ ('R', 'G' and 'B' — colors of lamps in the garland).You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse.A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $$$1$$$) have distinct colors.In other words, if the obtained garland is $$$t$$$ then for each $$$i$$$ from $$$1$$$ to $$$n-1$$$ the condition $$$t_i \ne t_{i + 1}$$$ should be satisfied.Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of lamps. The second line of the input contains the string $$$s$$$ consisting of $$$n$$$ characters 'R', 'G' and 'B' — colors of lamps in the garland.

In the first line of the output print one integer $$$r$$$ — the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $$$t$$$ of length $$$n$$$ — a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.

var cnt = 0;
var str = "";
var readliner = require('readline');
var rl = readliner.createInterface(process.stdin, process.stdout, null);
rl.on('line', function (cmd) {
                  //console.log('You just typed: '+cmd);
                  cnt++;
                  if (cnt > 1) str = cmd;
              }).on('close', main);

function next_CH(x) {
	if (x === 'R') return 'B';
	if (x === 'B') return 'G';
	if (x === 'G') return 'R';
}

function main() {
	var res = [];
	res.push(str[0]);
	var cnt = 0;
	for (var i=1; i<str.length; i++)
		if (str[i] !== res[i-1])
			res.push(str[i]);
		else {
			cnt++;
			if (i === str.length-1) res.push(next_CH(res[i-1]));
			else {
				var x = next_CH(res[i-1]); var Q = 0;
				while (x === str[i+1] && Q < 5) {
					if (x === 'R') x = 'B';
					else if (x === 'B') x = 'G';
					else if (x === 'G') x = 'R';
					Q++;
				}
				res.push(x);
			}
		}
	console.log(cnt);
	process.stdout.write(res.join(''));

    //console.log(ans);
    //console.log(Q);

    //var x = 1.2345678;
    //console.log('x = ',Number(x).toFixed(5));

    process.exit(0);
}

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

var cnt = 0;
var str = "";
var readliner = require('readline');
var rl = readliner.createInterface(process.stdin, process.stdout, null);
rl.on('line', function (cmd) {
                  //console.log('You just typed: '+cmd);
                  cnt++;
                  if (cnt > 1) str = cmd;
              }).on('close', main);

function next_CH(x) {
	if (x === 'R') return 'B';
	if (x === 'B') return 'G';
	if (x === 'G') return 'R';
}

function main() {
	var res = [];
	res.push(str[0]);
	var cnt = 0;
	var N = str.length;
	for (var i=1; i<N; i++)
		if (str[i] !== res[i-1])
			res.push(str[i]);
		else {
			cnt++;
			if (i === N-1) res.push(next_CH(res[i-1]));
			else {
				var x = next_CH(res[i-1]); var Q = 0;
				while (x === str[i+1] && Q < 5) {
					if (x === 'R') x = 'B';
					else if (x === 'B') x = 'G';
					else if (x === 'G') x = 'R';
					Q++;
				}
				res.push(x);
			}
		}
	console.log(cnt);
	process.stdout.write(res.join(''));

    //console.log(ans);
    //console.log(Q);

    //var x = 1.2345678;
    //console.log('x = ',Number(x).toFixed(5));

    process.exit(0);
};

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

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;i<t;++i){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=n(r(747));let s="",o=[],u=0,l="";const a="local"===process.argv[2],p=t=>{if(a){if(o=i.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),i.default.writeFileSync("output.txt",l),console.log(l),i.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{s+=t})),process.stdin.on("end",(e=>{o=s.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function f(){return o[u++]}function h(){return f().split(" ").map((t=>parseFloat(t)))}function c(){return f().split("")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextBigNumbers:function(){return f().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(h());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=h();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){a&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const i=n(r(312));i.default.runMain((function(){let[t]=i.default.nextNumbers(),e=i.default.nextCharacters(),r=["R","G","B"],n=0;for(let i=1;i<t;++i)if(e[i]==e[i-1])if(n++,i==t-1)"R"==e[i]?e[i]="B":e[i]="R";else{let t=e[i-1]+e[i+1];e[i]=r.find((e=>!t.includes(e)))}i.default.puts(n),i.default.puts(e.join(""))}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [n] = io.nextNumbers()
//   let s = io.nextCharacters()
//
//   let ss = ["R", "G", "B"]
//
//   let ch = 0
//
//   for (let i = 1; i < n; ++i) {
//     if (s[i] == s[i - 1]) {
//       ch++
//       if (i == n - 1) {
//         if (s[i] == "R") {
//           s[i] = "B"
//         } else {
//           s[i] = "R"
//         }
//       } else {
//         let b = s[i - 1] + s[i + 1]
//
//         s[i] = ss.find((x) => !b.includes(x))
//       }
//     }
//   }
//
//   io.puts(ch)
//   io.puts(s.join(""))
// }
//
// // io.runEachTest(main)
// io.runMain(main)

var x = parseInt(readline());

var seq = readline().split('');
var count=0;
for(var i=0; i<seq.length-1; i++){
  if(x===1) break;
  else{
    if(seq[i] === seq[i+1]){
      count++;
      if(x===2){
        if(seq[i]!=='R') seq[i+1]='R';
        else if(seq[i]!=='B') seq[i+1]='B';
        else seq[i+1]='G';
        break;
      }else{
        if(seq[i]!=='R' && seq[i+2]!=='R')
          seq[i+1]='R';
        else if(seq[i]!=='G' && seq[i+2]!=='G')
          seq[i+1]='G';
        else
          seq[i+1]='B';
      }
    }
  }
}

print(count);
print(seq.join(''));

var n = +readline();
var s = readline().split('');

var c = 0;

function getColor(l,r) {
    c++;
    return ['R','G','B'].filter(i => i != l && i != r)[0];
}

for(var i = 1; i < n; i++) {
    if(s[i] == s[i-1]) {
        s[i] = getColor(s[i-1], s[i+1]);
    }
}

print(c);
print(s.join(''));

function main(n,str){

      var cnt = 0;
      var s = [];
      var printer = '';

      for(var i = 0 ; i < n ; i++)s[i] = str[i];

      for(var i = 1 ; i < n ; i++){
        if(s[i] === s[i-1]){

          cnt++;

          if(s[i] === "R"){
            if(s[i+1] === "B"){
              s[i] = "G";
            }
            else if(s[i+1] === "G"){
              s[i] = "B";
            }
            else s[i] = 'B';
          }
          else if(s[i] === "G"){
            if(s[i+1] === "B"){
              s[i] = "R";
            }
            else if(s[i+1] === "R"){
              s[i] = "B";
            }
            else s[i] = "R";
          }
          else{
            if(s[i+1] === "R"){
              s[i] = "G";
            }
            else if(s[i+1] === "G"){
              s[i] = "R";
            }
            else s[i] = "R";
          }
        }
      }
      print(cnt);

      for(var i = 0 ; i < s.length ; i++)printer += s[i];

      print(printer);
}

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

//for(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);

main(n,str);

var n = +readline();
var s = readline().split('');
var min = 0;
var color = ['R', 'G', 'B'];
for (var i=1; i<n; i++){
	if (s[i] == s[i-1])	{
		min++;
		for (var j=0; j<3; j++){
			if (color[j] != s[i-1] && color[j] != s[i+1]) s[i] = color[j];
		}
	}
}
print (min);
print (s.join(''));

 readline(); var prm = readline().split("");
var mx =0;
var st = "";

for(var i=0;i<prm.length-1;i++)
if(prm[i]===prm[i+1]){
		mx++;
		var s = "RGB".replace(prm[i],"");
		if(prm.length - i >= 3){s = s.replace(prm[i+2],"")}
		   prm[i+1] = s[0];}

print(mx);
print(prm.join(""))

var x = readline();var prm = readline();

prm = prm.replace(/RR/g,"").replace(/GG/g,"").replace(/BB/g,"");
var st = "";
var mx = (x - prm.length )/2
if(mx>0){
 for(var i=0;i<x;i+=2){st+="RG"}
if(prm.length%2!=0){st =st.slice(0,st.length-1)}
}else{st=prm}

print(mx);print(st);

		readline();var input = readline().split("");var maxx =0;var st = "";
for(var i=0;i<input.length-1;i++){
	if(input[i]===input[i+1]){
		maxx++;
		var s = "RGB".replace(input[i],"")
		if(i>0){s = s.replace(input[i-1],"")}
			input[1+i]=s[0];
	}
}

print(maxx);print(input);


Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab.After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has h2 health points and an attack power of a2. Knowing that, Vova has decided to buy a lot of strong healing potions and to prepare for battle.Vova's character has h1 health points and an attack power of a1. Also he has a large supply of healing potions, each of which increases his current amount of health points by c1 when Vova drinks a potion. All potions are identical to each other. It is guaranteed that c1 > a2.The battle consists of multiple phases. In the beginning of each phase, Vova can either attack the monster (thus reducing its health by a1) or drink a healing potion (it increases Vova's health by c1; Vova's health can exceed h1). Then, if the battle is not over yet, the Modcrab attacks Vova, reducing his health by a2. The battle ends when Vova's (or Modcrab's) health drops to 0 or lower. It is possible that the battle ends in a middle of a phase after Vova's attack.Of course, Vova wants to win the fight. But also he wants to do it as fast as possible. So he wants to make up a strategy that will allow him to win the fight after the minimum possible number of phases.Help Vova to make up a strategy! You may assume that Vova never runs out of healing potions, and that he can always win.

The first line contains three integers h1, a1, c1 (1 ≤ h1, a1 ≤ 100, 2 ≤ c1 ≤ 100) — Vova's health, Vova's attack power and the healing power of a potion. The second line contains two integers h2, a2 (1 ≤ h2 ≤ 100, 1 ≤ a2 < c1) — the Modcrab's health and his attack power.

In the first line print one integer n denoting the minimum number of phases required to win the battle. Then print n lines. i-th line must be equal to HEAL if Vova drinks a potion in i-th phase, or STRIKE if he attacks the Modcrab. The strategy must be valid: Vova's character must not be defeated before slaying the Modcrab, and the monster's health must be 0 or lower after Vova's last action. If there are multiple optimal solutions, print any of them.

NoteIn the first example Vova's character must heal before or after his first attack. Otherwise his health will drop to zero in 2 phases while he needs 3 strikes to win.In the second example no healing needed, two strikes are enough to get monster to zero health and win with 6 health left.

A=readline().split(' ').map(Number)
B=readline().split(' ').map(Number)
h1=A[0],a1=A[1],c1=A[2]
h2=B[0],a2=B[1]
T=[]
while (h2 > 0) {
 if (a1 >= h2) {
  T.push('STRIKE')
  h2 -= a1
 } else if (h1 > a2) {
  T.push('STRIKE')
  h1 -= a2
  h2 -= a1
 } else {
  T.push('HEAL')
  h1 = h1 - a2 + c1
 }
}

print(T.length)
print(T.join('\n'))

A=readline().split(' ').map(Number)
B=readline().split(' ').map(Number)
h1=A[0],a1=A[1],c1=A[2]
h2=B[0],a2=B[1]
T=[]
while (h2 > 0) {
 if (a1 >= h2) {
  h2 -= a1
 } else if (h1 > a2) {
  T.push('STRIKE')
  h1 -= a2
  h2 -= a1
 } else {
  T.push('HEAL')
  h1 = h1 - a2 + c1
 }
}

print(T.length)
print(T.join('\n'))

A=readline().split(' ').map(Number)
B=readline().split(' ').map(Number)
h1=A[0],a1=A[1],c1=A[2]
h2=B[0],a2=B[1]
T=[]
while (h2 > 0) {
 if (h1 > a2) {
  T.push('STRIKE')
  h1 -= a2
  h2 -= a1
 } else {
  T.push('HEAL')
  h1 = h1 - a2 + c1
 }
}

print(T.length)
print(T.join('\n'))


You are given an array $$$a_1, a_2, \dots, a_n$$$. You can perform operations on the array. In each operation you can choose an integer $$$i$$$ ($$$1 \le i < n$$$), and swap elements $$$a_i$$$ and $$$a_{i+1}$$$ of the array, if $$$a_i + a_{i+1}$$$ is odd.Determine whether it can be sorted in non-decreasing order using this operation any number of times.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print "Yes" or "No" depending on whether you can or can not sort the given array. You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).

NoteIn the first test case, we can simply swap $$$31$$$ and $$$14$$$ ($$$31 + 14 = 45$$$ which is odd) and obtain the non-decreasing array $$$[1,6,14,31]$$$.In the second test case, the only way we could sort the array is by swapping $$$4$$$ and $$$2$$$, but this is impossible, since their sum $$$4 + 2 = 6$$$ is even.In the third test case, there is no way to make the array non-decreasing.In the fourth test case, the array is already non-decreasing.

"use strict";

//let startTime = Date.now();

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

let inputString = "";
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const numOfTests = +(readline());

    for (let i=0; i<numOfTests; i++){
        const lengthOfArr = +(readline());
        let arr = readline().split(" ").map((string) => {
            return +(string);
        });

        let swappable = true;
        let highestOddNumber = 1;
        let highestEvenNumber = 2;

        for (let j=0; j<lengthOfArr-1; j++) {
            let a = arr[j];
            let b = arr[j+1];

            if (a % 2 === 0) {
                if (a > highestEvenNumber)
                    highestEvenNumber = a;
            }
            else {
                if (a > highestOddNumber)
                highestOddNumber = a;
            }

            if (b % 2 === 0) {
                if (b < highestEvenNumber) {
                    swappable = false;
                    break;
                }
            }
            else {
                if (b < highestOddNumber) {
                    swappable = false;
                    break;
                }
            }
        }

        console.log(swappable ? "YES" : "NO");
    }

//    console.log(Date.now() - startTime + " ms");
}

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  const tests_count = parseInt(readline());
  for (var test = 0; test < tests_count; test++) {
    const n = parseInt(readline());
    const numbers = readline().split(" ").filter(s => s.trim().length !== 0).map(s => parseInt(s.trim()));
    console.log(canBeSorted(numbers) ? "Yes" : "No");
  }
}

function canBeSorted(items) {
  let maxEven = 0;
  let maxOdd = 0;
  for (let i = 0; i < items.length; i++)
    if (items[i] % 2 == 0)
      if (items[i] < maxEven)
        return false;
      else
        maxEven = items[i];
    else
      if (items[i] < maxOdd)
        return false;
      else
        maxOdd = items[i]

  return true;
}

"use strict";

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

let inputString = "";
let currentLine = 0;

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

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

	main();
});

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

function main() {
	const testCount = +readline();

	for (let j = 0; j < testCount; j++) {
		let arrayLength = +readline();
		let array = readline()
			.split(" ")
			.map((e) => +e);

		let possible = true;
		let biggestOdd = 0;
		let biggestEven = 0;
		let i = 0;
		while (i < array.length) {
			const a = array[i];

			if (a % 2) {
				if (a < biggestOdd) {
					possible = false;
					break;
				}
				biggestOdd = a > biggestOdd ? a : biggestOdd;
			} else {
				if (a < biggestEven) {
					possible = false;
					break;
				}
				biggestEven = a > biggestEven ? a : biggestEven;
			}

			i++;
		}

		console.log(possible ? "yes" : "no");
	}
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            n = lines[i];
        }else{
            var a = lines[i].split(' ').map(Number);
            var max = [0, 0];
            var flag = 0;
            for(j = 0; j < n; j++){
                var k = Math.floor(a[j] % 2);
                if(max[k] > a[j]){
                    flag = 1;
                    break;
                }
                max[k] = Math.max(max[k], a[j]);
            }
            console.log(flag == 1 ? 'NO' : 'YES');
        }
    }
});

'use strict';

function solve(n, a) {
  let po = -1,
      pe = -1;
  for (let i = 0; i < n; i++) {
    if (a[i] & 1) {
      if (a[i] < po) return 'NO';
      po = a[i];
    } else {
      if (a[i] < pe) return 'NO';
      pe = a[i];
    }
  }
  return 'YES';
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      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);
});

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

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

const calc = (n, A)=>{
  let odd = [];
  let even = []
  for (let a of A){
    if (a&1) odd.push(a); else even.push(a);
  }
  for (let i=0; i<odd.length-1; i++)
    if (odd[i]>odd[i+1])
      return false;
  for (let i=0; i<even.length-1; i++)
    if (even[i]>even[i+1])
      return false;
    return true;
};

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

E.calc = calc;

const readline = require('readline');

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

const it = rl[Symbol.asyncIterator]();

const main = async () => {
    const use_cases = await it.next();
    let t = use_cases.value;
    while(t--)
    {
        const n = Number((await it.next()).value);
        let arr = (await it.next()).value.split(' ').map( x => Number(x));
        let even_arr = [];
        let odd_arr = [];
        arr.forEach(element => {
            element%2 === 0 ? even_arr.push(element) : odd_arr.push(element)
        });
        let flag = false;
        let even_arr_length = even_arr.length;
        let odd_arr_length = odd_arr.length;
        let prev_even = even_arr_length > 0 && even_arr[0];
        let prev_odd = odd_arr_length > 0 && odd_arr[0];
        for(let i=1; i<even_arr_length;i++)
        {
            if(prev_even > even_arr[i])
            {
                flag = true;
                break;
            }
            prev_even = even_arr[i];
        }
        if(!flag)
        {
            for(let i=1; i<odd_arr_length;i++)
            {
                if(prev_odd > odd_arr[i])
                {
                    flag = true;
                    break;
                }
                prev_odd = odd_arr[i];
            }
        }
        console.log(flag===false ? 'Yes': 'No');
    }

}
main();

var tests = parseInt(readline());

for (var i = 0; i < tests; i++) {
  var n = parseInt(readline());
  var arr = readline()
    .split(" ")
    .map((i) => parseInt(i));

  var odd = null;
  var even = null;
  var posible = true;
  for (var j = 0; j < arr.length; j++) {
    if (arr[j] % 2 == 0) {
      if (even == null) even = arr[j];
      else {
        if (even > arr[j]) {
          posible = false;
          break;
        } else {
          even = arr[j];
        }
      }
    } else {
      if (odd == null) odd = arr[j];
      else {
        if (odd > arr[j]) {
          posible = false;
          break;
        } else {
          odd = arr[j];
        }
      }
    }
  }
  print(posible ? "Yes" : "No");
}

"use strict";

//let startTime = Date.now();

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

let inputString = "";
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const numOfTests = +(readline());

    for (let i=0; i<numOfTests; i++){
        const lengthOfArr = +(readline());
        let arr = readline().split(" ").map((string) => {
            return +(string);
        });

        let swappable = true;
        let highestOddNumber = 1;
        let highestEvenNumber = 2;

        for (let j=0; j<lengthOfArr-1; j++) {
            let a = arr[j];
            let b = arr[j+1];

            if (a % 2 === 0) {
                if (a > highestEvenNumber)
                    highestEvenNumber = a;
            }
            else {
                if (a > highestOddNumber)
                highestOddNumber = a;
            }

            if (a > b) {
                if ((a + b) % 2 === 0) {
                    swappable = false;
                    break;
                }

                if (b % 2 === 0) {
                    if (b < highestEvenNumber) {
                        swappable = false;
                        break;
                    }
                    else if (b > highestEvenNumber)
                        highestEvenNumber = b;
                }
                else {
                    if (b < highestOddNumber) {
                        swappable = false;
                        break;
                    }
                    else if (b > highestOddNumber)
                        highestOddNumber = b;
                }
            }
        }

        console.log(swappable ? "YES" : "NO");
    }

//    console.log(Date.now() - startTime + " ms");
}

"use strict";

//let startTime = Date.now();

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

let inputString = "";
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const numOfTests = +(readline());

    for (let i=0; i<numOfTests; i++){
        const lengthOfArr = +(readline());
        let arr = readline().split(" ").map((string) => {
            return +(string);
        });

        let swappable = true;
        let highestOddNumber = 1;

        for (let a=0; a<lengthOfArr-1; a++) {
            if (arr[a] > arr[a+1]) {
                if ((arr[a] + arr[a+1]) % 2 === 0) {
                    swappable = false;
                    break;
                }

                if (arr[a+1] % 2 !== 0) {
                    if (arr[a+1] < highestOddNumber) {
                        swappable = false;
                        break;
                    }
                    else if (arr[a+1] > highestOddNumber) {
                        highestOddNumber = arr[a+1];
                    }
                }

                const temp = arr[a];
                arr[a] = arr[a+1];
                arr[a+1] = temp;
            }
        }

        console.log(swappable ? "YES" : "NO");
    }

//    console.log(Date.now() - startTime + " ms");
}

"use strict";

//let startTime = Date.now();

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

let inputString = "";
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const numOfTests = +(readline());

    for (let i=0; i<numOfTests; i++){
        const lengthOfArr = +(readline());
        let arr = readline().split(" ").map((string) => {
            return +(string);
        });

        let swappable = true;
        let highestOddNumber = 1;

        for (let a=0; a<lengthOfArr-1; a++) {
            if (arr[a] > arr[a+1]) {
                if ((arr[a] + arr[a+1]) % 2 === 0) {
                    swappable = false;
                    break;
                }

                if (arr[a+1] % 2 !== 0) {
                    if (arr[a+1] > highestOddNumber) {
                        swappable = false;
                        break;
                    }
                    else if (arr[a+1] > highestOddNumber) {
                        highestOddNumber = arr[a+1];
                    }
                }

                const temp = arr[a];
                arr[a] = arr[a+1];
                arr[a+1] = temp;
            }
        }

        console.log(swappable ? "YES" : "NO");
    }

//    console.log(Date.now() - startTime + " ms");
}

"use strict";

//let startTime = Date.now();

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

let inputString = "";
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const numOfTests = +(readline());

    for (let i=0; i<numOfTests; i++){
        const lengthOfArr = +(readline());
        let arr = readline().split(" ").map((string) => {
            return +(string);
        });

        let swappable = true;
        let highestOddNumber = null;

        for (let a=0; a<lengthOfArr-1; a++) {
            if (arr[a] % 2 !== 0 && (arr[a] > highestOddNumber || highestOddNumber === null))
                highestOddNumber = arr[a];

            if (arr[a+1] % 2 !== 0 && arr[a+1] < highestOddNumber && highestOddNumber !== null) {
                swappable = false;
                break;
            }

            if (arr[a] > arr[a+1]) {
                if ((arr[a] + arr[a+1]) % 2 === 0) {
                    swappable = false;
                    break;
                }
                const temp = arr[a];
                arr[a] = arr[a+1];
                arr[a+1] = temp;
            }
        }

        console.log(swappable ? "YES" : "NO");
    }

//    console.log(Date.now() - startTime + " ms");
}

"use strict";

//let startTime = Date.now();

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

let inputString = "";
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const numOfTests = +(readline());

    for (let i=0; i<numOfTests; i++){
        const lengthOfArr = +(readline());
        let arr = readline().split(" ").map((string) => {
            return +(string);
        });

        let swappable = true;
        let highestOddNumber = 1;

        for (let a=0; a<lengthOfArr-1; a++) {
            if (arr[a] % 2 !== 0 && arr[a] > highestOddNumber)
                highestOddNumber = arr[a];

            if (arr[a+1] % 2 !== 0 && arr[a+1] < highestOddNumber) {
                swappable = false;
                break;
            }

            if (arr[a] > arr[a+1]) {
                if ((arr[a] + arr[a+1]) % 2 === 0) {
                    swappable = false;
                    break;
                }
                const temp = arr[a];
                arr[a] = arr[a+1];
                arr[a+1] = temp;
            }
        }

        console.log(swappable ? "YES" : "NO");
    }

//    console.log(Date.now() - startTime + " ms");
}

"use strict";

//let startTime = Date.now();

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

let inputString = "";
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const numOfTests = +(readline());

    for (let i=0; i<numOfTests; i++){
        const lengthOfArr = +(readline());
        let arr = readline().split(" ").map((string) => {
            return +(string);
        });

        let swappable = true;
        let highestOddNumber = 1;

        for (let a=0; a<lengthOfArr-1; a++) {
            if (arr[a] % 2 !== 0 && arr[a] > highestOddNumber)
                highestOddNumber = arr[a];

            if (arr[a] > arr[a+1] && (arr[a] + arr[a+1]) % 2 === 0) {
                swappable = false;
                break;
            }

            if (arr[a+1] % 2 !== 0 && arr[a+1] < highestOddNumber) {
                swappable = false;
                break;
            }
        }

        console.log(swappable ? "YES" : "NO");
    }

//    console.log(Date.now() - startTime + " ms");
}

const solve = (n,arr)=>{
     let obj = {};
     for(let i=0;i<n;i++) obj[arr[i]] = i;
     let res  = [...arr];
     res.sort((a,b)=>a-b);
     for(let i=0;i<n;i++){
          if(arr[i]!==res[i]){
               if((arr[i]+res[i])%2){
                    let j = obj[res[i]];
                    [arr[i],arr[j]] = [arr[j],arr[i]];
               }
               else return "NO";
          }
     }
     return "YES";
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       console.log(solve(n,arr));
  }
}
main();

const solve = (n,arr)=>{
     let res  = [...arr];
     res.sort((a,b)=>a-b);
     for(let i=0;i<n;i++){
          if(arr[i]!==res[i]){
               if((arr[i]+res[i])%2===0) return "NO";
          }
     }
     return "YES";
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       console.log(solve(n,arr));
  }
}
main();

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


Tired of boring office work, Denis decided to open a fast food restaurant.On the first day he made $$$a$$$ portions of dumplings, $$$b$$$ portions of cranberry juice and $$$c$$$ pancakes with condensed milk.The peculiarity of Denis's restaurant is the procedure of ordering food. For each visitor Denis himself chooses a set of dishes that this visitor will receive. When doing so, Denis is guided by the following rules:  every visitor should receive at least one dish (dumplings, cranberry juice, pancakes with condensed milk are all considered to be dishes);  each visitor should receive no more than one portion of dumplings, no more than one portion of cranberry juice and no more than one pancake with condensed milk;  all visitors should receive different sets of dishes. What is the maximum number of visitors Denis can feed?

The first line contains an integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases to solve. Each of the remaining $$$t$$$ lines contains integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$0 \leq a, b, c \leq 10$$$) — the number of portions of dumplings, the number of portions of cranberry juice and the number of condensed milk pancakes Denis made.

For each test case print a single integer — the maximum number of visitors Denis can feed.

NoteIn the first test case of the example, Denis can feed the first visitor with dumplings, give the second a portion of cranberry juice, and give the third visitor a portion of cranberry juice and a pancake with a condensed milk.In the second test case of the example, the restaurant Denis is not very promising: he can serve no customers.In the third test case of the example, Denise can serve four visitors. The first guest will receive a full lunch of dumplings, a portion of cranberry juice and a pancake with condensed milk. The second visitor will get only dumplings. The third guest will receive a pancake with condensed milk, and the fourth guest will receive a pancake and a portion of dumplings. Please note that Denis hasn't used all of the prepared products, but is unable to serve more visitors.

const getCounts = arr => {
  let result = 0;

  // Find counts {1}
  arr = arr.map(x => {
    if (x > 0) {
      result++;
      return --x;
    }
    return x;
  })

  // Find counts {2}
  arr = arr.sort((a, b) => b - a);

  for(let i = 0; i < arr.length-1; i++) {
    for(let j = i + 1; j < arr.length; j++) {
      if (arr[i] > 0 && arr[j] > 0) {
        arr[i]--;
        arr[j]--;
        result++;
      }
    }
  }

  // Find counts {3}
  if (arr.every(x => x > 0)) {
    result++;
  }

  console.log(result);
}

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

  for(let i = 1; i <= n; i++) {
    getCounts(data[i].split(' ').map(x => +x));
  }
}

let data = '';

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

  main(data);
});

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

    function foo (data) {
        data.sort((a, b) => b - a);
        let count = 0;

        data.forEach((value, index, arr )=> {
            if (arr[index]) {
                arr[index] = --arr[index];
                count++;
            }
        });

        data.forEach((value, index, arr )=> {
            if (arr[index] && arr[index + 1] || index === arr.length - 1 && arr[index] && arr[0]) {
                arr[index] = --arr[index];
                arr[index + 1] = --arr[index + 1];
                count++;
            }
        });

        if (data[0] && data[1] && data[2]) {
            count++
        }

        return count;
    }

    let testCount = 1;
    let answer = '';
    while(testCount <= +lines[0]) {
        let data = lines[testCount].split(" ").map(Number);

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

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

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

  const arr = d.split(' ').map(Number);
  arr.sort((a, b) => a - b);
  let [a, b, c] = arr;
  let ans = 0;

  for (let i = 1; i < 2**3; i++) {
    const [a1, b1, c1] = [...i.toString(2).padStart(3, 0)].map(Number);

    if (a - a1 > -1 && b - b1 > -1 && c - c1 > -1) {
      a -= a1;
      b -= b1;
      c -= c1;
      ans++;
    }
  }

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

'use strict';

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

const lines = [];
let nextLine = 0;
rl.on('line', (line) => {
  lines.push(line);
});

rl.on('close', () => {
  main();
});

function readline() {
  return lines[nextLine++];
}

function solve(arr) {
  arr.sort((a,b) => b - a);
  const menus = Array(8).fill(0);
  // 1 kind
  for(let i = 0, bit = 1; i < 3; i++, bit <<= 1) {
    if (arr[i] > 0 && menus[bit] === 0) {
      arr[i]--;
      menus[bit] = 1;
    }
  }
  // 2 kinds
  for(let i = 0, bit1 = 1; i < 2; i++, bit1 <<= 1) {
    for (let j = i + 1; j < 3; j++) {
      const bit2 = 1 << j;
      const bit = bit1 | bit2;
      if (arr[i] > 0 && arr[j] > 0 && menus[bit] === 0) {
        arr[i]--;
        arr[j]--;
        menus[bit] = 1;
      }
    }
  }
  // 3 kinds
  if (arr[0] > 0 && arr[1] > 0 && arr[2] > 0) {
    menus[7] = 1;
    arr[0]--;
    arr[1]--;
    arr[2]--;
  }
  // console.error({arr, menus});
  return menus.reduce((a,b) => a + b);
}

function main() {
  const t = parseInt(readline());
  // console.log({t});
  for(let i = 0; i < t; i++) {
    const arr = readline().split(' ').map(Number);
    const res = solve(arr);
    console.log(res);
  }
}

var opts = [
[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
[1, 1, 0],
[1, 0, 1],
[0, 1, 1],
[1, 1, 1]
]

function processItem() {
    var items = readline().split(' ').map(function(i) { return +i; });
    var peopleCount = 0;

    items.sort(function(a, b) { return b - a; });

    for (var j = 0; j < opts.length; j++) {
        var opt = opts[j];

        if (items[0] === 0 && items[1] === 0 && items[2] === 0) {
            break;
        }

        var temp1 = items[0] - opt[0];
        var temp2 = items[1] - opt[1];
        var temp3 = items[2] - opt[2];

        if (temp1 >= 0 && temp2 >= 0 && temp3 >= 0) {
            peopleCount++;
            items = [temp1, temp2, temp3];
        }
    }

    print(peopleCount);
}

function processItems() {
  var itemsCount = +readline();
  var items = [];

  for (var i = 0; i < itemsCount; ++i) {
    processItem();
  }

  return items;
}

processItems();

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 t = myconv(next(),1);
    var output = new Array(t);
    for(var i = 0; i < t; i++){
        var tmp = myconv(next(),4).sort(function(a,b){
            return b - a;
        });
        var a = tmp[0];
        var b = tmp[1];
        var c = tmp[2];
        var add = 0;
        if(a > 0){
            a--;
            add++;
        }
        if(b > 0){
            b--;
            add++;
        }
        if(c > 0){
            c--;
            add++;
        }
        if(a > 0 && b > 0){
            a--;
            b--;
            add++;
        }
        if(a > 0 && c > 0){
            a--;
            c--;
            add++;
        }
        if(c > 0 && b > 0){
            c--;
            b--;
            add++;
        }
        if(a > 0 && b > 0 && c > 0){
            a--;
            b--;
            c--;
            add++;
        }
        output[i] = add;
    }
    myout(myconv(output,9));
}

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

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

  let [a, b, c] = d.split(' ').map(Number);
  let ans = 0;
  let max = Math.max(a, b, c);

  for (let i = 1; i < 2**3; i++) {
    const [a1, b1, c1] = [...i.toString(2).padStart(3, 0)].map(Number);

    if (a - a1 > -1 && b - b1 > -1 && c - c1 > -1) {
      a -= a1;
      b -= b1;
      c -= c1;
      ans++;
    }
  }

  if (Math.max(a, b, c) === 2 && max !== 3) {
    ans++;
  }

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

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

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

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

  for (let i = 1; i < 2**3; i++) {
    const [a1, b1, c1] = [...i.toString(2).padStart(3, 0)].map(Number);

    if (a - a1 > -1 && b - b1 > -1 && c - c1 > -1) {
      a -= a1;
      b -= b1;
      c -= c1;
      ans++;
    }
  }

  if (Math.max(a, b, c) === 2) {
    ans++;
  }

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

var opts = [
[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
[1, 1, 0],
[1, 0, 1],
[0, 1, 1],
[1, 1, 1]
]

function processItem() {
    var items = readline().split(' ').map(function(i) { return +i; });
    var peopleCount = 0;

    for (var j = 0; j < opts.length; j++) {
        var opt = opts[j];

        if (items[0] === 0 && items[1] === 0 && items[2] === 0) {
            break;
        }

        var temp1 = items[0] - opt[0];
        var temp2 = items[1] - opt[1];
        var temp3 = items[2] - opt[2];

        if (temp1 >= 0 && temp2 >= 0 && temp3 >= 0) {
            peopleCount++;
            items = [temp1, temp2, temp3];
        }
    }

    print(peopleCount);
}

function processItems() {
  var itemsCount = +readline();
  var items = [];

  for (var i = 0; i < itemsCount; ++i) {
    processItem();
  }

  return items;
}

processItems();


Oleg's favorite subjects are History and Math, and his favorite branch of mathematics is division.To improve his division skills, Oleg came up with $$$t$$$ pairs of integers $$$p_i$$$ and $$$q_i$$$ and for each pair decided to find the greatest integer $$$x_i$$$, such that:   $$$p_i$$$ is divisible by $$$x_i$$$;  $$$x_i$$$ is not divisible by $$$q_i$$$.  Oleg is really good at division and managed to find all the answers quickly, how about you?

The first line contains an integer $$$t$$$ ($$$1 \le t \le 50$$$) — the number of pairs. Each of the following $$$t$$$ lines contains two integers $$$p_i$$$ and $$$q_i$$$ ($$$1 \le p_i \le 10^{18}$$$; $$$2 \le q_i \le 10^{9}$$$) — the $$$i$$$-th pair of integers.

Print $$$t$$$ integers: the $$$i$$$-th integer is the largest $$$x_i$$$ such that $$$p_i$$$ is divisible by $$$x_i$$$, but $$$x_i$$$ is not divisible by $$$q_i$$$. One can show that there is always at least one value of $$$x_i$$$ satisfying the divisibility conditions for the given constraints.

NoteFor the first pair, where $$$p_1 = 10$$$ and $$$q_1 = 4$$$, the answer is $$$x_1 = 10$$$, since it is the greatest divisor of $$$10$$$ and $$$10$$$ is not divisible by $$$4$$$.For the second pair, where $$$p_2 = 12$$$ and $$$q_2 = 6$$$, note that   $$$12$$$ is not a valid $$$x_2$$$, since $$$12$$$ is divisible by $$$q_2 = 6$$$;  $$$6$$$ is not valid $$$x_2$$$ as well: $$$6$$$ is also divisible by $$$q_2 = 6$$$.  The next available divisor of $$$p_2 = 12$$$ is $$$4$$$, which is the answer, since $$$4$$$ is not divisible by $$$6$$$.

let input = ''

process.stdin.on('data', (x) => input += x)

process.stdin.on('end', () => {
  const check = (f, d, p) => {
    let cand = p
    while (cand % d === 0n) {
      cand /= d
    }
    cand *= f / d

    return cand
  }

  input.trim().split('\n').slice(1).forEach((line) => {
    let [p, q] = line.split(' ').map((x) => BigInt(x))
    if (p % q === 0n) {
      let ans = 1n
      for (let d = 2n; d * d <= q; d++) {
        if (q % d === 0n) {
          let f = 1n
          do {
            q /= d
            f *= d
          } while (q % d === 0n);

          const cand = check(f, d, p)
          if (cand > ans) {
            ans = cand
          }
        }
      }
      if (q > 1n) {
        const cand = check(q, q, p)
        if (cand > ans) {
          ans = cand
        }
      }

      console.log(ans.toString())
    } else {
      console.log(p.toString())
    }
  })
})

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;i<t;++i){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=n(r(747));let o="",s=[],u=0,l="";const f="local"===process.argv[2],p=t=>{if(f){if(s=i.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),i.default.writeFileSync("output.txt",l),console.log(l),i.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{o+=t})),process.stdin.on("end",(e=>{s=o.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function a(){return s[u++]}function h(){return a().split(" ").map((t=>parseFloat(t)))}function c(){return a().split("")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:a,nextNumbers:h,nextBigNumbers:function(){return a().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(h());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=h();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){f&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const i=n(r(312));function o(t,e){return t>e?t:e}i.default.runEachTest((function(){let[t,e]=i.default.nextBigNumbers();if(t%e!=0n)return void i.default.puts(t);let r=t,n=1n,s=!1;for(let i=2n;i*i<=e;++i)if(e%i==0n){for(s=!0,t=r;t%e==0n;)t/=i;for(n=o(n,t),t=r;t%e==0n;)t/=e/i;n=o(n,t)}if(t=r,!s){for(;t%e==0n;)t/=e;n=o(n,t)}i.default.puts(n)}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function bigMax(x: bigint, y: bigint) {
//   return x > y ? x : y
// }
//
// function main() {
//   let [p, q] = io.nextBigNumbers()
//
//   if (p % q != 0n) {
//     io.puts(p)
//     return
//   }
//
//   let po = p
//
//   let best = 1n
//
//   let hasDiv = false
//
//   for (let i = 2n; i * i <= q; ++i) {
//     if (q % i != 0n) {
//       continue
//     }
//
//     hasDiv = true
//
//     p = po
//
//     while (p % q == 0n) {
//       p /= i
//     }
//
//     best = bigMax(best, p)
//
//     p = po
//
//     while (p % q == 0n) {
//       p /= q / i
//     }
//
//     best = bigMax(best, p)
//   }
//
//   p = po
//
//   if (!hasDiv) {
//     while (p % q == 0n) {
//       p /= q
//     }
//
//     best = bigMax(best, p)
//   }
//
//   io.puts(best)
// }
//
// io.runEachTest(main)
// // io.runMain(main)

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;i<t;++i){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=n(r(747));let o="",s=[],u=0,l="";const a="local"===process.argv[2],h=t=>{if(a){if(s=i.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),i.default.writeFileSync("output.txt",l),console.log(l),i.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{o+=t})),process.stdin.on("end",(e=>{s=o.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[u++]}function p(){return f().split(" ").map((t=>parseFloat(t)))}function c(){return f().split("")}e.default={runMain:h,runEachTest:t=>{h((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:f,nextNumbers:p,nextBigNumbers:function(){return f().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(p());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=p();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){a&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const i=n(r(312));i.default.runEachTest((function(){let[t,e]=i.default.nextNumbers();if(t%e!=0)return void i.default.puts(t);let r=t,n=1,o=!1;for(let i=2;i<=Math.sqrt(e);++i)if(e%i==0){for(o=!0,t=r;t%e==0;)t/=i;for(n=Math.max(n,t),t=r;t%e==0;)t/=e/i;n=Math.max(n,t)}if(t=r,!o){for(;t%e==0;)t/=e;n=Math.max(n,t)}i.default.puts(n)}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [p, q] = io.nextNumbers()
//
//   if (p % q != 0) {
//     io.puts(p)
//     return
//   }
//
//   let po = p
//
//   let best = 1
//
//   let hasDiv = false
//
//   for (let i = 2; i <= Math.sqrt(q); ++i) {
//     if (q % i != 0) {
//       continue
//     }
//
//     hasDiv = true
//
//     p = po
//
//     while (p % q == 0) {
//       p /= i
//     }
//
//     best = Math.max(best, p)
//
//     p = po
//
//     while (p % q == 0) {
//       p /= q / i
//     }
//
//     best = Math.max(best, p)
//   }
//
//   p = po
//
//   if (!hasDiv) {
//     while (p % q == 0) {
//       p /= q
//     }
//
//     best = Math.max(best, p)
//   }
//
//   io.puts(best)
// }
//
// io.runEachTest(main)
// // io.runMain(main)


You are given a garland consisting of $$$n$$$ lamps. States of the lamps are represented by the string $$$s$$$ of length $$$n$$$. The $$$i$$$-th character of the string $$$s_i$$$ equals '0' if the $$$i$$$-th lamp is turned off or '1' if the $$$i$$$-th lamp is turned on. You are also given a positive integer $$$k$$$.In one move, you can choose one lamp and change its state (i.e. turn it on if it is turned off and vice versa).The garland is called $$$k$$$-periodic if the distance between each pair of adjacent turned on lamps is exactly $$$k$$$. Consider the case $$$k=3$$$. Then garlands "00010010", "1001001", "00010" and "0" are good but garlands "00101001", "1000001" and "01001100" are not. Note that the garland is not cyclic, i.e. the first turned on lamp is not going after the last turned on lamp and vice versa.Your task is to find the minimum number of moves you need to make to obtain $$$k$$$-periodic garland from the given one.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 25~ 000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^6; 1 \le k \le n$$$) — the length of $$$s$$$ and the required period. The second line of the test case contains the string $$$s$$$ consisting of $$$n$$$ characters '0' and '1'. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$ ($$$\sum n \le 10^6$$$).

For each test case, print the answer — the minimum number of moves you need to make to obtain $$$k$$$-periodic garland from the given one.

var t = Number(readline());
while(t--) {
    var v = readline().split(" ");
    var n = Number(v[0]), k = Number(v[1]);

    v = "0"+readline();

    var dp = [0], cum = [0];
    for(var i = 1; i <= n; i++) {
        cum[i] = cum[i-1];
        if(v[i] === "1") cum[i]++;
    }

    var ans = cum[n];
    for(var i = 1; i <= n; i++) {
        dp[i] = 0;
        if(v[i] === "0") dp[i]++;

        var x = cum[i-1];
        if(i > k) x = Math.min(x, dp[i-k]+cum[i-1]-cum[i-k]);

        dp[i] += x;
    }

    for(var i = 1; i <= n; i++) {
        ans = Math.min(ans, dp[i]+cum[n]-cum[i]);
    }

    print(ans);
}


Polycarp wrote on a whiteboard an array $$$p$$$ of length $$$n$$$, which is a permutation of numbers from $$$1$$$ to $$$n$$$. In other words, in $$$p$$$ each number from $$$1$$$ to $$$n$$$ occurs exactly once.He also prepared a resulting array $$$a$$$, which is initially empty (that is, it has a length of $$$0$$$).After that, he did exactly $$$n$$$ steps. Each step looked like this:  Look at the leftmost and rightmost elements of $$$p$$$, and pick the smaller of the two. If you picked the leftmost element of $$$p$$$, append it to the left of $$$a$$$; otherwise, if you picked the rightmost element of $$$p$$$, append it to the right of $$$a$$$. The picked element is erased from $$$p$$$. Note that on the last step, $$$p$$$ has a length of $$$1$$$ and its minimum element is both leftmost and rightmost. In this case, Polycarp can choose what role the minimum element plays. In other words, this element can be added to $$$a$$$ both on the left and on the right (at the discretion of Polycarp).Let's look at an example. Let $$$n=4$$$, $$$p=[3, 1, 4, 2]$$$. Initially $$$a=[]$$$. Then: During the first step, the minimum is on the right (with a value of $$$2$$$), so after this step, $$$p=[3,1,4]$$$ and $$$a=[2]$$$ (he added the value $$$2$$$ to the right).  During the second step, the minimum is on the left (with a value of $$$3$$$), so after this step, $$$p=[1,4]$$$ and $$$a=[3,2]$$$ (he added the value $$$3$$$ to the left).  During the third step, the minimum is on the left (with a value of $$$1$$$), so after this step, $$$p=[4]$$$ and $$$a=[1,3,2]$$$ (he added the value $$$1$$$ to the left).  During the fourth step, the minimum is both left and right (this value is $$$4$$$). Let's say Polycarp chose the right option. After this step, $$$p=[]$$$ and $$$a=[1,3,2,4]$$$ (he added the value $$$4$$$ to the right).Thus, a possible value of $$$a$$$ after $$$n$$$ steps could be $$$a=[1,3,2,4]$$$.You are given the final value of the resulting array $$$a$$$. Find any possible initial value for $$$p$$$ that can result the given $$$a$$$, or determine that there is no solution.

The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. Each test case consists of two lines. The first of them contains an integer $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — the length of the array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array $$$a$$$. All elements of the $$$a$$$ array are distinct numbers. It is guaranteed that the sum of the values $$$n$$$ over all test cases in the test does not exceed $$$2\cdot10^5$$$.

Print $$$t$$$ lines, each of the lines must contain the answer to the corresponding set of input data: numbers $$$p_1, p_2, \dots, p_n$$$  — any of the possible initial values of the array $$$p$$$, which will lead to the given array $$$a$$$. All elements of $$$p$$$ are distinct integers from $$$1$$$ to $$$n$$$. Thus, if there are several solutions, print any. If there is no solution, then print -1 on the line.

NoteThe first test case in the example is clarified in the main section of the problem statement. There may be other correct answers for this test set.In the second test case, $$$n=1$$$. Thus, there is only one permutation that can be the answer: $$$p=[1]$$$. Indeed, this is the answer to this test case.In the third test case of the example, no matter what permutation you take as $$$p$$$, after applying the $$$n$$$ steps, the result will differ from $$$a=[1, 3, 5, 4, 2]$$$.

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

    function print(x) {
                  console.log(x);
    }
    let inputString = "";
    let currentLine = 0;

    process.stdin.on("data", (inputStdin) => {
      inputString += inputStdin;
    });
    process.stdin.on("end", () => {
      inputString = inputString.split("\n");
      main();
    });
    function readline() {
      return inputString[currentLine++];
    }

    // ********** Code Start **********
    function main() {
      // your code goes here
      let t = parseInt(readline());
      while (t--)
        console.log(solution());
    }

    function solution() {
      let n = parseInt(readline());

      let aString = readline();

      let array = aString.split(" ");

      if (+array[0] != n && +array[array.length-1] != n)
        return -1;

      let perm = reverse(aString);
      return perm;
    }

    function reverse(s){
    return s.split(" ").reverse().join(" ");
    }

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

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

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

		let ans;
		if (a[0] == n || a[n-1] == n) {
			ans = a.reverse();
		}

		console.log(ans ? ans.join(' ') : -1);
	}
}

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

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

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

		const mx = Math.max(...a);

		let ans;
		if (a[0] == mx) {
			ans = a.reverse();
		} else if (a[n-1] == mx) {
			ans = a.slice(0, n-1).reverse();
			ans.push(a[n-1]);
		}

		console.log(ans ? ans.join(' ') : -1);
	}
}

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)
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    if (n === 1) return arr
    const [first, last] = pickMax(n, arr)
    // console.log(print(n, first))
    // console.log(print(n, first.next))
    let mfirst = pickMin(n, first, last.prev)
    if (same(n, arr, mfirst)) return print(n, first)
    if (same(n, arr, mfirst.next)) return print(n, first)
    mfirst = pickMin(n, first.next, last)
    if (same(n, arr, mfirst)) return print(n, first.next)
    if (same(n, arr, mfirst.next)) return print(n, first.next)
    return -1
}
function print(n, first) {
    const ans = Array(n)
    for (let i = 0; i < n; i++) {
        ans[i] = first.x
        first = first.next
    }
    return ans.join(' ')
}
function same(n, arr, first) {
    let i = 0
    while (i < n) {
        if (arr[i] !== first.x) return false
        i++
        first = first.next
    }
    // for (let i = 0; i < a.length; i++) {
    //     if (a[i] !== b[i]) return false
    // }
    return true
}
function pickMin(n, pf, pl) {
    let item
    let first
    let last
    while (pf !== pl) {
        if (pf.x < pl.x) {
            item = { x: pf.x }
            pf = pf.next
            if (!first) {
                first = last = item
            } else {
                item.next = first
                first = item
            }
            // p.unshift(arr[i++])
        } else {
            item = { x: pl.x }
            pl = pl.prev
            if (!first) {
                first = last = item
            } else {
                last.next = item
                last = item
            }
            // p.push(arr[j--])
        }
    }
    item = { x: pf.x }
    if (n === 1) {
        return item
    }
    item.next = first
    first = item

    item = { x: pf.x }
    last.next = item
    return first
    // return [p.concat([arr[i]]), [arr[i]].concat(p)]
}
function pickMax(n, arr) {
    // const p = []
    let i = 0
    let j = n - 1
    let first
    let last
    let item
    while (i < j) {
        if (arr[i] > arr[j]) {
            item = { x: arr[i++] }
            if (!first) {
                first = last = item
            } else {
                item.next = first
                first.prev = item
                first = item
            }
            // p.unshift(arr[i++])
        } else {
            item = { x: arr[j--] }
            if (!first) {
                first = last = item
            } else {
                last.next = item
                item.prev = last
                last = item
            }
            // p.push(arr[j--])
        }
    }
    item = { x: arr[i] }
    if (n === 1) {
        first = last = item
        return [first, last]
    }
    item.next = first
    first.prev = item
    first = item

    item = { x: arr[i] }
    last.next = item
    item.prev = last
    last = item
    return [first, last]
}

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

const solve = (n,arr)=>{
     if((arr[0]!==n) && (arr[n-1]!==n)){
          console.log(-1);
          return;
     }
     let start = 0,end = arr.length;
     if(arr[0]===n) start++;
     else end--;
     let first = [],second = []
     for(let i=start;i<end;i++){
          if(i<Math.floor(n/2)) first.push(arr[i]);
          else second.push(arr[i]);
     }
     let res = "";
     for(let i=first.length-1;i>=0;i--) res+=first[i]+" ";
     res+=n+" ";
     for(let i=second.length-1;i>=0;i--) res+=second[i]+" ";
     console.log(res);
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       solve(n,arr);
  }
}
main();

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

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

    function print(x) {
                  console.log(x);
    }
    let inputString = "";
    let currentLine = 0;

    process.stdin.on("data", (inputStdin) => {
      inputString += inputStdin;
    });
    process.stdin.on("end", () => {
      inputString = inputString.split("\n");
      main();
    });
    function readline() {
      return inputString[currentLine++];
    }

    // ********** Code Start **********
    function main() {
      // your code goes here
      let t = parseInt(readline());
      while (t--)
        console.log(solution());
    }

    function solution() {
      let n = parseInt(readline());

      let aString = readline();

      if (n==200000 && aString[0] == '1')
        console.log("yes");
      if (+(aString[0]) !== n && +(aString[aString.length-2]) !== n && +(aString[aString.length-1]) !== n) {
        return -1;
      }

      let perm = reverse(aString);
      return perm;
    }

    function reverse(s){
    return s.split(" ").reverse().join(" ");
    }

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

    function print(x) {
                  console.log(x);
    }
    let inputString = "";
    let currentLine = 0;

    process.stdin.on("data", (inputStdin) => {
      inputString += inputStdin;
    });
    process.stdin.on("end", () => {
      inputString = inputString.split("\n");
      main();
    });
    function readline() {
      return inputString[currentLine++];
    }

    // ********** Code Start **********
    function main() {
      // your code goes here
      let t = parseInt(readline());
      while (t--)
        console.log(solution());
    }

    function solution() {
      let n = parseInt(readline());

      let aString = readline();

      if (+(aString[0]) !== n && +(aString[aString.length-2]) !== n && +(aString[aString.length-1]) !== n) {
        return -1;
      }

      let perm = reverse(aString);
      return perm;
    }

    function reverse(s){
    return s.split(" ").reverse().join(" ");
    }

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

    function print(x) {
                  console.log(x);
    }
    let inputString = "";
    let currentLine = 0;

    process.stdin.on("data", (inputStdin) => {
      inputString += inputStdin;
    });
    process.stdin.on("end", () => {
      inputString = inputString.split("\n");
      main();
    });
    function readline() {
      return inputString[currentLine++];
    }

    // ********** Code Start **********
    function main() {
      // your code goes here
      let t = parseInt(readline());
      while (t--)
        console.log(solution());
    }

    function solution() {
      let n = parseInt(readline());

      let aString = readline();

      console.log(aString[aString.length-1] == '\r');

      if (+(aString[0]) !== n && +(aString[aString.length-2]) !== n && +(aString[aString.length-1]) !== n) {
        return -1;
      }

      let perm = reverse(aString);
      return perm;
    }

    function reverse(s){
    return s.split(" ").reverse().join(" ");
    }

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

    function print(x) {
                  console.log(x);
    }
    let inputString = "";
    let currentLine = 0;

    process.stdin.on("data", (inputStdin) => {
      inputString += inputStdin;
    });
    process.stdin.on("end", () => {
      inputString = inputString.split("\n");
      main();
    });
    function readline() {
      return inputString[currentLine++];
    }

    // ********** Code Start **********
    function main() {
      // your code goes here
      let t = parseInt(readline());
      while (t--)
        console.log(solution());
    }

    function solution() {
      let n = parseInt(readline());

      let aString = readline();

      console.log(aString[aString.length-1] == '\r');

      if (+(aString[0]) !== n && +(aString[aString.length-2]) !== n)
        return -1;

      let perm = reverse(aString);
      return perm;
    }

    function reverse(s){
    return s.split(" ").reverse().join(" ");
    }

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

    function print(x) {
                  console.log(x);
    }
    let inputString = "";
    let currentLine = 0;

    process.stdin.on("data", (inputStdin) => {
      inputString += inputStdin;
    });
    process.stdin.on("end", () => {
      inputString = inputString.split("\n");
      main();
    });
    function readline() {
      return inputString[currentLine++];
    }

    // ********** Code Start **********
    function main() {
      // your code goes here
      let t = parseInt(readline());
      while (t--)
        console.log(solution());
    }

    function solution() {
      let n = parseInt(readline());

      let aString = readline();

      console.log(aString[aString.length-1] == '\r\n');

      if (+(aString[0]) !== n && +(aString[aString.length-2]) !== n)
        return -1;

      let perm = reverse(aString);
      return perm;
    }

    function reverse(s){
    return s.split(" ").reverse().join(" ");
    }

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

    function print(x) {
                  console.log(x);
    }
    let inputString = "";
    let currentLine = 0;

    process.stdin.on("data", (inputStdin) => {
      inputString += inputStdin;
    });
    process.stdin.on("end", () => {
      inputString = inputString.split("\n");
      main();
    });
    function readline() {
      return inputString[currentLine++];
    }

    // ********** Code Start **********
    function main() {
      // your code goes here
      let t = parseInt(readline());
      while (t--)
        console.log(solution());
    }

    function solution() {
      let n = parseInt(readline());

      let aString = readline();

      console.log(aString[aString.length-1] );

      if (+(aString[0]) !== n && +(aString[aString.length-2]) !== n)
        return -1;

      let perm = reverse(aString);
      return perm;
    }

    function reverse(s){
    return s.split(" ").reverse().join(" ");
    }

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

    function print(x) {
                  console.log(x);
    }
    let inputString = "";
    let currentLine = 0;

    process.stdin.on("data", (inputStdin) => {
      inputString += inputStdin;
    });
    process.stdin.on("end", () => {
      inputString = inputString.split("\n");
      main();
    });
    function readline() {
      return inputString[currentLine++];
    }

    // ********** Code Start **********
    function main() {
      // your code goes here
      let t = parseInt(readline());
      while (t--)
        console.log(solution());
    }

    function solution() {
      let n = parseInt(readline());

      let aString = readline();

      if(aString[aString.length-1] == ' ')
        console.log("yes");

      if (+(aString[0]) !== n && +(aString[aString.length-2]) !== n)
        return -1;

      let perm = reverse(aString);
      return perm;
    }

    function reverse(s){
    return s.split(" ").reverse().join(" ");
    }

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

    function print(x) {
                  console.log(x);
    }
    let inputString = "";
    let currentLine = 0;

    process.stdin.on("data", (inputStdin) => {
      inputString += inputStdin;
    });
    process.stdin.on("end", () => {
      inputString = inputString.split("\n");
      main();
    });
    function readline() {
      return inputString[currentLine++];
    }

    // ********** Code Start **********
    function main() {
      // your code goes here
      let t = parseInt(readline());
      while (t--)
        console.log(solution());
    }

    function solution() {
      let n = parseInt(readline());

      let aString = readline();

      if(aString[aString.length-1] == '\n')
        console.log("yes");

      if (+(aString[0]) !== n && +(aString[aString.length-2]) !== n)
        return -1;

      let perm = reverse(aString);
      return perm;
    }

    function reverse(s){
    return s.split(" ").reverse().join(" ");
    }

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

    function print(x) {
                  console.log(x);
    }
    let inputString = "";
    let currentLine = 0;

    process.stdin.on("data", (inputStdin) => {
      inputString += inputStdin;
    });
    process.stdin.on("end", () => {
      inputString = inputString.split("\n");
      main();
    });
    function readline() {
      return inputString[currentLine++];
    }

    // ********** Code Start **********
    function main() {
      // your code goes here
      let t = parseInt(readline());
      while (t--)
        console.log(solution());
    }

    function solution() {
      let n = parseInt(readline());

      let aString = readline();

      if (+(aString[0]) !== n && +(aString[aString.length-2]) !== n)
        return -1;

      let perm = reverse(aString);
      return perm;
    }

    function reverse(s){
    return s.split(" ").reverse().join(" ");
    }

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

    function print(x) {
                  console.log(x);
    }
    let inputString = "";
    let currentLine = 0;

    process.stdin.on("data", (inputStdin) => {
      inputString += inputStdin;
    });
    process.stdin.on("end", () => {
      inputString = inputString.split("\n");
      main();
    });
    function readline() {
      return inputString[currentLine++];
    }

    // ********** Code Start **********
    function main() {
      // your code goes here
      let t = parseInt(readline());
      while (t--)
        console.log(solution());
    }

    function solution() {
      let n = parseInt(readline());

      let aString = readline();
      console.log(typeof(aString));

      if (+(aString[0]) !== n && +(aString[aString.length-2]) !== n)
        return -1;

      // let perm = aString.reverse();
      // return perm;
    }

    function reverse(s){
    return s.split("").reverse().join("");
    }

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

    function print(x) {
                  console.log(x);
    }
    let inputString = "";
    let currentLine = 0;

    process.stdin.on("data", (inputStdin) => {
      inputString += inputStdin;
    });
    process.stdin.on("end", () => {
      inputString = inputString.split("\n");
      main();
    });
    function readline() {
      return inputString[currentLine++];
    }

    // ********** Code Start **********
    function main() {
      // your code goes here
      let t = parseInt(readline());
      while (t--)
        console.log(solution());
    }

    function solution() {
      let n = parseInt(readline());

      let aString = readline();

      if (+(aString[0]) == n || +(aString[aString.length-2]) == n)
       console.log("it works");

      // let perm = aString.reverse();
      // return perm;
    }

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

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

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

		const mx = Math.max(...a);

		let ans;
		if (a[0] == mx) {
			ans = a.reverse();
		} else if (a[n-1] == mx) {
			ans = a;
		}

		console.log(ans ? ans.join(' ') : -1);
	}
}

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

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

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

		if (a.length > 2
			&& a[0] < Math.max(a[1], a[n-1])
			&& a[n-1] < Math.max(a[0], a[n-2])) {
			console.log(-1);
			continue;
		}

		m = n >> 1;
		ans = [...a.slice(0, m).reverse(), ...a.slice(m).reverse()],

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

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)
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    const [p1, p2] = pickMax(n, arr)
    const [p3, p4] = pickMin(n, p1)
    if (same(arr, p3)) return p3.join(' ')
    if (same(arr, p4)) return p4.join(' ')
    const [p5, p6] = pickMin(n, p2)
    if (same(arr, p5)) return p5.join(' ')
    if (same(arr, p6)) return p6.join(' ')
    return -1
}
function same(a, b) {
    for (let i = 0; i < a.length; i++) {
        if (a[i] !== b[i]) return false
    }
    return true
}
function pickMin(n, arr) {
    const p = []
    let i = 0
    let j = n - 1
    while (i < j) {
        if (arr[i] < arr[j]) {
            p.unshift(arr[i++])
        } else {
            p.push(arr[j--])
        }
    }
    return [p.concat([arr[i]]), [arr[i]].concat(p)]
}
function pickMax(n, arr) {
    const p = []
    let i = 0
    let j = n - 1
    while (i < j) {
        if (arr[i] > arr[j]) {
            p.unshift(arr[i++])
        } else {
            p.push(arr[j--])
        }
    }
    return [p.concat([arr[i]]), [arr[i]].concat(p)]
}