You are given an array $$$a_1, a_2, \dots a_n$$$. Count the number of pairs of indices $$$1 \leq i, j \leq n$$$ such that $$$a_i < i < a_j < j$$$.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \leq a_i \leq 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output a single integer — the number of pairs of indices satisfying the condition in the statement. Please note, that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).

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

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = iInpArr();
    let arr = iInpArr();
    let arr1 = new Array(arr.length).fill(0);
    let res = [];
    for (let i = 0; i < n; i++) {
      if (arr[i] < i + 1) {
        res.push(arr[i]);
        arr1[i] = 1;
      }
    }
    let psum = [],
      sum = 0;
    for (let i = 0; i < n; i++) {
      sum += arr1[i];
      psum[i] = sum;
    }
    let cnt = 0;
    for (let i = res.length - 1; i >= 0; i--) {
      let j = res[i] - 2;
      if (j >= 0) cnt += psum[j];
    }
    console.log(cnt);
  }
};
solve();

const readline = require('readline')

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

function solve(n, arr) {
    const good = []
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] < i + 1) {
            good.push(i)
        }
    }
    let p = 0
    good.sort((a, b) => arr[a] - arr[b])
// console.log(good)
    //
    let ans = 0
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] < i + 1) {
            // for good after now, how may i + 1 < arr[good[x]]
            // for (let j = 0; j < good.length; j++) {
            //     if (good[j] > i && i + 1 < arr[good[j]]) ans++
            // }
            while (p < good.length) {
                const j = good[p]
                if (i + 1 >= arr[j]) {
                    p++
                } else {
                    break
                }
            }
            ans += good.length - p
            // const j = binarySearch(0, good.length - 1, x => i + 1 >= arr[good[x]])
            // ans += good.length - (j + 1)
        }
    }
    return ans
}
function binarySearch(l, r, fn) {
    while (l <= r) {
        const m = Math.floor((l + r) / 2)
        if (fn(m)) {
            l = m + 1
        } else {
            r = m - 1
        }
    }
    return r
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

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

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

        let works = arr.map((val, index) => val < index + 1);

        let inLeft = new Array(n).fill(0);
        inLeft[inLeft.length - 1] = 0;
        for (let i = 0; i < n; i++) {
            inLeft[i] = (inLeft[i - 1] || 0) + (works[i - 1] ? 1 : 0);
        }

        let total = 0;
        for (let i = 1; i < n; i++) {
            if (arr[i] < i + 1) {
                total += inLeft[Math.max(Math.min(arr[i] - 1, i), 0)];
            }
        }

        output(total);
    }
}

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;
}
// console.log(input)
var T = readline();
var inf = 1000000000000;
for(var tc=1;tc<=T;tc++) {
  var n = readline()//.split(' ').map((x) => parseInt(x));
  var a = readline().split(' ').map((x) => parseInt(x));
  var s = [];
  var ans = BigInt(0);
  for(var i=0;i<n;i++) {
    if(a[i] < i+1) s.push([a[i], i+1])
  }
  for(var i=0;i<s.length;i++) {
    var L=0, R=s.length-1;
    var res = -inf;
    while(L<=R) {
      var mid = L+(Math.floor((R-L)/2))
      if(s[mid][1] < s[i][0]) {
        res = max(res, mid);
        L = mid+1;
      } else {
        R = mid-1;
      }
    }
    if(res !== -inf) {
      ans = BigInt(ans) + BigInt(res+1);
    }
  }
  var q = ""+ans;
  console.log(q)
}

var t = parseInt(readline());

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

    var part = [0];
    var ans = 0;

    for (var i = 0; i < arr.length; i++) {
        var isLess = arr[i] < i + 1;

        part.push(part[i] + isLess);

        if (isLess && arr[i] != 0) {
            ans += part[arr[i] - 1];
        }
    }

    print(ans);
}

var t = parseInt(readline());

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

    var part = [0];
    var ans = 0;

    for (var i = 0; i < arr.length; i++) {
        var isLess = arr[i] < i + 1;

        part.push(part[i] + isLess);

        if (isLess && arr[i] !== 0) {
            ans += part[arr[i] - 1];
        }
    }

    print(ans);
}

var t = parseInt(readline());

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

    var part = [0];
    var ans = 0;

    for (var i = 0; i < arr.length; i++) {
        var isLess = arr[i] < i + 1;

        part.push(part[i] + isLess);

        if (isLess) {
            ans += part[arr[i] - 1];
        }
    }

    print(ans);
}

var t = parseInt(readline());

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

    var part = [0];
    var ans = 0;

    for (var i = 0; i < arr.length; i++) {
        var isLess = arr[i] < i + 1;

        part.push(part[i] + isLess);

        if (isLess) {
            ans += part[arr[i]];
        }
    }

    print(ans);
}

