You are given two arrays $$$a$$$ and $$$b$$$, both consisting of $$$n$$$ integers.In one move, you can choose two indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$; $$$i \neq j$$$) and swap $$$a_i$$$ with $$$a_j$$$ and $$$b_i$$$ with $$$b_j$$$. You have to perform the swap in both arrays.You are allowed to perform at most $$$10^4$$$ moves (possibly, zero). Can you make both arrays sorted in a non-decreasing order at the end? If you can, print any sequence of moves that makes both arrays sorted.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$) — the number of elements in both arrays. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the first array. The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le n$$$) — the second array.

For each testcase, print the answer. If it's impossible to make both arrays sorted in a non-decreasing order in at most $$$10^4$$$ moves, print -1. Otherwise, first, print the number of moves $$$k$$$ $$$(0 \le k \le 10^4)$$$. Then print $$$i$$$ and $$$j$$$ for each move $$$(1 \le i, j \le n$$$; $$$i \neq j)$$$. If there are multiple answers, then print any of them. You don't have to minimize the number of moves.

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

let input = [];
rl.on("line", function (line) {
  input.push(line);
}).on("close", function () {
  solution(input);
  process.exit();
});

function solution(_input) {
  const input = _input[Symbol.iterator]();
  const T = Number(input.next().value);

  const results = [];
  tc: for (let t = 0; t < T; t++) {
    const N = Number(input.next().value);
    const A = input.next().value.split(" ").map(Number);
    const B = input.next().value.split(" ").map(Number);

    const AB = [];
    for (let i = 0; i < N; i++) {
      AB.push([A[i], B[i]]);
    }
    AB.sort(([a1, b1], [a2, b2]) => (a1 < a2 ? -1 : b1 < b2 ? -1 : 0));
    for (let i = 1; i < N; i++) {
      if (AB[i - 1][0] > AB[i][0] || AB[i - 1][1] > AB[i][1]) {
        results.push("-1");
        continue tc;
      }
    }

    ops = [];
    for (let i = 0; i < N; i++) {
      for (let j = i + 1; j < N; j++) {
        if (A[i] > A[j] || B[i] > B[j]) {
          [A[i], A[j]] = [A[j], A[i]];
          [B[i], B[j]] = [B[j], B[i]];
          ops.push([j + 1, i + 1].join(" "));
        }
      }
    }
    results.push(ops.length);
    for (let i = 0; i < ops.length; i++) {
      results.push(ops[i]);
    }
  }
  console.log(results.join("\n"));
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr1 = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr2 = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let res = [];
    const sort = (arr, arr1) => {
      for (let i = 0; i < n; i++) {
        let min = i;
        for (let j = i + 1; j < n; j++) {
          if (arr[min] > arr[j]) min = j;
        }
        if (min === i) continue;
        res.push(`${min + 1} ${i + 1}`);
        [arr[i], arr[min]] = [arr[min], arr[i]];
        [arr1[i], arr1[min]] = [arr1[min], arr1[i]];
      }
      for (let i = 1; i < n; i++) {
        if (arr1[i - 1] > arr1[i]) return false;
      }
      return true;
    };
    const print = () => {
      console.log(res.length);
      if (res.length === 0) return;
      for (let i = 0; i < res.length; i++) console.log(res[i]);
    };
    if (sort(arr1, arr2)) {
      print();
      continue;
    }
    if (sort(arr2, arr1)) {
      print();
      continue;
    }
    console.log(-1);
  }
};
solve();

'use strict';
// HEADER:
const print = function(arg){
  let str = arg;
  if (arguments.length>1)
    str = Array.prototype.slice.call(arguments).join(' ');
  process.stdout.write(str+'\n');
};
let IS_MULTITEST, testN, tests;
const pcalc = (testN, toPrint)=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    toPrint.push(res.join(' '));
  } else if (Number.isFinite(res) || typeof res=='string'){
    toPrint.push(res+'');
  }
  if (process.env.DEBUG && toPrint.length){
    let ans = toPrint.pop();
    print(ans);
    let expected = tests[testN-1];
    if (expected){
      if (expected==ans)
        console.log('\x1b[32m%s\x1b[0m', 'correct');
      else {
        console.log('\x1b[31m%s\x1b[0m', 'wrong, expected:', expected);
      }
    }
  }
};