var t = parseInt(readline());

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

    var part = [0];
    var ans = 0;

    for (var i = 0; i < arr.length; i++) {
        if (arr[i] < i + 1) {
            part.push(part[i] + 1);
            ans += part[arr[i]];
        }
    }

    print(ans);
}

var t = parseInt(readline());

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

    var part = [0];
    var ans = 0;

    var isLess = arr[i] < i + 1;

    for (var i = 0; i < arr.length; i++) {
        part.push(part[i] + isLess);
    }

    for (var i = 0; i < arr.length; i++) {
        if (isLess) {
            ans += part[arr[i]];
        }
    }

    print(ans);
}

var t = parseInt(readline());

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

    var part = [0];
    var ans = 0;

    var isLess = arr[i] < i + 1;

    for (var i = 0; i < arr.length; i++) {
        part.push(part[i] + isLess);

        if (isLess) {
            ans += part[arr[i]];
        }
    }

    print(ans);
}


Gregor is learning about RSA cryptography, and although he doesn't understand how RSA works, he is now fascinated with prime numbers and factoring them.Gregor's favorite prime number is $$$P$$$. Gregor wants to find two bases of $$$P$$$. Formally, Gregor is looking for two integers $$$a$$$ and $$$b$$$ which satisfy both of the following properties.  $$$P \bmod a = P \bmod b$$$, where $$$x \bmod y$$$ denotes the remainder when $$$x$$$ is divided by $$$y$$$, and  $$$2 \le a < b \le P$$$. Help Gregor find two bases of his favorite prime number!

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Each subsequent line contains the integer $$$P$$$ ($$$5 \le P \le {10}^9$$$), with $$$P$$$ guaranteed to be prime.

Your output should consist of $$$t$$$ lines. Each line should consist of two integers $$$a$$$ and $$$b$$$ ($$$2 \le a < b \le P$$$). If there are multiple possible solutions, print any.

NoteThe first query is $$$P=17$$$. $$$a=3$$$ and $$$b=5$$$ are valid bases in this case, because $$$17 \bmod 3 = 17 \bmod 5 = 2$$$. There are other pairs which work as well.In the second query, with $$$P=5$$$, the only solution is $$$a=2$$$ and $$$b=4$$$.

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

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

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t= nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		let p = nl.num();
		ans.push([2, p-1]);
	}
	console.log(ans.map(e => e.join(' ')).join('\n'));
};

process.stdin.on('end', sol);

'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 writeOutput(s) {
  process.stdout.write(s);
}

function main() {
  let t = parseInt(readline(), 10);
  while(t--) {
    let n = parseInt(readline(), 10);
    for (let i = 0; i*i < n; ++i) {
      let found = false;
      for (let a = Math.max(2, i+1); a*a < n; ++a) {
        if ((n-i) % a === 0 && (n-i) != a) {
          writeOutput(`${a} ${(n-i)}\n`);
          found = true;
          break;
        }
      }
      if (found) break;
    }
  }
}

// run: cat input.txt | node A.js

var fs = require("fs");
var stdinBuffer = fs.readFileSync(0); // STDIN_FILENO = 0

const lines = stdinBuffer.toString().match(/[^\r\n]+/g).slice(1);

const examples = [];

for(let i = 0; i < lines.length; i++) {
    examples.push(parseInt(lines[i], 10));
}

const solver = (n) => {
    return 2 + " " + (n-1).toString()
};

for(let example of examples) {
    console.log(solver(example))
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

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

function main() {
  const xx = readline();
  Array(Number(xx)).fill(1).map((t, i) => {
  var a = parseInt(readline());
  // var [n, m] = readline().split(' ').map((x, iii) => {
  //     return parseInt(x)
  //   })
    var answe = 2
    console.log(2, a-1)
  })
  // var res = new Array(n)
}

function plus(a, b, res) {
// console.log(a, b, res)
  if (a === 0) return res

  return plus(a < 0 ? a + 1 : a - 1, b, a < 0 ? res - b : res + b)
}

//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] = BigInt(next());
		}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 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 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 P = nextInt();
		var L = 2;
		var R = (P - 1);
		myout(L + " " + R);
	}
}

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

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

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

// ********** Code Start **********

function main() {
  let t;
t = parseInt(readline());
while (t--) {
  let n = parseInt(readline());
  console.log(2 + " " + (n - 1) );
}

}

const nextString = (function() {
  const listeners = [], strings = [], ps = process.stdin
  let last = ''
  ps.setEncoding('utf8')
  ps.on('readable', () => {
    let chunk
    while ((chunk = ps.read()) !== null) {
      chunk = (last + chunk).split(/\r\n|\r|\n/)
      last = chunk[chunk.length - 1]
      for (let i = 0; i < chunk.length - 1; ++i) {
        if (chunk[i].length > 0) {
          if (listeners.length > 0) {
            listeners.shift()(chunk[i])
          }
          else {
            strings.push(chunk[i])
          }
        }
      }
    }
  })
  const fn = resolve => {
    if (strings.length > 0) {
      resolve(strings.shift())
    }
    else {
      listeners.push(resolve)
    }
  }
  return () => new Promise(fn)
})()