const main = ()=>{
  let toPrint = [];
  L('\nSolving:');
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(testN, toPrint);
  } else {
    pcalc(1, toPrint);
  }
  if (toPrint.length){
    print(toPrint.join('\n'));
  }
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`\nTest #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

tests = [
``, // Test #1
``, // Test #2
``, // Test #3
``, // Test #4
``, // Test #5
];

// SOLUTION:
IS_MULTITEST = true;

const calc = (testN)=>{
  // READING:
  let [n] = ra();
  let A = ra();
  let B = ra();
  LT({n, A, B});
  // PROCESSING:
  let P = [];
  for (let i=0; i<n; i++)
    P.push(i);
  let swaps = [];
  let swap = (i, j)=>{
    swaps.push((i+1)+' '+(j+1));
    let tmp = A[i];
    A[i] = A[j];
    A[j] = tmp;
    tmp = B[i];
    B[i] = B[j];
    B[j] = tmp;
  };
  for (let i=0; i<n; i++){
    for (let j=0; j<n-1; j++){
      if (A[j]==A[j+1]){
        if (B[j]>B[j+1]){
          swap(j, j+1);
        }
      } else {
        if (A[j]<A[j+1]){
          if (B[j]>B[j+1])
            return void print(-1);
        } else {
          if (B[j]<B[j+1])
            return void print(-1);
          swap(j, j+1);
        }
      }
    }
  }
  print(swaps.length);
  if (swaps.length)
    print(swaps.join('\n'))
};

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

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

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

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

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

    let moves = [];

    for (let i = 0; i < n; i++) {
        let minidx = i;
        let j = i + 1;
        for (; j < n; j++) {
            if (a[j] < a[minidx]) {
                minidx = j;
            }
        }
        if (minidx === i) continue;
        j = minidx;
        moves.push(`${i + 1} ${j + 1}`);

        let tmpa = a[i];
        a[i] = a[j];
        a[j] = tmpa;

        let tmpb = b[i];
        b[i] = b[j];
        b[j] = tmpb;
    }

    for (let l = 0; l < n - 1; l++) {
        let r = l + 1;
        while (r < n && a[l] === a[r]) {
            r++;
        }

        for (let i = l; i < r; i++) {
            let minidx = i;
            let j = i + 1
            for (; j < r; j++) {
                if (b[j] < b[minidx]) {
                    minidx = j;
                }
            }
            if (minidx === i) continue;
            j = minidx;
            moves.push(`${i + 1} ${j + 1}`);

            let tmpb = b[i];
            b[i] = b[j];
            b[j] = tmpb;
        }

    }

    if (moves.length > 10000) return '-1';

    for (let i = 1; i < n; i++) {
        if (b[i] < b[i - 1]) return '-1';
    }

    let result = `${moves.length}`;
    if (moves.length > 0) {
        result += '\n';
        result += moves.join('\n');
    }
    return result;
};

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

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

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
var T = readline();
for(var qe=1;qe<=T;qe++) {
  var n = parseInt(readline());
  var a = readline().split(' ').map((x) => parseInt(x));
  var b = readline().split(' ').map((x) => parseInt(x));
  var as = [...a]
  var bs = [...b]
  as.sort(function(x,y) { return x-y })
  bs.sort(function(x,y) { return x-y })
  // var rev_a = reverse(as);
  // var rev_b = reverse(bs);
  // function reverse(arr) {
  //   var v = [];
  //   for(var j=arr.length-1;j>=0;j--) v.push(arr[j]);
  //   return v;
  // }
  //console.log(a, as, rev_a);
  var ans = [];
  var flag = true;
  for(var i=0;i<n;i++) {
    var ok = false;
    for(var j=i;j<n;j++) {
      if(a[j] == as[i] && b[j] == bs[i]) {
        if(i != j) ans.push([i+1, j+1]);
        ok = true;
        a[j] = a[i];
        b[j] = b[i];
        break;
      }
    }
    if(!ok) flag = false;
  }
  if(!flag) console.log(-1);
  else {
      console.log(ans.length);
      for(var i=0;i<ans.length;i++) {
        console.log(ans[i].join(' '));
      }
  }

  //console.log(ans);
  //fs.appendFileSync('output.txt', ans+'\r\n');

}
//

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

function solve(sa, sb) {
    const moves = []
    const sorted = sa.map((x, i) => ({ x, i }))
        // .sort((a, b) => a.x - b.x)
    sort(sorted, 0, sorted.length - 1, sa, moves)
// console.log(sorted)
    //
    let p = {}, pi = -1
    sorted.forEach((x, i) => {
        if (x.x === p.x) {
            //
        } else {
            // [pi, i - 1]
            if (pi >= 0) {
                // console.log(pi, i - 1)
                sort(sorted, pi, i - 1, sb, moves)
            }
            p = x
            pi = i
        }
    })
// console.log(pi, sa.length - 1)
    sort(sorted, pi, sa.length - 1, sb, moves)
    const after = sorted.map(o => sb[o.i])
// console.log(after)
    for (let i = 1; i < after.length; i++) {
        if (after[i - 1] > after[i]) return -1
    }
    if (!moves.length) return 0
    return moves.length + '\n' + moves.join('\n')
}
function sort(arr, first, last, old, moves) {
    let swap
    for (let i = first; i <= last; i++) {
        swap = 0
        for (let j = first + 1; j <= last; j++) {
            if (old[arr[j - 1].i] > old[arr[j].i]) {
                [arr[j - 1], arr[j]] = [arr[j], arr[j - 1]]
                moves.push([j - 1 + 1, j + 1].join(' '))
                swap = 1
            }
        }
        if (!swap) break
    }
}

'use strict';

function solve(n, a, b) {
  let nums = new Array(n);
  for (let i = 0; i < n; i++) {
    nums[i] = [a[i], b[i], i];
  }
  let flag = true;
  nums.sort((a, b) => {
    if (a[0] === b[0]) {
      return a[1] - b[1];
    } else if (a[1] === b[1]) {
      return a[0] - b[0];
    } else {
      const x = a[0] - b[0],
            y = a[1] - b[1];
      if (x * y < 0) {
        flag = false;
      }
      return a[0] - b[0];
    }
  });
  if (!flag) return -1;
  const h = new Array(n).fill(-1),
        e = [],
        ne = [];
  let idx = 0;
  const add = (i, j) => {
    e[idx] = j, ne[idx] = h[i], h[i] = idx++;
  };
  for (let i = 0; i < n; i++) {
    if (nums[i][2] !== i) {
      add(i, nums[i][2]);
    }
  }
  let res = [],
      st = new Array(n);
  for (let i = 0; i < n; i++) {
    if (st[i]) continue;
    if (h[i] !== -1) {
      const queue = [i];
      for (let u of queue) {
        st[u] = 1;
        for (let k = h[u]; k !== -1; k = ne[k]) {
          const v = e[k];
          if (st[v]) continue;
          queue.push(v);
        }
      }
      let cur = i;
      for (let j = 1; j < queue.length; j++) {
        res.push([cur, queue[j]]);
        cur = queue[j];
      }
    }
  }
  if (res.length === 0) return '0';
  return `${res.length}\n${res.map(arr => arr.map(num => num + 1).join(' ')).join('\n')}`;
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    while (t--) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      const b = (await read()).split(' ').map(Number);
      res.push(solve(n, a, b));
    }
    console.log(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', () => {
  inputs = str.split('\n').values();
  main(read);
});

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

let input = [];
rl.on("line", function (line) {
  input.push(line);
}).on("close", function () {
  solution(input);
  process.exit();
});

function solution(_input) {
  const input = _input[Symbol.iterator]();
  const T = Number(input.next().value);

  const results = [];
  tcloop: for (let t = 0; t < T; t++) {
    const N = Number(input.next().value);
    const A = input.next().value.split(" ").map(Number);
    const B = input.next().value.split(" ").map(Number);

    const AB = [];
    for (let i = 0; i < N; i++) {
      AB.push([A[i], B[i]]);
    }
    AB.sort(([a1, b1], [a2, b2]) => (a1 < a2 ? -1 : b1 < b2 ? -1 : 0));
    for (let i = 1; i < N; i++) {
      if (AB[0][i - 1] > AB[0][i] || AB[1][i - 1] > AB[1][i]) {
        results.push("-1");
        continue tcloop;
      }
    }

    ops = [];
    // for (let i = 0; i < N; i++) {
    //   for (let j = i + 1; j < N; j++) {
    //     if (A[i] > A[j] || B[i] > B[j]) {
    //       [A[i], A[j]] = [A[j], A[i]];
    //       [B[i], B[j]] = [B[j], B[i]];
    //       ops.push([j + 1, i + 1].join(" "));
    //     }
    //   }
    // }
    for (let i = 1; i < N; i++) {
      for (let j = 1; j < N; j++) {
        if (A[j - 1] > A[j] || B[j - 1] > B[j]) {
          [A[j - 1], A[j]] = [A[j], A[j - 1]];
          [B[j - 1], B[j]] = [B[j], B[j - 1]];
          ops.push([j, j + 1].join(" "));
        }
      }
    }

    results.push(ops.length);
    for (let i = 0; i < ops.length; i++) {
      results.push(ops[i]);
    }
  }
  console.log(results.join("\n"));
}

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

let input = [];
rl.on("line", function (line) {
  input.push(line);
}).on("close", function () {
  solution(input);
  process.exit();
});

function solution(_input) {
  const input = _input[Symbol.iterator]();
  const T = Number(input.next().value);

  const results = [];
  tcloop: for (let t = 0; t < T; t++) {
    const N = Number(input.next().value);
    const A = input.next().value.split(" ").map(Number);
    const B = input.next().value.split(" ").map(Number);

    const AB = [];
    for (let i = 0; i < N; i++) {
      AB.push([A[i], B[i]]);
    }
    AB.sort(([a1, b1], [a2, b2]) => (a1 < a2 ? -1 : b1 < b2 ? -1 : 0));
    for (let i = 1; i < N; i++) {
      if (AB[0][i - 1] > AB[0][i] || AB[1][i - 1] > AB[1][i]) {
        results.push("-1");
        continue tcloop;
      }
    }

    ops = [];
    for (let i = 0; i < N; i++) {
      for (let j = i + 1; j < N; j++) {
        if (A[i] > A[j] || B[i] > B[j]) {
          [A[i], A[j]] = [A[j], A[i]];
          [B[i], B[j]] = [B[j], B[i]];
          ops.push([j + 1, i + 1].join(" "));
        }
      }
    }

    results.push(ops.length);
    for (let i = 0; i < ops.length; i++) {
      results.push(ops[i]);
    }
  }
  console.log(results.join("\n"));
}

const { Console } = require("console");

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

let input = [];
rl.on("line", function (line) {
  input.push(line);
}).on("close", function () {
  solution(input);
  process.exit();
});

function solution(_input) {
  const input = _input[Symbol.iterator]();
  const T = Number(input.next().value);

  const results = [];
  tcloop: for (let t = 0; t < T; t++) {
    const N = Number(input.next().value);
    const A = input.next().value.split(" ").map(Number);
    const B = input.next().value.split(" ").map(Number);

    const AB = [];
    for (let i = 0; i < N; i++) {
      AB.push([A[i], B[i]]);
    }
    AB.sort(([a1, b1], [a2, b2]) => (a1 < a2 ? -1 : b1 < b2 ? -1 : 0));
    for (let i = 1; i < N; i++) {
      if (AB[0][i - 1] > AB[0][i] || AB[1][i - 1] > AB[1][i]) {
        results.push("-1");
        continue tcloop;
      }
    }

    ops = [];
    for (let i = 0; i < N; i++) {
      for (let j = i + 1; j < N; j++) {
        if (A[i] > A[j] || B[i] > B[j]) {
          [A[i], A[j]] = [A[j], A[i]];
          [B[i], B[j]] = [B[j], B[i]];
          ops.push([j + 1, i + 1].join(" "));
        }
      }
    }

    for (let i = 0; i < N; i++) {
      for (let j = i + 1; j < N; j++) {
        if (A[i] > A[j] || B[i] > B[j]) {
          [A[i], A[j]] = [A[j], A[i]];
          [B[i], B[j]] = [B[j], B[i]];
          ops.push([j + 1, i + 1].join(" "));
        }
      }
    }

    results.push(ops.length);
    for (let i = 0; i < ops.length; i++) {
      results.push(ops[i]);
    }
  }
  console.log(results.join("\n"));
}

const { Console } = require("console");

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

let input = [];
rl.on("line", function (line) {
  input.push(line);
}).on("close", function () {
  solution(input);
  process.exit();
});

function solution(_input) {
  const input = _input[Symbol.iterator]();
  const T = Number(input.next().value);

  const results = [];
  tcloop: for (let t = 0; t < T; t++) {
    const N = Number(input.next().value);
    const A = input.next().value.split(" ").map(Number);
    const B = input.next().value.split(" ").map(Number);

    const AB = [];
    for (let i = 0; i < N; i++) {
      AB.push([A[i], B[i]]);
    }
    AB.sort(([a1, b1], [a2, b2]) => (a1 < a2 ? -1 : b1 < b2 ? -1 : 0));
    for (let i = 1; i < N; i++) {
      if (AB[0][i - 1] > AB[0][i] || AB[1][i - 1] > AB[1][i]) {
        results.push("-1");
        continue tcloop;
      }
    }

    ops = [];
    for (let i = 0; i < N - 1; i++) {
      for (let j = i + 1; j < N; j++) {
        if (A[i] > A[j] || B[i] > B[j]) {
          [A[i], A[j]] = [A[j], A[i]];
          [B[i], B[j]] = [B[j], B[i]];
          ops.push([j + 1, i + 1].join(" "));
        }
      }
    }

    results.push(ops.length);
    for (let i = 0; i < ops.length; i++) {
      results.push(ops[i]);
    }
  }
  console.log(results.join("\n"));
}

const { Console } = require("console");

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

let input = [];
rl.on("line", function (line) {
  input.push(line);
}).on("close", function () {
  solution(input);
  process.exit();
});

function solution(_input) {
  const input = _input[Symbol.iterator]();
  const T = Number(input.next().value);

  const results = [];
  tcloop: for (let t = 0; t < T; t++) {
    const N = Number(input.next().value);
    const A = input.next().value.split(" ").map(Number);
    const B = input.next().value.split(" ").map(Number);

    const AB = [];
    for (let i = 0; i < N; i++) {
      AB.push([A[i], B[i]]);
    }
    AB.sort(([a1, b1], [a2, b2]) => (a1 < a2 ? -1 : b1 < b2 ? -1 : 0));
    for (let i = 1; i < N; i++) {
      if (AB[0][i - 1] > AB[0][i] || AB[1][i - 1] > AB[1][i]) {
        results.push(-1);
        continue tcloop;
      }
    }

    ops = [];
    for (let i = 0; i < N; i++) {
      for (let j = i + 1; j < N; j++) {
        if (A[i] > A[j] || B[i] > B[j]) {
          [A[i], A[j]] = [A[j], A[i]];
          [B[i], B[j]] = [B[j], B[i]];
          ops.push([j + 1, i + 1].join(" "));
        }
      }
    }

    results.push(ops.length);
    for (let i = 0; i < ops.length; i++) {
      results.push(ops[i]);
    }
  }
  console.log(results.join("\n"));
}

const { Console } = require("console");

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

let input = [];
rl.on("line", function (line) {
  input.push(line);
}).on("close", function () {
  solution(input);
  process.exit();
});

function solution(_input) {
  const input = _input[Symbol.iterator]();
  const T = Number(input.next().value);

  const results = [];
  tcloop: for (let t = 0; t < T; t++) {
    const N = Number(input.next().value);
    const A = input.next().value.split(" ").map(Number);
    const B = input.next().value.split(" ").map(Number);

    const AB = [];
    for (let i = 0; i < N; i++) {
      AB.push([A[i], B[i]]);
    }
    AB.sort(([a1, b1], [a2, b2]) => (a1 < a2 ? -1 : b1 < b2 ? -1 : 0));
    for (let i = 1; i < N; i++) {
      if (AB[1][i - 1] > AB[1][i]) {
        results.push(-1);
        continue tcloop;
      }
    }

    ops = [];
    for (let i = 0; i < N; i++) {
      for (let j = i + 1; j < N; j++) {
        if (A[i] > A[j] || B[i] > B[j]) {
          [A[i], A[j]] = [A[j], A[i]];
          [B[i], B[j]] = [B[j], B[i]];
          ops.push([j + 1, i + 1].join(" "));
        }
      }
    }

    results.push(ops.length);
    for (let i = 0; i < ops.length; i++) {
      results.push(ops[i]);
    }
  }
  console.log(results.join("\n"));
}

const { Console } = require("console");

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

let input = [];
rl.on("line", function (line) {
  input.push(line);
}).on("close", function () {
  solution(input);
  process.exit();
});

function solution(_input) {
  const input = _input[Symbol.iterator]();
  const T = Number(input.next().value);

  const results = [];
  tcloop: for (let t = 0; t < T; t++) {
    const N = Number(input.next().value);
    const A = input.next().value.split(" ").map(Number);
    const B = input.next().value.split(" ").map(Number);

    const AB = [];
    for (let i = 0; i < N; i++) {
      AB.push([A[i], B[i]]);
    }
    AB.sort(([a1, b1], [a2, b2]) => (a1 < a2 ? -1 : b1 < b2 ? -1 : 0));
    for (let i = 1; i < N; i++) {
      if (AB[1][i - 1] > AB[1][i]) {
        results.push(-1);
        continue tcloop;
      }
    }

    ops = [];
    for (let i = 0; i < N; i++) {
      for (let j = i + 1; j < N; j++) {
        if (A[i] > A[j] || B[i] > B[j]) {
          [A[i], A[j]] = [A[j], A[i]];
          [B[i], B[j]] = [B[j], B[i]];
          ops.push([i + 1, j + 1].join(" "));
        }
      }
    }

    results.push(ops.length);
    for (let i = 0; i < ops.length; i++) {
      results.push(ops[i]);
    }
  }
  console.log(results.join("\n"));
}

const { Console } = require("console");

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

let input = [];
rl.on("line", function (line) {
  input.push(line);
}).on("close", function () {
  solution(input);
  process.exit();
});

function solution(_input) {
  const input = _input[Symbol.iterator]();
  const T = Number(input.next().value);

  const results = [];
  for (let t = 0; t < T; t++) {
    const N = Number(input.next().value);
    const A = input.next().value.split(" ").map(Number);
    const B = input.next().value.split(" ").map(Number);
    const history = [];
    for (let i = 0; i < N; i++) {
      let minA = A[i];
      let minB = B[i];
      let idxA = null;
      let idxB = null;
      for (let j = i + 1; j < N; j++) {
        if (minA > A[j]) {
          minA = A[j];
          idxA = j;
        }
        if (minB > B[j]) {
          minB = B[j];
          idxB = j;
        }
      }
      const idx = idxA || idxB;
      if (idx !== null) {
        let tmp = A[i];
        A[i] = A[idx];
        A[idx] = tmp;
        tmp = B[i];
        B[i] = B[idx];
        B[idx] = tmp;
        history.push([i + 1, idx + 1]);
      }
    }
    if (
      JSON.stringify(A.slice().sort()) === JSON.stringify(A) &&
      JSON.stringify(B.slice().sort()) === JSON.stringify(B)
    ) {
      results.push(history.length);
      history.forEach((v) => results.push(v.join(" ")));
    } else {
      results.push(-1);
    }

    // console.log(history);
  }
  console.log(results.join("\n"));
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr1 = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr2 = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let res = [];
    const sort = (arr, arr1) => {
      for (let i = 0; i < n; i++) {
        let min = i;
        for (let j = i + 1; j < n; j++) {
          if (arr[min] > arr[j]) min = j;
        }
        if (min === i) continue;
        res.push(`${min + 1} ${i + 1}`);
        [arr[i], arr[min]] = [arr[min], arr[i]];
        [arr1[i], arr1[min]] = [arr1[min], arr1[i]];
      }
      for (let i = 1; i < n; i++) {
        if (arr1[i - 1] > arr1[i]) return false;
      }
      return true;
    };
    const print = () => {
      console.log(res.length);
      if (res.length === 0) return;
      for (let i = 0; i < res.length; i++) console.log(res[i]);
    };
    if (sort(arr1, arr2)) {
      print();
      continue;
    }
    res = [];
    if (sort(arr2, arr1)) {
      print();
      continue;
    }
    console.log(-1);
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr1 = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr2 = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let res = [];
    const sort = (arr, arr1) => {
      for (let i = 0; i < n; i++) {
        let min = i;
        for (let j = i + 1; j < n; j++) {
          if (arr[min] > arr[j]) min = j;
        }
        if (min === i) continue;
        res.push(`${min + 1} ${i + 1}`);
        [arr[i], arr[min]] = [arr[min], arr[i]];
        [arr1[i], arr1[min]] = [arr1[min], arr1[i]];
      }
      for (let i = 1; i < n; i++) {
        if (arr1[i - 1] > arr1[i]) return false;
      }
      return true;
    };
    const print = () => {
      console.log(res.length);
      if (res.length === 0) return;
      for (let i = 0; i < res.length; i++) console.log(res[i]);
    };
    if (sort([...arr1], [...arr2])) {
      print();
      continue;
    }
    res = [];
    if (sort([...arr2], [...arr1])) {
      print();
      continue;
    }
    console.log(-1);
  }
};
solve();

'use strict';
// HEADER:
const print = function(arg){
  let str = arg;
  if (arguments.length>1)
    str = Array.prototype.slice.call(arguments).join(' ');
  process.stdout.write(str+'\n');
};
let IS_MULTITEST, testN, tests;
const pcalc = (testN, toPrint)=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    toPrint.push(res.join(' '));
  } else if (Number.isFinite(res) || typeof res=='string'){
    toPrint.push(res+'');
  }
  if (process.env.DEBUG && toPrint.length){
    let ans = toPrint.pop();
    print(ans);
    let expected = tests[testN-1];
    if (expected){
      if (expected==ans)
        console.log('\x1b[32m%s\x1b[0m', 'correct');
      else {
        console.log('\x1b[31m%s\x1b[0m', 'wrong, expected:', expected);
      }
    }
  }
};

const main = ()=>{
  let toPrint = [];
  L('\nSolving:');
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(testN, toPrint);
  } else {
    pcalc(1, toPrint);
  }
  if (toPrint.length){
    print(toPrint.join('\n'));
  }
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`\nTest #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

tests = [
``, // Test #1
``, // Test #2
``, // Test #3
``, // Test #4
``, // Test #5
];

// SOLUTION:
IS_MULTITEST = true;

const calc = (testN)=>{
  // READING:
  let [n] = ra();
  let A = ra();
  let B = ra();
  LT({n, A, B});
  // PROCESSING:
  let P = [];
  for (let i=0; i<n; i++)
    P.push(i);
  let swaps = [];
  let swap = (i, j)=>{
    swaps.push((i+1)+' '+(j+1));
    let tmp = A[i];
    A[i] = A[j];
    A[j] = tmp;
    tmp = B[i];
    B[i] = B[j];
    B[j] = tmp;
  };
  for (let i=0; i<n; i++){
    for (let j=0; j<n-1; j++){
      if (A[j]==A[j+1]){
        if (B[j]>B[j+1]){
          swap(j, j+1);
        }
      } else {
        if (A[j]<A[j+1]){
          if (B[j]>B[j+1])
            print(-1);
        } else {
          if (B[j]<B[j+1])
            print(-1);
          swap(j, j+1);
        }
      }
    }
  }
  print(swaps.length);
  if (swaps.length)
    print(swaps.join('\n'))
};

'use strict';
// HEADER:
const print = function(arg){
  let str = arg;
  if (arguments.length>1)
    str = Array.prototype.slice.call(arguments).join(' ');
  process.stdout.write(str+'\n');
};
let IS_MULTITEST, testN, tests;
const pcalc = (testN, toPrint)=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    toPrint.push(res.join(' '));
  } else if (Number.isFinite(res) || typeof res=='string'){
    toPrint.push(res+'');
  }
  if (process.env.DEBUG && toPrint.length){
    let ans = toPrint.pop();
    print(ans);
    let expected = tests[testN-1];
    if (expected){
      if (expected==ans)
        console.log('\x1b[32m%s\x1b[0m', 'correct');
      else {
        console.log('\x1b[31m%s\x1b[0m', 'wrong, expected:', expected);
      }
    }
  }
};