function extend(mas) {
  let n = mas.length
  mas.unshift(new Array(n++).fill('.'))
  for (let i = 0; i < n; ++i) {
    mas[i].push('.')
  }
}

async function main() {
  let n = +await nextString()
  for (let i = 0; i < n; ++i) {
    let p = +await nextString()
    console.log(`2 ${p - 1}`)
  }
}

main()

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const assert = (condition) => { if (!condition) throw new Error("Assertion failed"); }
const mi = Math.min;
const mx = Math.max;
const mxll = (...args) => args.reduce((m, e) => e > m ? e : m);
const mill = (...args) => args.reduce((m, e) => e < m ? e : m);
const sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0
const abs = Math.abs;
const fl = Math.floor;
const int = parseInt;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg2 = Math.log2;
const lg10 = Math.log10;
const ll = BigInt;
const combination = (m, n) => { return factorial(m, n) / factorial(n, n); };
const factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };
const powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth
const initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };
const initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };
const stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));
const stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));
const stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));
const stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };
const counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };
const reverse2 = (s) => { let res = ""; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
const ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);
const isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 08/01/21 evening
 * https://codeforces.com/contest/1549/problem/A
 */
const solve = (p) => {
    pr(2, p - 1);
};

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

main()

let i = ''
let lines
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  lines = i.split('\n') // your input text, split by lines
  main()
})

function main() {
  let t = parseInt(lines.shift())

  while (t > 0) {
    const p = parseInt(lines.shift())

    if (p === 5) {
      console.log(2, 4)
    } else {
      console.log(2, (p - 1) / 2)
    }
    t--
  }
}

function solve(p) {
  if (p === 5) return [2, 4];
  return [2, parseInt(p / 2)];
}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
  p = parseInt(readline());
  var ans = solve(p);
  print(ans[0], ans[1]);
}

n = readline();
while(n--) {
  s = readline();
  print(2, s-1);
}

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

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    for(var j = 1; j <= n[0]; j++){
        var k = lines[j];

    }
    console.log(3 + ' ' + 5 + "\n" + 2 + ' ' + 4);
});

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

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t= nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		let p = nl.num();
		for(let j = 2; j <= p; j++){
			if (p%j == p%(j+2)){
				ans.push([j, j+2]);
				break;
			}
		}
	}
	console.log(ans.map(e => e.join(' ')).join('\n'));
};

process.stdin.on('end', sol);

'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 writeOutput(s) {
  process.stdout.write(s);
}

function main() {
  let t = parseInt(readline(), 10);
  while(t--) {
    let n = parseInt(readline(), 10);
    for (let i = 1; i*i < n; ++i) {
      let found = false;
      for (let a = i+1; a*a < n; ++a) {
        if ((n-i) % a === 0 && (n-i) / a != a) {
          writeOutput(`${a} ${(n-i)/a}\n`);
          found = true;
          break;
        }
      }
      if (found) break;
    }
  }
}

// run: cat input.txt | node A.js

var fs = require("fs");
var stdinBuffer = fs.readFileSync(0); // STDIN_FILENO = 0

const lines = stdinBuffer.toString().match(/[^\r\n]+/g).slice(1);

const examples = [];

for(let i = 0; i < lines.length; i++) {
    examples.push(parseInt(lines[i], 10));
}

const solver = (n) => {
    return 2 + " " + (n-1).toString()
};

for(let example of examples) {
    console.log(solver(example).length)
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

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

function main() {
  const xx = readline();
  Array(Number(xx)).fill(1).map((t, i) => {
  var a = parseInt(readline());
  // var [n, m] = readline().split(' ').map((x, iii) => {
  //     return parseInt(x)
  //   })
    var answe = 2
    for (let j = 2; j < 100; j++) {
      if(a %j === 1) answe = j
    }
    console.log(2, answe)
  // var a = readline().split(' ').map((x, iii) => {
  //   return parseInt(x)
  })
  // var res = new Array(n)
}

function plus(a, b, res) {
// console.log(a, b, res)
  if (a === 0) return res

  return plus(a < 0 ? a + 1 : a - 1, b, a < 0 ? res - b : res + b)
}

function solve(p) {
  if (p === 5) return [2, 3];
  return [2, parseInt(p / 2)];
}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
  p = parseInt(readline());
  var ans = solve(p);
  print(ans[0]+" "+ans[1]);
}

function solve(p) {
  if (p === 5) return [2, 3];
  var i = 2;

  while (true) {
    var a = i;
    var b = parseInt(p / i);
    if (a !== b && Math.max(a, b) <= p) return [Math.min(a, b), Math.max(a, b)];
    i++;
  }
}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
  p = parseInt(readline());
  var ans = solve(p);
  print(ans[0], ans[1]);
}

function solve(p) {
  if (p === 5) return [2, 3];
  var i = 2;

  while (true) {
    var a = i;
    var b = parseInt(p / i);
    if (Math.max(a, b) <= p) return [Math.min(a, b), Math.max(a, b)];
    i++;
  }
}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
  p = parseInt(readline());
  var ans = solve(p);
  print(ans[0], ans[1]);
}

function solve(p) {
  if (p === 5) return [2, 3];
  return [2, parseInt(p / 2)];
}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
  p = parseInt(readline());
  var ans = solve(p);
  print(ans[0], ans[1]);
}


Petya and Vasya are competing with each other in a new interesting game as they always do.At the beginning of the game Petya has to come up with an array of $$$N$$$ positive integers. Sum of all elements in his array should be equal to $$$S$$$. Then Petya has to select an integer $$$K$$$ such that $$$0 \leq K \leq S$$$.In order to win, Vasya has to find a non-empty subarray in Petya's array such that the sum of all selected elements equals to either $$$K$$$ or $$$S - K$$$. Otherwise Vasya loses.You are given integers $$$N$$$ and $$$S$$$. You should determine if Petya can win, considering Vasya plays optimally. If Petya can win, help him to do that.

The first line contains two integers $$$N$$$ and $$$S$$$ ($$$1 \leq N \leq S \leq 10^{6}$$$) — the required length of the array and the required sum of its elements.

If Petya can win, print "YES" (without quotes) in the first line. Then print Petya's array in the second line. The array should contain $$$N$$$ positive integers with sum equal to $$$S$$$. In the third line print $$$K$$$. If there are many correct answers, you can print any of them. If Petya can't win, print "NO" (without quotes). You can print each letter in any register (lowercase or uppercase).

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

const processData = (lines) => {
  const [n, s] = lines[0].split(' ').map(x => +x)
  if (n*2 > s) {
    console.log('NO')
  } else {
    console.log('YES')
    let t = s
    const res = []
    for (let i=0; i<n-1; i++) {
      res.push(2)
      t-= 2
    }
    res.push(t)
    console.log(res.join(' '))
    console.log(1)
  }
}

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

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

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


You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array.  It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array.

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

function Arr(a, b, step, fn, init) {
  if (!step) {
    return a < b
      ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))
      : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))
  }
  let arr = Array(Math.max(a, b) + 1).fill(0);
  if (init) init(arr);
  if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);
  else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);
  return arr;
}

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

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => {
//   return gt[n] * rgt[k] * rgt[n - k] % MOD;
// }
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

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

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let t = $()
  while (t--) {
    let n = $()
    let a = $(n)
    let c = Arr(0, n, 1, i => [-1]);
    For(0, n - 1, 1, i => { c[a[i]].push(i) });
    // log(c);
    let res = Array(n + 1).fill(-1);
    let k = n;
    For(1, n, 1, i => {
      if (c[i].length <= 1) return;
      c[i].push(n)
      // let maxk = Arr(1,c[i].length-1,1,j=>c[i][j]-1-c[i][j-1]).max()[0]
      // log(i,maxk);
      let maxk = 0;
      for (let j = 1; j < c[i].length; j++) maxk = max(maxk, c[i][j] - 1 - c[i][j - 1])
      while (k > 0 && k > maxk) res[k--] = i;
    })
    log(res.slice(1).join(' '))
  }
}

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

function Arr(a, b, step, fn, init) {
  if (!step) {
    return a < b
      ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))
      : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))
  }
  let arr = Array(Math.max(a, b) + 1).fill(0);
  if (init) init(arr);
  if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);
  else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);
  return arr;
}

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

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => {
//   return gt[n] * rgt[k] * rgt[n - k] % MOD;
// }
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

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

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let t = $()
  while (t--) {
    let n = $()
    let a = $(n)
    let c = Arr(0, n, 1, i => []);
    For(0, n - 1, 1, i => { c[a[i]].push(i) });
    // log(c);
    let res = Array(n + 1).fill(-1);
    let k = n;
    For(1, n, 1, i => {
      if (!c[i].length) return;
      c[i].push(n);
      let maxk = c[i].map((v, i, a) => i == 0 ? v : v - 1 - a[i - 1]).max()[0];
      while (k > 0 && k > maxk) res[k--] = i;
    })
    log(res.slice(1).join(' '))
  }
}

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