const main = ()=>{
  let toPrint = [];
  L('\nSolving:');
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(testN, toPrint);
  } else {
    pcalc(1, toPrint);
  }
  if (toPrint.length){
    print(toPrint.join('\n'));
  }
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`\nTest #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

tests = [
``, // Test #1
``, // Test #2
``, // Test #3
``, // Test #4
``, // Test #5
];

// SOLUTION:
IS_MULTITEST = true;

const calc = (testN)=>{
  // READING:
  let [n] = ra();
  let A = ra();
  let B = ra();
  LT({n, A, B});
  // PROCESSING:
  let P = [];
  for (let i=0; i<n; i++)
    P.push(i);
  let swaps = [];
  let swap = (i, j)=>{
    swaps.push((i+1)+' '+(j+1));
    let tmp = A[i];
    A[i] = A[j];
    A[j] = tmp;
    tmp = B[i];
    B[i] = B[j];
    B[j] = tmp;
  };
  for (let i=0; i<n; i++){
    for (let j=0; j<n-1; j++){
      if (A[j]==A[j+1]){
        if (B[j]>B[j+1]){
          swap(j, j+1);
        }
      } else {
        if (A[j]<A[j+1]){
          if (B[j]>B[j+1])
            return -1;
        } else {
          if (B[j]<B[j+1])
            return -1;
          swap(j, j+1);
        }
      }
    }
  }
  print(swaps.length);
  print(swaps.join('\n'))
};

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

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

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

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

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

    let moves = [];

    for (let i = 0; i < n; i++) {
        let minidx = i;
        let j = i + 1;
        for (; j < n; j++) {
            if (a[j] < a[minidx]) {
                minidx = j;
            }
        }
        if (minidx === i) continue;
        j = minidx;
        moves.push(`${i} ${j}`);

        let tmpa = a[i];
        a[i] = a[j];
        a[j] = tmpa;

        let tmpb = b[i];
        b[i] = b[j];
        b[j] = tmpb;
    }

    for (let l = 0; l < n - 1; l++) {
        let r = l + 1;
        while (r < n && a[l] === a[r]) {
            r++;
        }

        for (let i = l; i < r; i++) {
            let minidx = i;
            let j = i + 1
            for (; j < r; j++) {
                if (b[j] < b[minidx]) {
                    minidx = j;
                }
            }
            if (minidx === i) continue;
            j = minidx;
            moves.push(`${i} ${j}`);

            let tmpb = b[i];
            b[i] = b[j];
            b[j] = tmpb;
        }

    }

    if (moves.length > 10000) return '-1';

    for (let i = 1; i < n; i++) {
        if (b[i] < b[i - 1]) return '-1';
    }

    let result = `${moves.length}`;
    if (moves.length > 0) {
        result += '\n';
        result += moves.join('\n');
    }
    return result;
};

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

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

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
var T = readline();
for(var qe=1;qe<=T;qe++) {
  var n = parseInt(readline());
  var a = readline().split(' ').map((x) => parseInt(x));
  var b = readline().split(' ').map((x) => parseInt(x));
  var as = [...a]
  var bs = [...b]
  as.sort(function(x,y) { return x-y })
  bs.sort(function(x,y) { return x-y })
  // var rev_a = reverse(as);
  // var rev_b = reverse(bs);
  // function reverse(arr) {
  //   var v = [];
  //   for(var j=arr.length-1;j>=0;j--) v.push(arr[j]);
  //   return v;
  // }
  //console.log(a, as, rev_a);
  var ans = [];
  var flag = true;
  for(var i=0;i<n;i++) {
    var ok = false;
    for(var j=i;j<n;j++) {
      if(a[j] == as[i] && b[j] == bs[i]) {
        if(i != j) ans.push([i+1, j+1]);
        ok = true;
        a[j] = a[i];
        b[j] = b[i];
        break;
      }
    }
    if(!ok) flag = false;
  }
  if(!flag) console.log(-1);
  else {
    if(ans.length===0) console.log(0);
    else {
      for(var i=0;i<ans.length;i++) {
        console.log(ans[i].join(' '));
      }
    }
  }

  //console.log(ans);
  //fs.appendFileSync('output.txt', ans+'\r\n');

}
//


Given three distinct integers $$$a$$$, $$$b$$$, and $$$c$$$, find the medium number between all of them.The medium number is the number that is neither the minimum nor the maximum of the given three numbers. For example, the median of $$$5,2,6$$$ is $$$5$$$, since the minimum is $$$2$$$ and the maximum is $$$6$$$.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 6840$$$) — the number of test cases. The description of each test case consists of three distinct integers $$$a$$$, $$$b$$$, $$$c$$$ ($$$1 \leq a, b, c \leq 20$$$).

For each test case, output a single integer — the medium number of the three numbers.

'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 testNumbers = readline();

    for(let i = 0; i<testNumbers; i++){
        solve(readline().split(" ").map(x=>parseInt(x)));
    }
}

function solve(input){
    let max = 0;
    let min = 21;
    for(let i = 0; i<3; i++){
        max = input[i] > max ? input[i] : max;
        min = input[i] < min ? input[i] : min;
    }
    console.log(
        input.filter(x=>x != max && x != min)[0]
    )
}

let buf='';

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

process.stdin.on('end', function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    for(let _=1;_<=t;_++)
    {
        let [a,b,c]=line[_].split(' ').map(x=>{return parseInt(x)});
        if(a>b) [a,b]=[b,a];
        if(a>c) [a,c]=[c,a];
        if(b>c) [b,c]=[c,b];
        console.log(b);
    }
})

const fs = require("fs");
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}
function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}
var T = readline();
var inf = 1000000000000;
for(var tc=1;tc<=T;tc++) {
	var n = readline().split(" ").map(w => parseInt(w));
	n.sort((x,y) => x-y);
	console.log(n[1])
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

    return gcd( b , a%b )
}

function main() {

    let t = parseInt(readLine());

    //let mod = 10**9+7
    loopwhile:
    while(t--)
    {

        let a_b_c = readLine().trim().split(" ").map(x=>parseInt(x));

        //console.log("a_b_c " + a_b_c)
        let min = Math.min(...a_b_c);
        let max = Math.max(...a_b_c);

        /*console.log("min " + min)
        console.log("max " + max)*/

        let medium = a_b_c.filter(x=>(x!=min)&&(x!=max))[0]

        //console.log("medium " + medium)

        console.log(medium)
    }
}

'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 testCases = Number(readline());
    for (let i = 0; i < testCases; i++) {
        let arr = readline().split(" ").map(elem => Number(elem));
        console.log(findMedium(arr))
    }
}

function findMedium(arr) {
    arr.sort((a, b) => a - b)
    return arr[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 arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(arr) {
    arr.sort((a, b) => a - b)
    return arr[1]
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var list = nextIntArray(3);
		list.sort(function(a,b){
			return a - b;
		});
		myout(list[1]);
	}
}

t = +readline()

while(t--) {
    abc = readline().split(' ').map(value => +value).sort((a, b) => a - b)
    print(abc[1])
}

var t = +readline();

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

      var nums = [];
    var arr = readline().split(' ')

    print(ThreeNum(arr[0],arr[1],arr[2]))

}

function ThreeNum(a,b,c){
        a = +a
        b = +b
        c = +c

    return [a,b,c].sort((a,b) => a-b)[1]
}

var t = readline();

for(tt=0;tt<t;tt++){
    var arr = readline().split(' ');
    arr[0] = parseInt(arr[0])
    arr[1] = parseInt(arr[1])
    arr[2] = parseInt(arr[2])
    var x = arr[0] + arr[1] + arr[2];
    print(x - Math.min(arr[0],arr[1],arr[2]) - Math.max(arr[0],arr[1],arr[2]));
}

'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 testNumbers = readline()

    for(let i = 0; i<testNumbers; i++){
        solve(readline().split(" ").map(x=>parseInt(x)))
    }
}

function solve(input){
    let max = 0;
    let min = 21;
    for(let i = 0; i<3; i++){
        max = input[1] > max ? input[i] : max;
        min = input[i] < min ? input[i] : min;
    }
    console.log(
        input.filter(x=>x != max && x != min)[0]
    )
}

t = +readline()

while(t--) {
    abc = readline().split(' ').map(value => +value).sort()
    print(abc[1])
}


You are given $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ and an integer $$$k$$$. Find the maximum value of $$$i \cdot j - k \cdot (a_i | a_j)$$$ over all pairs $$$(i, j)$$$ of integers with $$$1 \le i < j \le n$$$. Here, $$$|$$$ is the bitwise OR operator.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains two integers $$$n$$$ ($$$2 \le n \le 10^5$$$) and $$$k$$$ ($$$1 \le k \le \min(n, 100)$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le n$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.

For each test case, print a single integer  — the maximum possible value of $$$i \cdot j - k \cdot (a_i | a_j)$$$.

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

const INF = 1e9;

function main () {
	let T = rn();
	while (T--) {
		const [n, k] = rna();
		const a = rna();
		a.unshift(0);

		let ans = -INF;
		for (let i = n; i > Math.max(0, n-2*k); i--) {
			for (let j = i-1; j > Math.max(0, n-2*k); j--) {
				const cur = i*j - k*(a[i]|a[j]);
				ans = Math.max(ans, cur);
			}
		}

		console.log(ans);
	}
}

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

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

const INF = 1e9;

function main () {
	let T = rn();
	while (T--) {
		const [n, k] = rna();
		const a = rna();
		a.unshift(0);

		let ans = -INF;
		for (let i = n; i >= Math.max(1, n-k-5); i--) {
			for (let j = i-1; j >= Math.max(1, n-k-5); j--) {
				const cur = i*j - k*(a[i]|a[j]);
				ans = Math.max(ans, cur);
			}
		}

		console.log(ans);
	}
}

const readline = require('readline')

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

function solve(n, k, arr) {
    let max = -Infinity
    const limit = 2 * k + 1
    for (let i = 0; i < limit; i++) {
        for (let j = 0; j < limit; j++) {
            if (i === j) continue

            const a = n - 1 - i
            const b = n - 1 - j
            if (a < 0 || b < 0) continue
            const v = (a + 1) * (b + 1) - k * (arr[a] | arr[b])
            // console.log(i, j, v)
            max = Math.max(max, v)
        }
    }
    return max
}

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

const INF = 1e9;

function main () {
	let T = rn();
	while (T--) {
		const [n, k] = rna();
		const a = rna();
		a.unshift(0);

		let ans = -INF;
		for (let i = n; i >= Math.max(1, n-k); i--) {
			for (let j = i-1; j >= Math.max(1, n-k); j--) {
				const cur = i*j - k*(a[i]|a[j]);
				ans = Math.max(ans, cur);
			}
		}

		console.log(ans);
	}
}

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

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

const INF = 1e9;

function main () {
	let T = rn();
	while (T--) {
		const [n, k] = rna();
		const a = rna();
		a.unshift(0);

		let ans = -INF;
		for (let i = n; i >= Math.max(1, n-k-5); i--) {
			for (let j = i-1; j >- Math.max(1, n-k-5); j--) {
				const cur = i*j - k*(a[i]|a[j]);
				ans = Math.max(ans, cur);
			}
		}

		console.log(ans);
	}
}

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

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

const INF = 1e9;

function main () {
	let T = rn();
	while (T--) {
		const [n, k] = rna();
		const a = rna();
		a.unshift(0);

		let ans = -INF;
		for (let i = n; i > n-k; i--) {
			for (let j = i-1; j > n-k; j--) {
				const cur = i*j - k*(a[i]|a[j]);
				ans = Math.max(ans, cur);
			}
		}

		console.log(ans);
	}
}


Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.

The first line contains two integers n, m (1 ≤ n, m ≤ 100) — the number of streets and avenues in Munhattan. Each of the next n lines contains m integers cij (1 ≤ cij ≤ 109) — the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.

Print the only integer a — the cost of the dinner for Jack and Emma.

NoteIn the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.

function cmp(a,b){return a-b;}

s=readline().split(' ')
n=+s[0]
m=+s[1]
res=0
while(n--)
{
    a=readline().split(' ')
    a.sort(cmp)
    if (+a[0]>res)
    {
        res=+a[0]
    }
}
print(res)

main.apply(0, readNums());
function main(n, m) {
    var max = 0;
    for (var i = 0; i < n; i++) {
        var v = min(readNums());
        if (v > max)
            max = v;
    }
    print(max);
}
function readNums() {
    return readline().split(' ').map(function(v) {
        return v - 0;
    })
}
function min(arr) {
    var v = arr[0];
    for (var i = 1; i < arr.length; i++) {
        if (v > arr[i])
            v = arr[i];
    }
    return v;
}


Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows:   if a word was written by one person — that person gets 3 points,  if a word was written by two people — each of the two gets 1 point,  if a word was written by all — nobody gets any points.  In the end, how many points does each player have?

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.

For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.

3

1

abc

def

abc

3

orz for qaq

qaq orz for

cod for ces

5

iat roc hem ica lly

bac ter iol ogi sts

bac roc lly iol iat

NoteIn the first test case:   The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point.  The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.

var t = parseInt(readline());

var calc = (ob1, ob2, ob3) => {
    var res = 0;
    for(var k in ob1){
        if(!ob2[k] && !ob3[k]) res += 3;
        else if (!ob2[k] || !ob3[k] ) res += 1;
    }

    return res;
};

var toObj = (r) => {
    var obj = {}
    for(var i = 0; i < r.length; i++){
        obj[r[i]] = true
    }
    return obj
}

while(t--){
    var n = parseInt(readline());
    var r1 = readline().split(" ");
    var r2 = readline().split(" ");
    var r3 = readline().split(" ");

    var ob1 = toObj(r1);
    var ob2 = toObj(r2);
    var ob3 = toObj(r3);

    var res1 = calc(ob1, ob2, ob3);
    var res2 = calc(ob2, ob1, ob3);
    var res3 = calc(ob3, ob2, ob1);

    print(res1 + " " + res2 + " " + res3);

}

(function main(){

    var t = readline();
    while(t--){
        var num = readline();
        var word = [];
        var obj = {

        }
        for(var i=0;i<3;i++){
            word[i] = readline().split(' ');
            for(var j=0;j<num;j++){
                if(typeof obj[word[i][j]] === 'undefined'){
                    obj[word[i][j]] = 1;
                }else{
                    obj[word[i][j]]++;
                }
            }
        }
        var result = "";

        for(var i=0;i<3;i++){
            var sum = 0;
            for(var j=0;j<num;j++){
                if(obj[word[i][j]]==1){
                    sum+=3;
                }else if(obj[word[i][j]]==2){
                    sum+=1;
                }
            }
            if(i){
                result=result+" "+sum;
            }else{
                result=result+sum;
            }
        }
        print(result);

    }

})();

var limit = parseInt(readline());
    for (var i = 0; i < limit; i++) {
        var caseLength = parseInt(readline());
        var firstArray = readline().split(" ");
        var secondArray = readline().split(" ");
        var thirdArray = readline().split(" ");
        var firstMap = new Map();
        var secondMap = new Map();
        var thirdMap = new Map();
        for (var j = 0; j < caseLength; j++) {
            firstMap.set(firstArray[j], 1);
            secondMap.set(secondArray[j], 1);
            thirdMap.set(thirdArray[j], 1);
        }
        var firstTotal = 0;
        var secondTotal = 0;
        var thridTotal = 0;
        for (var j = 0; j < caseLength; j++) {
            if (!secondMap.has(firstArray[j]) && !thirdMap.has(firstArray[j])) {
                firstTotal += 3;
            }
            else if ((!secondMap.has(firstArray[j]) && thirdMap.has(firstArray[j])) ||
                (secondMap.has(firstArray[j]) && !thirdMap.has(firstArray[j]))) {
                firstTotal++;
            }
            if (!firstMap.has(secondArray[j]) && !thirdMap.has(secondArray[j])) {
                secondTotal += 3;
            }
            else if ((!firstMap.has(secondArray[j]) && thirdMap.has(secondArray[j])) ||
                (firstMap.has(secondArray[j]) && !thirdMap.has(secondArray[j]))) {
                secondTotal++;
            }
            if (!firstMap.has(thirdArray[j]) && !secondMap.has(thirdArray[j])) {
                thridTotal += 3;
            }
            else if ((firstMap.has(thirdArray[j]) && !secondMap.has(thirdArray[j])) ||
                (!firstMap.has(thirdArray[j]) && secondMap.has(thirdArray[j]))) {
                thridTotal++;
            }
        }
        print("".concat(firstTotal, " ").concat(secondTotal, " ").concat(thridTotal));
    }

var t = parseInt(readline());

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

    var ans = [];

    var arr = pl1.concat(pl2).concat(pl3);
    var map = new Map();

    for (var i = 0; i < 3 * n; i++) {
        var mapEl = map.get(arr[i]);
        if (!mapEl) {
            map.set(arr[i], 1);
        } else {
            map.set(arr[i], mapEl + 1);
        }
    }

    var counter = pl => {
        var count = 0;

        for (var i = 0; i < n; i++) {
            if (map.get(pl[i]) === 1) {
                count += 3;
            } else if (map.get(pl[i]) === 2) {
                count += 1;
            }
        }

        return count;
    }

    ans.push(counter(pl1));
    ans.push(counter(pl2));
    ans.push(counter(pl3));

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

var n, a;

    var tests = parseInt(readline());
    for (var t=0; t<tests;t++) {
        n = parseInt(readline());
        a = [];
        for (var i = 0; i < 3; i++) {
            a.push(readline().split(' '));
        }
        var m = {};
        for (var i = 0; i < n; i++) {
            for (var j = 0; j < 3; j++) {
                if (!m[a[j][i]]) {
                    m[a[j][i]] = 0;
                }
                m[a[j][i]]++;
            }
        }
        var ans = [0, 0, 0];
        for (var i = 0; i < n; i++) {
            for (var j = 0; j < 3; j++) {
                var c = m[a[j][i]];
                if (c == 1) {
                    ans[j] += 3;
                } else if (c == 2) {
                    ans[j] += 1;
                }
            }
        }

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

var t = +readline();

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

      var nums = [];
    var t1 = +readline();
    var list = [];
    var arr1 = readline().split(' ');
    var arr2 = readline().split(' ');
    var arr3 = readline().split(' ');

    print(WordGame(arr1,arr2,arr3))

}

function WordGame(arr1,arr2,arr3){

    var set1 = new Set();
    var set2 = new Set();
    var set3 = new Set();

    for(var i = 0; i<arr1.length; i++){
        set1.add(arr1[i])
        set2.add(arr2[i])
        set3.add(arr3[i]);
    }

    var c1 = 0;
    var c2 = 0;
    var c3 = 0;
    for(var each of arr1){
        var test = set2.has(each) + set3.has(each)
        if (test === 1) c1 += 1;
        if (test === 0) c1 += 3;
    }
    for(var each1 of arr2){
        var test1 = set1.has(each1) + set3.has(each1)
        if (test1 === 1) c2 += 1;
        if (test1 === 0) c2 += 3;
    }
    for(var each2 of arr3){
        var test2 = set1.has(each2) + set2.has(each2)
        if (test2 === 1) c3 += 1;
        if (test2 === 0) c3 += 3;
    }
    return [c1,c2,c3].join(' ');
}

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

let lines = []

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

rl.on('line', line => lines.push(line))
rl.on('close', () => {
  const readLine = createReadLine();
  let t = parseInt(readLine())
  while (t--) {
    let words = {}
    let n = readLine()
    for (let i = 0; i < 3; i++){
      let playerWords = readLine().split(' ')
      for (const word of playerWords) {
        if (words[word]) {
          words[word].push(i)
        } else {
          words[word] = [i]
        }
      }
    }

    let result = {
      0: 0,
      1: 0,
      2: 0,
    };

    for (const word in words) {
      if (words.hasOwnProperty(word)) {
        if (words[word].length === 1) {
          result[words[word][0]] += 3
        } else if (words[word].length === 2) {
          result[words[word][0]] += 1
          result[words[word][1]] += 1
        }
      }
    }

    console.log(result['0'], result['1'], result['2'])
  }
})

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

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

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

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

        let a = readline().split(' ');
        let b = readline().split(' ');
        let c = readline().split(' ');

        let arr = [...a, ...b, ...c];

        let freq = {};
        for (let i = 0; i < arr.length; i++) {
            if (freq[arr[i]]) {
                freq[arr[i]]++;
            } else {
                freq[arr[i]] = 1;
            }
        }

        const val = word => {
            if (freq[word] === 1) {
                return 3;
            } else if (freq[word] === 2) {
                return 1;
            } else if (freq[word] === 3) {
                return 0;
            }
        };

        let sa = a.reduce((acc, curr) => acc + val(curr), 0);
        let sb = b.reduce((acc, curr) => acc + val(curr), 0);
        let sc = c.reduce((acc, curr) => acc + val(curr), 0);

        output(`${sa} ${sb} ${sc}`);
    }
}

'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 numberOfTest = Number.parseInt(readline());
    for(let i=0; i<numberOfTest; i++){
        readline();
        const str1 = readline();
        const str2 = readline();
        const str3 = readline();
        Solution(str1, str2, str3);
    }
}

function Solution(s1, s2, s3){
    const frqncy = {};
    const s1Words = s1.split(" ");
    const s2Words = s2.split(" ");
    const s3Words = s3.split(" ");
    s1Words.forEach(word => {
        if(frqncy[word]){
            frqncy[word] = frqncy[word]+1
        } else {
            frqncy[word]= 1;
        }
    });
    s2Words.forEach(word => {
        if(frqncy[word]){
            frqncy[word] = frqncy[word]+1
        } else {
            frqncy[word]= 1;
        }
    });
    s3Words.forEach(word => {
        if(frqncy[word]){
            frqncy[word] = frqncy[word]+1
        } else {
            frqncy[word]= 1;
        }
    });
    const s1Count = s1Words.reduce((acc, curr)=> {
        if(frqncy[curr] == 2){
            acc += 1
        }else if(frqncy[curr] == 1){
            acc += 3
        }
        return acc;
    }, 0);
    const s2Count = s2Words.reduce((acc, curr)=> {
        if(frqncy[curr] == 2){
            acc += 1
        }else if(frqncy[curr] == 1){
            acc += 3
        }
        return acc;
    }, 0);

    const s3Count = s3Words.reduce((acc, curr)=> {
        if(frqncy[curr] == 2){
            acc += 1
        }else if(frqncy[curr] == 1){
            acc += 3
        }
        return acc;
    }, 0);
    console.log(`${s1Count} ${s2Count} ${s3Count}`);
}

let readline = require("readline");
const { start } = require("repl");

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

let input = [];
rl.on("line", function (line) {
  input.push(line);

  if (input.length === +input[0] * 4 + 1) {
    // call your function here
    solve(input);
    rl.close();
  }
});

let solve = (input) => {
  //console.log(input[1 + 1].split(" "));

  for (let i = 1; i < input.length; i += 4) {
    let words1 = input[i + 1].split(" ");
    let words2 = input[i + 2].split(" ");
    let words3 = input[i + 3].split(" ");

    let words1Map = {};
    let words2Map = {};
    let words3Map = {};

    for (const word of words1) {
      words1Map[word] = true;
    }

    for (const word of words2) {
      words2Map[word] = true;
    }
    for (const word of words3) {
      words3Map[word] = true;
    }

    let score1 = 0;
    let score2 = 0;
    let score3 = 0;

    for (const word of words1) {
      if (words2Map[word] && words3Map[word]) continue;
      else if (words2Map[word] || words3Map[word]) score1++;
      else score1 += 3;
    }

    for (const word of words2) {
      if (words1Map[word] && words3Map[word]) continue;
      else if (words1Map[word] || words3Map[word]) score2++;
      else score2 += 3;
    }

    for (const word of words3) {
      if (words1Map[word] && words2Map[word]) continue;
      else if (words1Map[word] || words2Map[word]) score3++;
      else score3 += 3;
    }

    console.log(`${score1} ${score2} ${score3}`);
  }
};

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

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

// DO NOT CHANGE TEMPLATE BEFORE

const Def = Number(1e9);

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

    return ok;
}

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

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

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

    return ok;
}

const Solve = () =>
{
    let map1 = new Map();
    let map2 = new Map();
    let map3 = new Map();

    let n = +sc.L();
    let l1 = sc.L().split(' ');
    let l2 = sc.L().split(' ');
    let l3 = sc.L().split(' ');
    let map = new Map();

    for (let s of l1)
    {
        map1.set(s, 1);

        if (map.has(s))
        {
            map.set(s, map.get(s) + 1);
        }
        else map.set(s, 1);
    }

    for (let s of l2)
    {
        map2.set(s, 2);

        if (map.has(s))
        {
            map.set(s, map.get(s) + 1);
        }
        else map.set(s, 1);
    }

    for (let s of l3)
    {
        map3.set(s, 3);

        if (map.has(s))
        {
            map.set(s, map.get(s) + 1);
        }
        else map.set(s, 1);
    }

    let one = 0, two = 0, three = 0;
    for (let [key, value] of map)
    {
        let c = 0;

        if (map1.has(key))
        {
            ++c;
        }

        if (map2.has(key)) ++c;

        if (map3.has(key)) ++c;

        if (c === 2)
        {
            if (map1.has(key)) ++one;
            if (map2.has(key)) ++two;
            if (map3.has(key)) ++three;
        }
        else if (c === 1)
        {
            if (map1.has(key)) one += 3;
            if (map2.has(key)) two += 3;
            if (map3.has(key)) three += 3;
        }
    }

    console.log(`${one} ${two} ${three}`);

}

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

    // Solve();
}
main();

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var map = {};
		var one = nextStrArray(N);
		var two = nextStrArray(N);
		var three = nextStrArray(N);
		var oneP = 0;
		var twoP = 0;
		var threeP = 0;
		for(var i = 0; i < N; i++){
			if(map[one[i]] == null){
				map[one[i]] = 0;
			}
			map[one[i]]++;
			if(map[two[i]] == null){
				map[two[i]] = 0;
			}
			map[two[i]]++;
			if(map[three[i]] == null){
				map[three[i]] = 0;
			}
			map[three[i]]++;
		}
		for(var i = 0; i < N; i++){
			if(map[one[i]] == 1){
				oneP += 3;
			}else if(map[one[i]] == 2){
				oneP++;
			}
			if(map[two[i]] == 1){
				twoP += 3;
			}else if(map[two[i]] == 2){
				twoP++;
			}
			if(map[three[i]] == 1){
				threeP += 3;
			}else if(map[three[i]] == 2){
				threeP++;
			}
		}
		myout(oneP + " " + twoP + " " + threeP);
	}
}

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

function solve(n, arr) {
    const map = {}
    for (let i = 0; i < arr.length; i++) {
        for (let j = 0; j < arr[i].length; j++) {
            const s = arr[i][j]
            map[s] = (map[s] || 0) + 1
        }
    }
    // return [n, arr]
    // console.log(map)
    return arr.map(x => {
        let p = 0
        for (let i = 0; i < x.length; i++) {
            const s = x[i]
            if (map[s] === 1) {
                p += 3
            } else if (map[s] === 2) {
                p += 1
            }
        }
        return p
    }).join(' ')
}


Not so long ago, Vlad had a birthday, for which he was presented with a package of candies. There were $$$n$$$ types of candies, there are $$$a_i$$$ candies of the type $$$i$$$ ($$$1 \le i \le n$$$).Vlad decided to eat exactly one candy every time, choosing any of the candies of a type that is currently the most frequent (if there are several such types, he can choose any of them). To get the maximum pleasure from eating, Vlad does not want to eat two candies of the same type in a row.Help him figure out if he can eat all the candies without eating two identical candies in a row.

The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of input test cases. The following is a description of $$$t$$$ test cases of input, two lines for each. The first line of the case contains the single number $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of types of candies in the package. The second line of the case contains $$$n$$$ integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — the number of candies of the type $$$i$$$. It is guaranteed that the sum of $$$n$$$ for all cases does not exceed $$$2 \cdot 10^5$$$.

Output $$$t$$$ lines, each of which contains the answer to the corresponding test case of input. As an answer, output "YES" if Vlad can eat candy as planned, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

NoteIn the first example, it is necessary to eat sweets in this order: a candy of the type $$$2$$$, it is the most frequent, now $$$a = [2, 2]$$$; a candy of the type $$$1$$$, there are the same number of candies of the type $$$2$$$, but we just ate one, now $$$a = [1, 2]$$$; a candy of the type $$$2$$$, it is the most frequent, now $$$a = [1, 1]$$$; a candy of the type $$$1$$$, now $$$a = [0, 1]$$$; a candy of the type $$$2$$$, now $$$a = [0, 0]$$$ and the candy has run out.In the second example, all the candies are of the same type and it is impossible to eat them without eating two identical ones in a row.In the third example, first of all, a candy of the type $$$2$$$ will be eaten, after which this kind will remain the only kind that is the most frequent, and you will have to eat a candy of the type $$$2$$$ again.

var t = readline();
    for(var i = 0 ; i < t ; i++){
        var n = readline(),
            a = readline().split(' ').sort((a,b)=>{return(a - b)}).reverse();
            if(n == 1 && a[0] > 1){
                print("NO");
            }
            else if(a[0] - a[1] > 1){
                    print('NO');
                }
            else{
                print('YES');
            }
    }

var tests = parseInt(readline());
    for (var t=0; t < tests; t++) {
        var n = parseInt(readline());
        var a = readline().split(' ').map(x=>parseInt(x));
        var ans = 'YES';
        if (n == 1) {
            if (a[0] != 1) {
                ans = 'NO'
            }
        } else {
            var max = Math.max(...a);
            a.splice(a.indexOf(max), 1);
            var second = Math.max(...a);
            if (max - second > 1) {
                ans = 'NO'
            }
        }
        print(ans);
    }

var t = readline();

for (var i = 0; i < t; i++) {
  var n = readline();
  var c = readline().split(' ').map(Number);
  c.sort((a,b) => b - a);

  if (c[0] - c[1] <= 1 || c[0] === 1) print('YES');
  else {
    print('NO');
  }
}

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var t = lines[0];
    var e = 0;
    for(i = 1; i <= t * 2; i++){
        var k = lines[i].split(' ').map(Number).sort(function(a, b){return b - a});
        if(i % 2 == 1){
            e = k[0];
        }else{
            console.log(k[0] - k[1] < 2 || e == 1 && k[0] == 1? 'YES' : 'NO');
        }
    }
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

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

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

    for (let test = 0; test < N; test++) {
        let n = parseInt(readline(), 10);
        let arr = readline().split(' ').map(Number);

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

        if (arr.length === 1 && arr[0] > 1) {
            output('NO');
        } else if (arr[0] - 1 > arr[1]) {
            output('NO');
        } else {
            output('YES');
        }
    }
}

process.stdin.resume();
process.stdin.setEncoding("ascii");

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on("data", function (data) {
  input_stdin += data;
});

process.stdin.on("end", function () {
  input_stdin_array = input_stdin.split("\n");
  // console.log(input_stdin_array);
  main();
});

function readLine() {
  return input_stdin_array[input_currentline++];
}

function main() {
  var a = readLine();
  while (a--) {
    var b = readLine();
    var c = readLine();
    var res = solveMeFirst(b, c);
    // let out = "";
    // if (res) {
    //   for (let i = 0; i < res.length; i++) {
    //     out += res[i] + " ";
    //   }
    console.log(res);
    // }
  }
}
function solveMeFirst(n, arr) {
  arr = arr.split(" ");
  arr[arr.length - 1] = arr[arr.length - 1].replace("\r", "");
  arr.sort((a, b) => +a - +b);
  if (arr.length > 1) {
    if (
      +arr[arr.length - 1] - +arr[arr.length - 2] == 1 ||
      +arr[arr.length - 1] - +arr[arr.length - 2] == 0
    ) {
      return "YES";
    } else {
      return "NO";
    }
  } else {
    if (+arr[0] == 1) return "YES";
    else return "NO";
  }
}

// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));
// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		list.sort(function(a,b){
			return b - a;
		});
		var max = list[0];
		if(N == 1){
			if(max > 1){
				myout("NO");
			}else{
				myout("YES");
			}
		}else{
			var nx = list[1];
			if(max > nx + 1){
				myout("NO");
			}else{
				myout("YES");
			}
		}
	}
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main(){
	let t = parseInt(readLine());
	while(t--){
		let n = parseInt(readLine());
		let ans = true;
		const arr = readLine().split(' ');
		if(n == 1){
			if(parseInt(arr[0]) > 1)console.log("NO");
			else console.log("YES");
			continue;
		}
		arr.sort(function(a, b){return b - a});
		if(arr[0] - 1 > arr[1])ans = false;
		console.log((ans? "YES" : "NO"));
	}

}

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 N = readLine();
  for (let i = 0; i < N; i++) {
    const n = Number(readLine());
    const arr = readLine().split(' ').map(Number);
    arr.sort((x, y) => x - y);
    if (n === 1) {
      console.log(arr[0] === 1 ? 'YES' : 'NO');
    } else {
      console.log(arr[arr.length - 1] - arr[arr.length - 2] >=2 ? 'NO' : 'YES');
    }
  }
}

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

let inputString = "";
let currentLine = 0;

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

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

  main();
});

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

function main() {
  let t = parseInt(readLine());

  for (let i = 0; i < t; i++) {
    let n = parseInt(readLine());
    let arr = readLine().split(" ").map(Number);
    arr.sort((a, b) => a - b);

    if (n == 1) {
      if (arr[0] > 1) {
        console.log("NO");
      } else {
        console.log("YES");
      }
    } else {
      if (arr[n - 2] + 1 < arr[n - 1]) {
        console.log("NO");
      } else {
        console.log("YES");
      }
    }
  }
}

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

let stepeni = [1, 2]
let stepen = function (n) {
    if (stepeni[n]) return stepeni[n];
    let l = stepeni.length - 1;
    while (l < n) {
        stepeni.push(2 * stepeni[l++]);
    }
    return stepeni[n];
}

let parser = e=>parseInt(e);
let sorter = (a,b)=>a-b;

function main() {
    let k = parseInt(readLine());
    for(let i = 0; i<k;i++){
        let n = parseInt(readLine());
        let niz = readLine().split(" ").map(parser).sort(sorter);
        let sme = 1;
        let preth = niz.pop();
        let flag = true;
        if(n==1){
            flag = (preth==1);
        }
        else {
            while(niz.length>0){
                let br = niz.pop();
                if(preth-br>sme){
                    flag = false;
                    break;
                }
                sme+=br;
                preth = br;
            }
        }
        console.log(flag?"YES":"NO");
    }
}

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

const n = Number(inputs[0])

main(n, inputs)

function main(_, lines) {
  let res = []
  next: for (let i = 0; i < _; i++) {
    const n = Number(lines[i * 2 + 1])
    const data = lines[i * 2 + 2].trim().split(' ').map(Number)

    data.sort((a, b) => b - a)
    if ((data.length === 1 && data[0] > 1) || data[0] > data[1] + 1) {
      res.push('NO')
    } else {
      res.push('YES')
    }
  }

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

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) ? 'YES' : 'NO'
    }
    console.log(output.join('\n'))
// })()
})

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

    arr.sort((a, b) => b - a)
    return arr[0] - arr[1] <= 1
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
function readLine() {
    return inputString[currentLine++];
};
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    main();
    // cmd(not powershell): node cp.js < input.txt
});

function main() {
    let t = parseInt(readLine());
    while (t-- > 0) {
        console.log(solve());
    }
}
function solve() {
    const t = parseInt(readLine());
    const arr = readLine().split(" ").map(i => parseInt(i)).sort((a, b) => a - b);
    let last = arr[arr.length - 1]
    if (t == 1 && last > 1) return "NO";
    if (t == 1 && last == 1) return "YES";
    if ((last - arr[arr.length - 2]) > 1) return "NO"
    return "YES";
}

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

module.exports = E;

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

const EPS = 1e-6;

const calc = (arr, n)=>{
  arr.sort((a, b)=>b-a);
  if (n==1)
    return arr[0]==1;
  return arr[0]-arr[1]<2;
  for (let i=0; i<n-1; i++){
    if (arr[i]>arr[i+1]+1)
      return false;
    arr[i+1] = 0;
  }
  return true;
};

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

E.calc = calc;

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var t = lines[0];
    var e = 0;
    for(i = 1; i <= t * 2; i++){
        var k = lines[i].split(' ').map(Number).sort(function(a, b){return b - a});
        if(i % 2 == 1){
            e = k[0];
        }else{
            console.log(k[0] - k[1] < 2 || e == k[0] ? 'YES' : 'NO');
        }
    }
});


Phoenix has decided to become a scientist! He is currently investigating the growth of bacteria.Initially, on day $$$1$$$, there is one bacterium with mass $$$1$$$.Every day, some number of bacteria will split (possibly zero or all). When a bacterium of mass $$$m$$$ splits, it becomes two bacteria of mass $$$\frac{m}{2}$$$ each. For example, a bacterium of mass $$$3$$$ can split into two bacteria of mass $$$1.5$$$.Also, every night, the mass of every bacteria will increase by one.Phoenix is wondering if it is possible for the total mass of all the bacteria to be exactly $$$n$$$. If it is possible, he is interested in the way to obtain that mass using the minimum possible number of nights. Help him become the best scientist!

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^9$$$) — the sum of bacteria masses that Phoenix is interested in.

For each test case, if there is no way for the bacteria to exactly achieve total mass $$$n$$$, print -1. Otherwise, print two lines. The first line should contain an integer $$$d$$$  — the minimum number of nights needed. The next line should contain $$$d$$$ integers, with the $$$i$$$-th integer representing the number of bacteria that should split on the $$$i$$$-th day. If there are multiple solutions, print any.

NoteIn the first test case, the following process results in bacteria with total mass $$$9$$$:   Day $$$1$$$: The bacterium with mass $$$1$$$ splits. There are now two bacteria with mass $$$0.5$$$ each.  Night $$$1$$$: All bacteria's mass increases by one. There are now two bacteria with mass $$$1.5$$$.  Day $$$2$$$: None split.  Night $$$2$$$: There are now two bacteria with mass $$$2.5$$$.  Day $$$3$$$: Both bacteria split. There are now four bacteria with mass $$$1.25$$$.  Night $$$3$$$: There are now four bacteria with mass $$$2.25$$$.  The total mass is $$$2.25+2.25+2.25+2.25=9$$$. It can be proved that $$$3$$$ is the minimum number of nights needed. There are also other ways to obtain total mass 9 in 3 nights.$$$ $$$In the second test case, the following process results in bacteria with total mass $$$11$$$:   Day $$$1$$$: The bacterium with mass $$$1$$$ splits. There are now two bacteria with mass $$$0.5$$$.  Night $$$1$$$: There are now two bacteria with mass $$$1.5$$$.  Day $$$2$$$: One bacterium splits. There are now three bacteria with masses $$$0.75$$$, $$$0.75$$$, and $$$1.5$$$.  Night $$$2$$$: There are now three bacteria with masses $$$1.75$$$, $$$1.75$$$, and $$$2.5$$$.  Day $$$3$$$: The bacteria with mass $$$1.75$$$ and the bacteria with mass $$$2.5$$$ split. There are now five bacteria with masses $$$0.875$$$, $$$0.875$$$, $$$1.25$$$, $$$1.25$$$, and $$$1.75$$$.  Night $$$3$$$: There are now five bacteria with masses $$$1.875$$$, $$$1.875$$$, $$$2.25$$$, $$$2.25$$$, and $$$2.75$$$.  The total mass is $$$1.875+1.875+2.25+2.25+2.75=11$$$. It can be proved that $$$3$$$ is the minimum number of nights needed. There are also other ways to obtain total mass 11 in 3 nights.$$$ $$$In the third test case, the bacterium does not split on day $$$1$$$, and then grows to mass $$$2$$$ during night $$$1$$$.

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
/**
    3
    9
    11
    2
**/

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

    for(var r=0;r<range;r++) {
        let total = parseInt(readline());
        const b = [];
        const diff = [];
        let N = total;
        let i = 1;

        for(i=1;i<=total;i=i*2) {
            b.push(i);
            total = total - i;
        }

        if(total > 0) {
             b.push(total);
             b.sort((x,y) => x-y);
        }

        for(let i=1;i<b.length;i++) {
              diff.push(b[i] - b[i-1]);
        }

        console.log(diff.length);
        console.log(diff.join(" "));
    }
}