function Arr(a, b, step, fn, init) {
  if (!step) {
    return a < b
      ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))
      : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))
  }
  let arr = Array(Math.max(a, b) + 1).fill(0);
  if (init) init(arr);
  if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);
  else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);
  return arr;
}

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

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => {
//   return gt[n] * rgt[k] * rgt[n - k] % MOD;
// }
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

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

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let t = $()
  while (t--) {
    let n = $()
    let a = $(n)
    let c = Arr(0, n, 1, i => []);
    For(0, n - 1, 1, i => {
      c[a[i]].push(i);
    });
    // log(c);
    let res = Array(n + 1).fill(-1);
    let k = n;
    For(1, n, 1, i => {
      if (!c[i].length) return;
      let maxk = max(c[i][0], n - 1 - c[i][c[i].length - 1]);
      for (let j = 1; j < c[i].length; j++) maxk = max(maxk, c[i][j] - 1 - c[i][j - 1]);
      while (k > 0 && k > maxk) res[k--] = i;
    })
    log(res.slice(1).join(' '))
  }
}

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

function Arr(a, b, step, fn, init) {
  if (!step) {
    return a < b
      ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))
      : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))
  }
  let arr = Array(Math.max(a, b) + 1).fill(0);
  if (init) init(arr);
  if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);
  else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);
  return arr;
}

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

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => {
//   return gt[n] * rgt[k] * rgt[n - k] % MOD;
// }
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

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

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let t = $()
  while (t--) {
    let n = $()
    let a = $(n)
    let c = Arr(0, n, 1, i => [-1]);
    For(0, n - 1, 1, i => { c[a[i]].push(i) });
    // log(c);
    let res = Array(n + 1).fill(-1);
    let k = n;
    For(1, n, 1, i => {
      if (c[i].length <= 1) return;
      c[i].push(n)
      let maxk = Arr(1, c[i].length - 1, 0, j => c[i][j] - 1 - c[i][j - 1]).max()[0]
      // let maxk = 0;
      // for (let j = 0; j < a.length; j++) maxk = max(maxk, a[j])
      while (k > 0 && k > maxk) res[k--] = i;
    })
    log(res.slice(1).join(' '))
  }
}

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

function Arr(a, b, step, fn, init) {
  if (!step) {
    return a < b
      ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))
      : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))
  }
  let arr = Array(Math.max(a, b) + 1).fill(0);
  if (init) init(arr);
  if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);
  else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);
  return arr;
}

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

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => {
//   return gt[n] * rgt[k] * rgt[n - k] % MOD;
// }
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

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

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let t = $()
  while (t--) {
    let n = $()
    let a = $(n)
    let c = Arr(0, n, 1, i => [-1]);
    For(0, n - 1, 1, i => { c[a[i]].push(i) });
    // log(c);
    let res = Array(n + 1).fill(-1);
    let k = n;
    For(1, n, 1, i => {
      if (c[i].length <= 1) return;
      c[i].push(n)
      let a = Arr(1, c[i].length - 1, 1, j => c[i][j] - 1 - c[i][j - 1])
      let maxk = 0;
      for (let j = 0; j < a.length; j++) maxk = max(maxk, a[j])
      while (k > 0 && k > maxk) res[k--] = i;
    })
    log(res.slice(1).join(' '))
  }
}

'use strict';

var readline = require('readline');

function tTwoLinesPerStdin() {
  return new Promise(resolve => {
    const stdin = readline.createInterface(process.stdin);
    let t;
    let prevLine;
    let output = [];
    stdin.on('line', line => {
      if (typeof t !== 'number') {
        t = +line;
      } else {
        if (prevLine) {
          output.push([prevLine, line]);
          prevLine = undefined;

          if (output.length === t) {
            resolve(output);
            stdin.close();
          }
        } else {
          prevLine = line;
        }
      }
    });
  });
}

function solve(nums) {
  const track = new Map();

  for (let i = 0; i < nums.length; i++) {
    const element = nums[i];
    const t = track.get(element) || {
      maxSpace: 0,
      lastIndex: -1
    };
    const space = i - t.lastIndex;

    if (space > t.maxSpace) {
      t.maxSpace = space;
    }

    t.lastIndex = i;
    track.set(element, t);
  }

  for (const t of track.values()) {
    const space = nums.length - t.lastIndex;

    if (space > t.maxSpace) {
      t.maxSpace = space;
    }
  }

  const answerPrep = [];

  for (const [num, t] of track) {
    if (!answerPrep[t.maxSpace] || answerPrep[t.maxSpace] > num) {
      answerPrep[t.maxSpace] = num;
    }
  }

  const answer = [];
  let lastAnswer = -1;

  for (let i = 1; i <= nums.length; i++) {
    const element = answerPrep[i];

    if (element !== undefined && (lastAnswer === -1 || element < lastAnswer)) {
      lastAnswer = element;
    }

    answer.push(lastAnswer);
  }

  return answer;
}

async function main() {
  const input = await tTwoLinesPerStdin();

  for (let t = 0; t < input.length; t++) {
    const [line2] = input[t].slice(1);
    const answer = solve(line2.split(' ').map(Number));
    console.log(answer.join(' '));
  }
}

main().then();

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

function Arr(a, b, step, fn, init) {
  if (!step) {
    return a < b
      ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))
      : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))
  }
  let arr = Array(Math.max(a, b) + 1).fill(0);
  if (init) init(arr);
  if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);
  else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);
  return arr;
}

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

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => {
//   return gt[n] * rgt[k] * rgt[n - k] % MOD;
// }
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

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

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let t = $()
  while (t--) {
    let n = $()
    let a = $(n)
    let c = Arr(0, n, 1, i => []);
    For(0, n - 1, 1, i => {
      c[a[i]].push(i);
    });
    // log(c);
    let res = Array(n + 1).fill(-1);
    let k = n;
    For(1, n, 1, i => {
      if (!c[i].length) return;
      let maxk = c[i].map((v, i) => i == 0 ? v : v - a[i - 1] - 1).max()[0];
      maxk = max(maxk, n - 1 - c[i][c[i].length - 1]);
      // log(i,maxk);
      while (k > 0 && k > maxk) res[k--] = i;
    })
    log(res.slice(1).join(' '))
  }
}

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

function Arr(a, b, step, fn, init) {
  if (!step) {
    return a < b
      ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))
      : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))
  }
  let arr = Array(Math.max(a, b) + 1).fill(0);
  if (init) init(arr);
  if (step > 0) for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);
  else for (let i = a; i >= b; i += step) arr[i] = fn(i, arr);
  return arr;
}

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

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => {
//   return gt[n] * rgt[k] * rgt[n - k] % MOD;
// }
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

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

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let t = $()
  while (t--) {
    let n = $()
    let a = $(n)
    // let l = Array(n)
    // let r = Array(n)
    // l[0] = -1
    // For(1, n - 1, 1, i => {
    //   l[i] = i - 1;
    //   while (l[i] >= 0 && a[l[i]] >= a[i]) l[i] = l[l[i]];
    // })
    // r[n - 1] = n;
    // For(n - 2, 0, -1, i => {
    //   r[i] = i + 1;
    //   while (r[i] < n && a[r[i]] >= a[i]) r[i] = r[r[i]];
    // });
    let c = Arr(0, n, 1, i => []);
    For(0, n - 1, 1, i => {
      c[a[i]].push(i);
    });
    // log(c);
    let res = Array(n + 1).fill(-1);
    let k = n;
    For(1, n, 1, i => {
      if (!c[i].length) return;
      let maxk = c[i].map((v, i) => i == 0 ? v : v - a[i - 1]).max()[0];
      maxk = max(maxk, n - 1 - c[i][c[i].length - 1]);
      // log(i,maxk);
      while (k > 0 && k > maxk) res[k--] = i;
    })
    log(res.slice(1).join(' '))
  }
}


William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ is picked, which is then used to perform one of the following operations: (note, that for each operation you can choose a new positive integer $$$k$$$)  add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or  add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or  add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.

For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.

NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$:  Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$.  Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$.  Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$.  Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.

//Vismillahir Rahmanir Rahim (Allah hu Ackbar);

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

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

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});

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

// ************************ Code Start ***************************

function main() {

    var t = Number(readline());
    var ans = 0;
    while (t--) {

        var arr = readline().split(' ').map(x => parseInt(x));
        var a = arr[0],
            b = arr[1];

        if ((a + b) % 2 != 0) {
            ans = -1;
        } else if ((a + b == 0)) {
            ans = 0
        } else if (a == b) {
            ans = 1;
        } else {
            ans = 2;
        }
        console.log(ans);

    }
}

//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] = BigInt(next());
		}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 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 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 c = nextInt();
		var d = nextInt();
		if(Math.abs(c - d) % 2 == 1){
			myout(-1);
		}else if(Math.abs(c - d) == 0){
			if(c == 0 && d == 0){
				myout(0);
			}else{
				myout(1);
			}
		}else{
			myout(2);
		}
	}
}

'use strict'
var os = require('os')
function createInput(n) {
  const t = n.stdin || process.stdin,
    e = /-?\d+/g,
    r = /-?\d+(?:\.\d+)?/g
  let u = [],
    i = 0
  return {
    init: async function () {
      const n = []
      ;(u = await new Promise(e => {
        t.on('data', t => n.push(t)),
          t.on('end', function () {
            const t = n.join('').split(os.EOL)
            e(t)
          })
      })),
        (i = 0)
    },
    dried: function () {
      return i >= u.length
    },
    readLine: o,
    readLineAsNumber: function () {
      return Number(o())
    },
    readIntegersOfLine: function () {
      const n = o().match(e)
      return null == n ? [] : n.map(n => Number(n))
    },
    readNumsOfLine: function () {
      const n = o().match(r)
      return null == n ? [] : n.map(n => Number(n))
    },
  }
  function o() {
    return u[i++]
  }
}
function createOutput(n) {
  const t = n.stdout || process.stdout,
    e = n.encoding || 'ascii',
    r = n.outputBufferThreshold || 1 << 24,
    u = r >> 1,
    i = Buffer.alloc(r)
  let o = 0
  return {
    flush: s,
    print: function (n) {
      c('string' == typeof n ? n : n.toString())
    },
    println: function (n) {
      c(('string' == typeof n ? n : n.toString()).concat('\n'))
    },
  }
  function s() {
    t.write(i.toString(e, 0, o)), (o = 0)
  }
  function c(n) {
    const c = Buffer.byteLength(n, e)
    r - o < c && (s(), c > u) ? t.write(n) : (i.write(n, o, e), (o += c))
  }
}
function createInputAndOutput(n) {
  return {
    ...createInput({ stdin: n.stdin, encoding: n.encoding }),
    ...createOutput({
      stdout: n.stdout,
      encoding: n.encoding,
      outputBufferThreshold: n.outputBufferThreshold,
    }),
  }
}
async function __main__(n, t, e = {}) {
  const r = createInputAndOutput(e)
  await Promise.all([r.init(), Promise.resolve(t && t())]),
    await n(r),
    r.flush()
}
__main__(function (n) {
  const t = n.readLineAsNumber()
  for (let r = 1; r <= t; ++r) {
    const [t, r] = n.readIntegersOfLine(),
      u = e(t, r)
    n.println(u)
  }
  function e(n, t) {
    return 1 & Math.abs(n - t) ? -1 : n === t ? (0 === n ? 0 : 1) : 2
  }
})

//Vismillahir Rahmanir Rahim (Allah hu Ackbar);

// var t = Number(readline());
// var ans = 0;
// var k0 = 0;
// var k01 = 0;
// while (t--) {
//     var arr = readline().split(' ').map(x => parseInt(x));
//     var a = arr[0],
//         b = arr[1];
//     if (a > b) {
//         var temp = b;
//         b = a;
//         a = temp;
//     }
//     for (var i = 0; i <= 10000; i++) {
//         if (a < i) {
//             k0 = i - a;
//         } else {
//             k0 = a - i;
//         }
//         if (b < i) {
//             k01 = i - b;
//         } else {
//             k01 = b - i;
//         }
//         var k1 = a + i;
//         var k11 = b + i;
//         var k2 = a + i;
//         var k22 = k01;
//         var k3 = k0;
//         var k33 = b + i
//         if (a == 0 && b == 0) {
//             ans = 0;
//             break;
//         } else if (k1 == k11) {

//             ans = 1;
//             break;
//         } else if (k2 == k22) {
//             // console.log(k2 + " " + k22);
//             ans = 2;
//             break;
//         } else if (k3 == k33) {
//             ans = 3
//                 // console.log(k3 + " " + k33);
//             break;
//         } else {
//             ans = -1;
//         }
//     }
//     console.log(ans);

// }

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

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

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});

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

// ************************ Code Start ***************************

function main() {

    var t = Number(readline());
    var ans = 0;
    var k0 = 0;
    var k01 = 0;
    while (t--) {
        var arr = readline().split(' ').map(x => parseInt(x));
        var a = arr[0],
            b = arr[1];
        if (a > b) {
            var temp = b;
            b = a;
            a = temp;
        }
        for (var i = 0; i <= 10000; i++) {
            if (a < i) {
                k0 = i - a;
            } else {
                k0 = a - i;
            }
            if (b < i) {
                k01 = i - b;
            } else {
                k01 = b - i;
            }
            var k1 = a + i;
            var k11 = b + i;
            var k2 = a + i;
            var k22 = k01;
            var k3 = k0;
            var k33 = b + i
            if (a == 0 && b == 0) {
                ans = 0;
                break;
            } else if (k1 == k11) {

                ans = 1;
                break;
            } else if (k2 == k22) {
                // console.log(k2 + " " + k22);
                ans = 2;
                break;
            } else if (k3 == k33) {
                ans = 3
                    // console.log(k3 + " " + k33);
                break;
            } else {
                ans = -1;
            }
        }
        console.log(ans);

    }

}

//Vismillahir Rahmanir Rahim (Allah hu Ackbar);

// var t = Number(readline());
// var ans = 0;
// var k0 = 0;
// var k01 = 0;
// while (t--) {
//     var arr = readline().split(' ').map(x => parseInt(x));
//     var a = arr[0],
//         b = arr[1];
//     if (a > b) {
//         var temp = b;
//         b = a;
//         a = temp;
//     }
//     for (var i = 0; i < 1000000; i++) {
//         if (a < i) {
//             k0 = i - a;
//         } else {
//             k0 = a - i;
//         }
//         if (b < i) {
//             k01 = i - b;
//         } else {
//             k01 = b - i;
//         }
//         var k1 = a + i;
//         var k11 = b + i;
//         var k2 = a + i;
//         var k22 = k01;
//         var k3 = k0;
//         var k33 = b + i
//         if (a == 0 && b == 0) {
//             ans = 0;
//             break;
//         } else if (k1 == k11) {

//             ans = 1;
//             break;
//         } else if (k2 == k22) {
//             // console.log(k2 + " " + k22);
//             ans = 2;
//             break;
//         } else if (k3 == k33) {
//             ans = 3
//                 // console.log(k3 + " " + k33);
//             break;
//         } else {
//             ans = -1;
//         }
//     }
//     console.log(ans);

// }

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

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

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});

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

// ************************ Code Start ***************************

function main() {

    var t = Number(readline());
    var ans = 0;
    var k0 = 0;
    var k01 = 0;
    while (t--) {
        var arr = readline().split(' ').map(x => parseInt(x));
        var a = arr[0],
            b = arr[1];
        if (a > b) {
            var temp = b;
            b = a;
            a = temp;
        }
        for (var i = 0; i < 10000; i++) {
            // if (a < i) {
            //     k0 = i - a;
            // } else {
            //     k0 = a - i;
            // }
            // if (b < i) {
            //     k01 = i - b;
            // } else {
            //     k01 = b - i;
            // }
            var k1 = a + i;
            var k11 = b + i;
            var k2 = a + i;
            var k22 = i - b;
            var k3 = a - i;
            var k33 = b + i
            if (a == 0 && b == 0) {
                ans = 0;
                break;
            } else if (k1 == k11) {

                ans = 1;
                break;
            } else if (k2 == k22) {
                // console.log(k2 + " " + k22);
                ans = 2;
                break;
            } else if (k3 == k33) {
                ans = 3
                    // console.log(k3 + " " + k33);
                break;
            } else {
                ans = -1;
            }
        }
        console.log(ans);

    }

}

//Vismillahir Rahmanir Rahim (Allah hu Ackbar);

// var t = Number(readline());
// var ans = 0;
// var k0 = 0;
// var k01 = 0;
// while (t--) {
//     var arr = readline().split(' ').map(x => parseInt(x));
//     var a = arr[0],
//         b = arr[1];
//     if (a > b) {
//         var temp = b;
//         b = a;
//         a = temp;
//     }
//     for (var i = 0; i < 1000000; i++) {
//         if (a < i) {
//             k0 = i - a;
//         } else {
//             k0 = a - i;
//         }
//         if (b < i) {
//             k01 = i - b;
//         } else {
//             k01 = b - i;
//         }
//         var k1 = a + i;
//         var k11 = b + i;
//         var k2 = a + i;
//         var k22 = k01;
//         var k3 = k0;
//         var k33 = b + i
//         if (a == 0 && b == 0) {
//             ans = 0;
//             break;
//         } else if (k1 == k11) {

//             ans = 1;
//             break;
//         } else if (k2 == k22) {
//             // console.log(k2 + " " + k22);
//             ans = 2;
//             break;
//         } else if (k3 == k33) {
//             ans = 3
//                 // console.log(k3 + " " + k33);
//             break;
//         } else {
//             ans = -1;
//         }
//     }
//     console.log(ans);

// }

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

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

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});

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

// ************************ Code Start ***************************

function main() {

    var t = Number(readline());
    var ans = 0;
    var k0 = 0;
    var k01 = 0;
    while (t--) {
        var arr = readline().split(' ').map(x => parseInt(x));
        var a = arr[0],
            b = arr[1];
        if (a > b) {
            var temp = b;
            b = a;
            a = temp;
        }
        for (var i = 0; i < 10000; i++) {
            if (a < i) {
                k0 = i - a;
            } else {
                k0 = a - i;
            }
            if (b < i) {
                k01 = i - b;
            } else {
                k01 = b - i;
            }
            var k1 = a + i;
            var k11 = b + i;
            var k2 = a + i;
            var k22 = k01;
            var k3 = k0;
            var k33 = b + i
            if (a == 0 && b == 0) {
                ans = 0;
                break;
            } else if (k1 == k11) {

                ans = 1;
                break;
            } else if (k2 == k22) {
                // console.log(k2 + " " + k22);
                ans = 2;
                break;
            } else if (k3 == k33) {
                ans = 3
                    // console.log(k3 + " " + k33);
                break;
            } else {
                ans = -1;
            }
        }
        console.log(ans);

    }

}