Given an array $$$a$$$ of $$$n$$$ elements, print any value that appears at least three times or print -1 if there is no such value.

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

For each test case, print any value that appears at least three times or print -1 if there is no such value.

NoteIn the first test case there is just a single element, so it can't occur at least three times and the answer is -1.In the second test case, all three elements of the array are equal to $$$2$$$, so $$$2$$$ occurs three times, and so the answer is $$$2$$$.For the third test case, $$$2$$$ occurs four times, so the answer is $$$2$$$.For the fourth test case, $$$4$$$ occurs three times, so the answer is $$$4$$$.For the fifth test case, $$$1$$$, $$$2$$$ and $$$3$$$ all occur at least three times, so they are all valid outputs.For the sixth test case, all elements are distinct, so none of them occurs at least three times and the answer is -1.

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var n = lines[0];
    var e = 0;
    for(i = 1; i <= n * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var a = new Map();
            var ans = -1;
            for(j = 0; j <= e; j++){
                if(a.has(k[j])){
                    temp = a.get(k[j]);
                    temp++;
                    a.set(k[j], temp);
                }else{
                    a.set(k[j], 1);
                }
            }
            for(var [key, value] of a){
                if(value >= 3){
                    ans = key;
                    break;
                }
            }
            console.log(ans);
        }
    }
});

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

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    var e = 0;
    for(i = 1; i <= n * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var a = new Map();
            for(j = 0; j < e; j++){
                if(a.has(k[j])){
                    var temp = a.get(k[j]);
                    temp++;
                    a.set(k[j], temp);
                }else{
                    a.set(k[j], 1);
                }
            }
            var found = false;
            for(var [key, value] of a){
                if(value >= 3){
                    console.log(key);
                    found = true;
                    break;
                }
            }
            if(!found){
                console.log(-1);
            }
        }
    }
});

function solve(nums) {
    const map = new Map();
    for (const num of nums) {
        pre = map.get(num) || 0;
        map.set(num, pre + 1);
        if (pre == 2) {
            console.log(num)
            return;
        }
    }
    console.log(-1)
}

let text = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', t => {
    if (t === '\r\n' || t === '\n') {
        process.stdin.emit('end');
    } else {
        text += t;
    }
});
process.stdin.on('end', () => {
    const input = text.trim().replace(/\r/g, '').split('\n');
    const dataArr = input.slice(1).map(item => item.split(' ').map(n => parseInt(n)));
    const len = dataArr.length;

    for (let i = 1; i < len; i += 2) {
        solve(dataArr[i]);
    }
    process.exit();
});

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

process.stdin.on('end', () => {
    const input = text.trim().replace(/\r/g, '').split('\n');
    const total = +input[0];

    for (let i = 1; i <= total; i++) {
        console.log(solve(input[i * 2]));
    }

    process.exit();
});

function solve(str) {
    const ary = str.split(' ');
    const map = new Map();
    for (let ele of ary) {
        const get = map.get(ele) || 0;
        if (get === 2) {
            return ele;
        }
        map.set(ele, get + 1);
    }
    return -1;
}

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

let input = [];
let ans = [];

readline.on('line', line => {
    input.push(line);
}).on('close', () => {
    for (let i = 2; i < input.length; i+=2) {
        let nums = input[i].split(' ').map(Number);
        let freq = new Map();
        let max = 0;

        for (let j = 0; j < nums.length; j++) {
            freq.set(nums[j], (freq.get(nums[j]) || 0) + 1);
            if (freq.get(nums[j]) > 2 && freq.get(nums[j]) > max) max = freq.get(nums[j]);
        }
        freq = [...freq].filter(v=>v[1]===max).sort((a,b)=>b[0]-a[0]);
        ans.push(freq.length === 0 ? -1 : freq[0][0]);
    }
    console.log(ans.join('\n'));

});

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

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

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

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(c);
    // let out = "";
    // if (res) {
    //   for (let i = 0; i < res.length; i++) {
    //     out += res[i] + " ";
    //   }
    console.log(res);
    // }
  }
}
function solveMeFirst(str) {
  str = str.split(" ");
  let arr = [];
  for (let i = 0; i < str.length; i++) {
    arr[+str[i]] ? arr[+str[i]]++ : (arr[+str[i]] = 1);
    if (arr[+str[i]] >= 3) return +str[i];
  }
  return -1;
}

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

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 n = nl.num();
		let a = nl.nums();
		let c = new Array(n+1);
		a.forEach((e) => {
			if (c[e]) {
				c[e]++;
			} else {
				c[e]= 1;
			}
		});
		let flag = true;
		for(let j = 0; j <= n; j++){
			if (c[j] && c[j] >=3) {
				flag = false;
				ans.push(j);
				break;
			}
		}
		if (flag) {
			ans.push(-1);
		}
	}
	console.log(ans.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++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  let i = readline()
  while (i--) {
    const n = readline() | 0
    const arr = readline().split(' ').map(Number)
    const map = Array.from(new Array(arr.length), _ => 0)
    let out = -1
    for (let i = 0; i < arr.length; i++)
      if (++map[arr[i] - 1] === 3) {
        out = arr[i]
        break
      }
    console.log(out)
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const T = readline();
    for (let i = 0; i < T; i++) {
        const n = readline()
        const A = readline().split(' ').map(x => +x)
        solve(A)
    }
}
function solve(A) {

    let map = new Map()
    for (let i = 0; i < A.length; i++) {
        if (map.has(A[i])) {
            map.set(A[i], map.get(A[i]) + 1)
        } else {
            map.set(A[i], 1)
        }

        if (map.get(A[i]) >= 3) {
            console.log(A[i])
            return
        }
    }

    console.log(-1)
}

/*
 * File Created: Thursday, 11th February 2021 1:42:08 pm
 * Author: Lukas Rimkus
 */
'use-strict'

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

let data = '';
let currentLine = 0;

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

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(data.shift());

    while(testCases--) {

        const n = parseInt(data.shift());
        const a = get_ints();

        console.log(b784(n,a));
    }
});

function get_ints() {
    return data[currentLine++].split(' ').map(Number);
}

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

function a(n,arr){
    let k = 0;
    let j = 0;
    for(let i = 0 ; i < n; i++){
        if(arr[i] < 0){
            arr[j++] *= -1;
            arr[i] *= -1;
        }
    }
    if(isSorted(arr)) {
        return 'YES';
    } else {
        return 'NO'
    }
}

function isSorted(arr){
    for(let i = 0 ; i < arr.length - 1; i++){
        if(arr[i] > arr[i+1]) return false;
    }
    return true;
}

function b(s) {
    let arr = [];
    for(let i = 97; i <= 122; i++ ){
        for(let j = 97; j <= 122; j++){
            if(i != j) arr.push(String.fromCharCode(i,j));
        }
    }
    let count = 1;
    let index = 0;
    while(true){
        if(s != arr[index]) {
            count++;
            index++;
        } else{
            return count;
        }
    }
}

function a784(s){
    if(s >= 1900) {
        return 'Division 1';
    } else if(s >= 1600){
        return 'Division 2';
    } else if(s >= 1400){
        return 'Division 3';
    } else {
        return 'Division 4';
    }
}

function b784(n,array){
    let list = {};
    let counter = 0;
    array.forEach(item => {
        if (!list[item]) {
            list[item] = 1;
        } else {
            list[item] += 1;
        }
        if (list[item] > counter) {
            counter = list[item];
        }
    })
    for(const[key,value] of Object.entries(list)){
        if(value >= 3) return key;
    }
    return -1;
}
module.exports = b784;

const processData = (lines) => {
    let count = +lines[0]
    let cur = 0
    while(count--) {
        cur++
        // let [n] = lines[cur].split(' ').map(x => +x)
        cur++
        let nums = lines[cur].split(' ').map(x => +x)
        let found = -1;

        let map = {}
        for (const num of nums) {
            map[num] = map[num] ? map[num] + 1 : 1;
            if (map[num] >= 3) {
                found = num;
                break;
            }
        }

        console.log(found);
    }
}

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

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

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

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

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

		let ans = -1;
		const cnt = Array(n+1).fill(0);
		for (let i = 0; i < n; i++) {
			cnt[a[i]]++;
			if (cnt[a[i]] == 3) ans = a[i];
		}

		console.log(ans);
	}
}

'use strict';

var readline = require('readline');

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

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

function solve(n, a) {
  const map = new Map();
  for (let num of a) {
    var _map$get;
    map.set(num, ((_map$get = map.get(num)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);
  }
  for (let [num, count] of map) {
    if (count >= 3) {
      console.log(num);
      return;
    }
  }
  console.log(-1);
}

async function main(read) {
  const t = Number(await read());
  for (let i = 0; i < t; i++) {
    const n = Number(await read());
    const a = (await read()).split(' ').map(Number);
    solve(n, a);
  }
}

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

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var map = getCountMap(list);
		var key = Object.keys(map);
		var output = -1;
		for(var i = 0; i < key.length; i++){
			if(map[key[i]] >= 3){
				output = key[i];
				break;
			}
		}
		myout(output);
	}
}

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 = (n, a)=>{
    let map = {};

    for (const x of a) {
        if (map[x] === 2) return x;
        map[x] = (map[x] || 0) + 1;
    }

    return -1;
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let n = +readline();
        let a = ra();
        console.log(`${calc(n, a)}`);
    }
}

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

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

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

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

E.calc = calc;

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 map = {}
    for (let i = 0; i < arr.length; i++) {
        const x = arr[i]
        map[x] = (map[x] || 0) + 1
        if (map[x] >= 3) return x
    }
    return -1
}

T = readline()
while (T--) {
   n = readline()
   x = readline().split(' ').map(x => +x)
   result = {}
   for( i=0; i<n; i++){
      a = x[i]
      if(result[a] != undefined)
         ++result[a]
      else
         result[a] = 1
   }
   ans = -1
   for(key in result){
      if(result[key] >=3){
         ans = key
         break
      }
   }

   print(ans)
}

var sum=parseInt(readline());
var num=[];
var arr=[];
for(var i=0;i<sum;i++){
    num[i]=parseInt(readline());
    arr[i]=readline().split(" ");
}
for(var i=0;i<sum;i++){
    arr[i].sort(function(a, b){return a - b});
}
var bom;
var calc;
var hob;
var b;
for(var i=0;i<sum;i++){
    calc=[];
    hob=[];
    bom=0;
    for(var x=0;x<num[i];x++){
        if(parseInt(arr[i][x])===parseInt(arr[i][x+1])){
            ++bom;
        }
        else{
            calc.push(bom);
            hob.push(arr[i][x]);
            bom=0;
        }
        }
        b=-1;
        for(var y=0;y<calc.length;y++){
            if(calc[y]>=2){
                b=y;
                if(calc[y]<=calc[y+1]){
                b=y+1;
                }
            }
        }
        if(b!=-1){
            print(hob[b]);
        }
        else{
            print(-1);
        }

    }

var t = +readline()

for(var i = 0; i< t; i ++) {
    var a = readline()
    var arr1 = readline().split(" ").map(x => +x);
    print(returnThree(arr1));
}

function returnThree(n){

   var obj = {};
   for(var each of n){
      if (obj.hasOwnProperty(each)){
         obj[each]++;
         if (obj[each] >= 3){
            return each;
         }
      }else {
         obj[each] = 1;
      }
   }
   return -1;
}

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

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

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

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    var e = 0;
    for(i = 1; i <= n * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var ok = true;
            for(j = 0, l = 1; j < e, l < e; j += 2, l += 2){
                if(k[j] % 2 != k[0] % 2 || k[l] % 2 != k[1] % 2){
                    ok = false;
                    break;
                }
            }
            if(ok){
                console.log('YES');
            }else{
                console.log('NO');
            }
        }
    }
});

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

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

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

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

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

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    var e = 0;
    for(i = 1; i <= n * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var a = new Map();
            for(j = 0; j < e; j++){
                if(a.has(k[j])){
                    var temp = a.get(k[j]);
                    temp++;
                    a.set(k[j], temp);
                }else{
                    a.set(k[j], 1);
                }
            }
            var found = false;
            for(var [key, value] of a){
                if(value >= 3){
                    console.log(key);
                    found = true;
                }
            }
            if(!found){
                console.log(-1);
            }
        }
    }
});

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

let num = -1;
const rows = [];
rl.on('line', line => {
    if (num < 0) {
        num = parseInt(line.trim());
    } else {
        rows.push(line.trim());
        if (rows.length === num * 2) {
            dealInput(rows);
        }
    }
});
const dealInput = (rows) => {
    rows.forEach((item, index) => {
        if ((index + 1) % 2 === 0) {
            let newArr = item.split(' ')
            console.log(setNum(newArr));
        }
    })
    rl.close();
};

function setNum(arr) {
    let l = -1
    let newArr = arr.join(',')
    if(arr.length < 3) return -1
    for(let i = 0; i < arr.length; i++) {
        if(newArr.split(arr[i]).length > 3) {
            return arr[i]
        } else {
           continue
        }
    }
    return l
}

rl.on('close', () => {
    process.exit(0);
});

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

let input = [];
let ans = [];

readline.on('line', line => {
    input.push(line);
}).on('close', () => {
    for (let i = 2; i < input.length; i+=2) {
        let nums = input[i].split(' ').map(Number);
        let freq = new Map();
        let max = 0;

        for (let j = 0; j < nums.length; j++) freq.set(nums[j], (freq.get(nums[j]) || 0) + 1);
        freq = [...freq].filter(v=>v[1]>1).sort((a,b)=>{
            return a[1] < b[1] ? b[1]-a[1] : a[0] < b[0] ? 1 : -1;
        });
        ans.push(freq.length === 0 ? -1 : freq[0][0]);
    }
    console.log(ans.join('\n'));

});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0
    for(j = 1; j <= n * 2; j++){
        if(j % 2 === 0){
                var a = new Map()

        var k = lines[j].split(' ')
        for(l = 0 ;l < e; l++){

        if(a.has(k[l])){
            var temp = a.get(k[l])
            temp++
            a.set(k[l], temp)
        }else{
            a.set(k[l], 1)

             }
        }
        var biggestValue = 0
        var biggestKey = 'ashle'
            for(var [key,value] of a){
        if(biggestValue < value){
            biggestKey = key
            biggestValue = value
        }
    }
    if(biggestValue > 3){
        console.log(-1)
    }else{
    console.log(biggestKey)
    }
        } else {
            e = lines[j]
        }

}

});

T = readline()
while(T--){
   n = readline()
   x = readline().split(' ').map(x => +x)
   res = -1
   sums = [];

   for(i=0; i<n; i++){
      sumEl = x.filter(el => el === x[i])
      sums.push(sumEl.length)
   }
   print(sums)
   for(i=0; i<n; i++){
      if(sums[i]>=3){
      res = x[i]
      break
      }
   }

   print(res)
}

T = readline()
while(T--){
   n = readline()
   x = readline().split(' ').map(x => +x)
   res = -1
   sums = [];
   for(i=0; i<n; i++){
      sums.push((x.filter(el => el===x[i])).length)
   }

   for(i=0; i<n; i++){
      if(sums[i]>=3)
      res = x[i]
      break
   }

   print(res)
}


During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x — the number of different solutions that are sent before the first solution identical to A, and k — the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.

The first line of the input contains an integer n (1 ≤ n ≤ 105) — the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 ≤ x ≤ 105; 1 ≤ k ≤ 105) — the number of previous unique solutions and the identifier of the participant.

A single line of the output should contain «YES» if the data is in chronological order, and «NO» otherwise.

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

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

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

function main() {
	var n = parseInt(readline()),
		id2seen = {};
	for (var i = 0; i < n; ++i) {
		var data = tokenizeIntegers(readline()),
			x = data[0], id = data[1],
			seen = id2seen[id];
		if (seen === undefined) {
			seen = id2seen[id] = {};
		}
		if (x != 0 && seen[x-1] === undefined) {
			print('NO');
			return;
		}
		seen[x] = true;
	}
	print('YES');
}

main();


For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 < 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.

The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 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\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$.  Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).

NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var length = +readline();
    var arr = readline().split(' ').map(Number);

    var found = false;
    for (var j = 0; j < length - 1; j++) {
      if (Math.abs(arr[j] - arr[j + 1]) > 1) {
        found = true;
        print("YES");
        print(String(j + 1) + ' ' + String(j + 2));
        break;
      }
    }

    if (!found) {
      print("NO");
    }
  }
}

main();

'use strict';

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', _ => {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));
    main();
});

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

function parseIntArrLine() {
  return readLine().split(' ').map(cTemp => parseInt(cTemp, 10));
}

function parseIntLine() {
  return parseInt(readLine(), 10);
}

function isInterestingArr(arr) {
  for (let i = 0; i < (arr.length - 1); i++) {
    if (Math.abs(arr[i + 1] - arr[i]) > 1) {
      return [i + 1, i + 2];
    }
  }
  return null;
}

function main() {
    const numberOfTestCases = parseIntLine();
    const results = [];
    let arrLength, arr, found;
    for (let i = 1; i <= numberOfTestCases; i++) {
      arrLength = parseIntLine();
      arr = parseIntArrLine();
      found = isInterestingArr(arr);
      if (found !== null) {
        results.push("YES");
        results.push(found[0] + " " + found[1]);
      } else {
        results.push("NO");
      }
    }
    results.forEach(item => {
      process.stdout.write(item + "\n");
    });
    process.stdout.end();
}

let finalInput = '';

process.stdin.setEncoding('utf-8').on('data', input => {
    finalInput += input;
});

process.stdin.setEncoding('utf-8').on('end', () => {
    let lines = finalInput.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);
    for (let i = 0; i < lines.length; i += 2) {
        const array = lines[i + 1].split(' ').map(Number);
        let found = false;

        for (let j = 1; j < array.length; j++) {
            if (Math.max(array[j - 1], array[j]) - Math.min(array[j - 1], array[j]) >= 2) {
                console.log('YES');
                console.log(j, j + 1);
                found = true;
                break;
            }
        }
        if (!found) {
            console.log('NO');
        }
    }
});

let finalInput = '';

process.stdin.setEncoding('utf-8').on('data', input => {
    finalInput += input;
});

process.stdin.setEncoding('utf-8').on('end', () => {
    let lines = finalInput.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);
    for (let i = 0; i < lines.length; i += 2) {
        const array = lines[i + 1].split(' ').map(Number);
        let found = false;

        for (let j = 0; j < array.length && !found; j++) {
            let [min, max] = [array[j], array[j]];
            // console.log('[min, max]', min, max);
            for (let k = j + 1; k < array.length && !found; k++) {
                min = Math.min(min, array[k]);
                max = Math.max(max, array[k]);
                // console.log(array, min, max, j, k, max - min, k - j);
                if (max - min > k - j) {
                    found = true;
                    console.log('YES');
                    console.log(j + 1, k + 1);
                } else if (array[j + 1] < array[j]) {
                    j += 1;
                }
            }
        }
        if (!found) {
            console.log('NO');
        }
    }
});

let finalInput = '';

process.stdin.setEncoding('utf-8').on('data', input => {
    finalInput += input;
});

process.stdin.setEncoding('utf-8').on('end', () => {
    let lines = finalInput.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);
    for (let i = 0; i < lines.length; i += 2) {
        const array = lines[i + 1].split(' ').map(Number);
        const sum = array.reduce((acc, v) => acc + v, 0);
        const xorSum = array.reduce((acc, v) => acc ^ v, 0);
        // console.log(array, 'sum, xorSum', sum, xorSum);
        if (sum === 2 * xorSum) {
            console.log(0);
            console.log();
        } else {
            let first = xorSum;
            let second = (sum + first);
            console.log(2);
            console.log(first, second);
            // assert(BigInt(sum) + BigInt(first) + BigInt(second) === BigInt(n) * (BigInt(xorSum) ^ BigInt(first) ^ BigInt(second)), 'Wrong answer 1');
        }
    }
});

function assert(condition, message) {
    if (!condition) {
        throw new Error(message);
    }
}


Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with m pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2 × 2 square consisting of black pixels is formed. Pasha has made a plan of k moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers i and j, denoting respectively the row and the column of the pixel to be colored on the current move.Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2 × 2 square consisting of black pixels is formed.

The first line of the input contains three integers n, m, k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.  The next k lines contain Pasha's moves in the order he makes them. Each line contains two integers i and j (1 ≤ i ≤ n, 1 ≤ j ≤ m), representing the row number and column number of the pixel that was painted during a move.

If Pasha loses, print the number of the move when the 2 × 2 square consisting of black pixels is formed. If Pasha doesn't lose, that is, no 2 × 2 square consisting of black pixels is formed during the given k moves, print 0.

(function solve() {

var arr = readline().split(" ");

var n = parseInt(arr[0])+2;
var m = parseInt(arr[1])+2;
var k = parseInt(arr[2]);

var grid = [];
for(var i = 0; i < n; i++) {
    var arr = [];
    for(var j = 0; j < m; j++)
        arr.push(false);
    grid.push(arr);
}

var check = [
    [-1,-1],
    [-1,0],
    [0,-1],
    [0,0]
];

for(var i = 0; i < k; i++) {
    var arr = readline().split(" ");
    var ii = parseInt(arr[0]);
    var jj = parseInt(arr[1]);

    grid[ii][jj] = true;

    for(var j = 0; j < check.length; j++) {
        var flag = true;
        for(var x=0;x<2;x++)
            for(var y=0;y<2;y++)
                flag &= grid[ii+check[j][0]+x][jj+check[j][1]+y];
        if(flag) {
            return print(i+1);
        }
    }
}

print(0);

})();

function main() {
    var R = nextInt();
    var C = nextInt();
    var k = nextInt();

    var i;
    var b = [];

    for (i = 0; i < R; i++) {
        b.push([]);
    }

    var res = 0;

    for (i = 0; i < k; i++) {
        var r = nextInt() - 1;
        var c = nextInt() - 1;
        b[r][c] = 1;
        var found = false;
        for (var dr = -1; dr <= 1; dr += 2) {
            for (var dc = -1; dc <= 1; dc += 2) {
                var r1 = r + dr;
                var c1 = c + dc;
                if (r1 >= 0 && r1 < R && c1 >= 0 && c1 < C && b[r1][c1] === 1 && b[r][c1] === 1 && b[r1][c] === 1) {
                    found = true;
                }
            }
        }
        if (found) {
            res = i + 1;
            break;
        }
    }

    print(res);
}

// auxiliary code
var curTokens = [], curToken = 0;

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

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

main();

var debug = false;

function main(lineArr) {
    var lineNum = 0;
    function readln() {
        return debug? lineArr[lineNum++] : readline();
    }
    function readints() {
       return  readln().split(' ').map(function(x) {
           return parseInt(x)
       })
    }
    function println(data) {
        debug? console.log(data) : print(data);
    }

    //***************************************
    function check(i, j) {
        return arr[i] && arr[i + 1] &&
            arr[i][j] && arr[i + 1][j] &&
            arr[i][j + 1] && arr[i + 1][j + 1];
    }

    var line = readints();
    var n = line[0], m = line[1], k = line[2];
    var arr = new Array(n);
    var mez = [[0, 0], [-1, -1], [-1, 0], [0, -1]]
    for (var i = 0; i < n; i++)
        arr[i]  = new Array(m);
    outer:
    for (var i = 0; i < k; i++)
    {
        line = readints();
        var x = line[0] - 1, y = line[1] - 1;
        arr[x][y] = true;
        for (var j = 0; j < mez.length; j++)
            if (check(x + mez[j][0], y + mez[j][1])) {
                break outer;
            }
    }
    println(i == k? 0 : i + 1)
}

if (debug) {
    fs = require('fs');
    var fn = '/Users/zisakadze/Projects/codeforces/js/input.txt'
    fs.readFile(fn, 'utf8', function (err, data) {
        if (err) {
            return console.log(err);
        }
        main(data.split("\n"));
    });
} else {
    main();
}

try {require('codef');} catch (e) {};
function readLineAsArray(separator) {
    return readline().split(typeof separator == "undefined" ? ' ' : separator)
}
function readLineAsIntegerArray(separator) {
    return readLineAsArray(separator).map(function (v) {
        return +v
    });
}

var irsm = readLineAsIntegerArray();
var n = irsm[0], m = irsm[1], k = irsm[2];
var arr = [];
var end = false;
for(var i = 0; i < n + 2 ; i++) {
    var t = [];
    arr.push(t);
    for(var j = 0; j < m + 2; j++) {
        t.push(0);
    }
}

function check(i, j){
    if (arr[i - 1][j] == 1  &&  arr[i][j] == 1 && arr[i][j-1] == 1 && arr[i-1][j-1] == 1) {
        end = true;
        return true
    }
    return false;
}

for(var i = 0; i < k ; i++) {
    if (!end) {
        var cc = readLineAsIntegerArray();
        var t1 = cc[0], t2 = cc[1];
        arr[t1][t2] = 1;
        if (check(t1, t2) || check(t1+1, t2+1) || check(t1, t2+1) || check(t1+1, t2)) {
            write(i+1);
        }
    }
}

if (!end) write(0);

(function solve() {

var arr = readline().split(" ");

var n = parseInt(arr[0])+2;
var m = parseInt(arr[1])+2;
var k = parseInt(arr[2]);

var grid = [];
for(var i = 0; i < n; i++) {
    var arr = [];
    for(var j = 0; j < m; j++)
        arr.push(false);
    grid.push(arr);
}

var check = [
    [-1,-1],
    [-1,0],
    [0,-1],
    [0,0]
];

for(var i = 0; i < k; i++) {
    var arr = readline().split(" ");
    var ii = parseInt(arr[0])+1;
    var jj = parseInt(arr[1])+1;

    grid[ii][jj] = true;

    for(var j = 0; j < check.length; j++) {
        var flag = true;
        for(var x=0;x<2;x++)
            for(var y=0;y<2;y++)
                flag |= grid[ii+check[j][0]+x][jj+check[j][1]+y];
        if(flag) {
            return print(i+1);
        }
    }
}

print(0);

})();


Today the kindergarten has a new group of $$$n$$$ kids who need to be seated at the dinner table. The chairs at the table are numbered from $$$1$$$ to $$$4n$$$. Two kids can't sit on the same chair. It is known that two kids who sit on chairs with numbers $$$a$$$ and $$$b$$$ ($$$a \neq b$$$) will indulge if:   $$$gcd(a, b) = 1$$$ or,  $$$a$$$ divides $$$b$$$ or $$$b$$$ divides $$$a$$$. $$$gcd(a, b)$$$ — the maximum number $$$x$$$ such that $$$a$$$ is divisible by $$$x$$$ and $$$b$$$ is divisible by $$$x$$$.For example, if $$$n=3$$$ and the kids sit on chairs with numbers $$$2$$$, $$$3$$$, $$$4$$$, then they will indulge since $$$4$$$ is divided by $$$2$$$ and $$$gcd(2, 3) = 1$$$. If kids sit on chairs with numbers $$$4$$$, $$$6$$$, $$$10$$$, then they will not indulge.The teacher really doesn't want the mess at the table, so she wants to seat the kids so there are no $$$2$$$ of the kid that can indulge. More formally, she wants no pair of chairs $$$a$$$ and $$$b$$$ that the kids occupy to fulfill the condition above.Since the teacher is very busy with the entertainment of the kids, she asked you to solve this problem.

The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line containing an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of kids.

Output $$$t$$$ lines, which contain $$$n$$$ distinct integers from $$$1$$$ to $$$4n$$$ — the numbers of chairs that the kids should occupy in the corresponding test case. If there are multiple answers, print any of them. You can print $$$n$$$ numbers in any order.

var tc = parseInt(readline());
for (; tc--;){

  var number = parseInt(readline());
var multiply = 4*number;
var result = [];
for(var i = 1; i<=number;i++){
	var res = (multiply -=2);
	result.push(res);
}
print((result.join(' ')))

}

var tc = parseInt(readline());

while(tc--){
    var num = parseInt(readline());
    var result = num*4 - 2;
    for(var i = 0; i < num; i++){
        print(result + ' ');
        result -= 2;
    }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const n = +readLine();
    let start = n * 2;
    const ans = [];
    for (let i = 1; i <= n; i++) {
      ans.push(start);
      start += 2;
    }
    console.log(ans.join(" "));
  }
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var add = [];
		for(var j = N * 4; j >= 1; j--){
			if(add.length == N){
				break;
			}
			var isOK = true;
			for(var k = 0; k < add.length; k++){
				if(gcd(add[k], j) == 1 || add[k] % j == 0 || j % add[k] == 0){
					isOK = false;
				}
			}
			if(isOK){
				add.push(j);
			}
		}
		output[i] = myconv(add, 8);
	}
	myout(myconv(output, 9));
}
function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}

'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 println(x) {
    console.log(x);
};

function print(x) {
    process.stdout.write(x);
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    let tc = parseInt(readline());
    while (tc > 0) {
        const n = parseInt(readline());
        for (let i = 4 * n; i > 2 * n; i -= 2) {
            print (i + " ");
        }
        println("");
        tc -= 1;
    }
}

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

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

// import './array'
//
// import io from './io'
//
// function main() {
//   let [n] = io.nextNumbers()
//
//   let s = 2 * n
//
//   for (let i = 0; i < n; ++i) {
//     io.put(s + " ")
//     s += 2
//   }
//
//   io.put("\n")
// }
//
// io.runEachTest(main)
// // io.runMain(main)

let input = ''

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

process.stdin.on('end', () => {
  input.trim().split('\n').slice(1).map((x) => parseInt(x)).forEach((n) => {
    const ans = []
    for (let i = 0; i < n; i++) {
      ans.push(4 * n - 2 * i)
    }
    console.log(ans.join(' '))
  })
})

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

let inputString = '';
let currentLine = 0;

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

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

    A();
});

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

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

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

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let x = n;
        let res = [4*n];
        let num = 4*n;
        n -= 1;
        let i = 3;
        let f = 2;
        while(n > 0){
                num -= 2;
                let flag = false;
                for(let j = res.length-1; j >= 0; j--){
                    if(res[j] % num === 0){
                        flag = true;
                        break;
                    }
                }
                if(!flag){
                    res.push(num);
                    n--;
                }
        }

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

var number = parseInt(readline());
var multiply = 4*number;
var result = [];
for(var i = 1; i<=number;i++){
	var res = (multiply -=2);
	result.push(res);
}
var convertIntoNumber = result;
print((convertIntoNumber.join(' ')))

var tc = parseInt(readline());
var check = [];
var prime = [];
function primeGenerator(){
    for(var i = 4; i<=10000000; i+=2)check[i]=0;

    for(var i = 3; i*i <= 10000000; i++){
        if(check[i]!=0){
            for(var j = 2*i; j<=10000000; j+=i){
                check[j]=0;
            }
        }
    }
    for(var i = 2; i<= 10000000; i++){
        if(check[i]!=0)prime.push(i);
    }
}
primeGenerator();

while(tc--){
    var num = parseInt(readline());
    for(var i = 0; i<num; i++)print(prime[i]*2 + " ");
}

var tc = parseInt(readline());
var check = [];
var prime = [];
function primeGenerator(range){
    for(var i = 4; i<=range; i+=2)check[i]=0;

    for(var i = 3; i*i <= range; i++){
        if(check[i]!=0){
            for(var j = 2*i; j<=range; j+=i){
                check[j]=0;
            }
        }
    }
    for(var i = 2; i<=range; i++){
        if(check[i]!=0)prime.push(i);
    }
}
while(tc--){
    var num = parseInt(readline());
    primeGenerator(4*num);
    for(var i = 0; i<num; i++){
        print(2*prime[i] + ' ');
    }
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var add = [4];
		for(var j = 3; j <= N * 4; j++){
			if(add.length == N){
				break;
			}
			var isOK = true;
			for(var k = 0; k < add.length; k++){
				if(gcd(add[k], j) == 1 || add[k] % j == 0 || j % add[k] == 0){
					isOK = false;
				}
			}
			if(isOK){
				add.push(j);
			}
		}
		output[i] = myconv(add, 8);
	}
	myout(myconv(output, 9));
}
function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var add = [4];
		for(var j = N * 4; j >= 1; j--){
			if(add.length == N){
				break;
			}
			var isOK = true;
			for(var k = 0; k < add.length; k++){
				if(gcd(add[k], j) == 1 || add[k] % j == 0 || j % add[k] == 0){
					isOK = false;
				}
			}
			if(isOK){
				add.push(j);
			}
		}
		output[i] = myconv(add, 8);
	}
	myout(myconv(output, 9));
}
function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}

'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 println(x) {
    console.log(x);
}

function print(x) {
    process.stdout.write(x);
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    let tc = parseInt(readline());
    while (tc > 0) {
        const n = parseInt(readline());
        for (let i = 4 * n; i > 3 * n; i -= 1) {
            print (i + " ");
        }
        println("");
        tc -= 1;
    }
}

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

let inputString = '';
let currentLine = 0;

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

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

    A();
});

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

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

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

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let res = [4];
        n -= 1;
        let i = 3;
        while(n > 0){
            res.push(i*2);
            i += 2;
            n--;
        }
        console.log(res.join(' '));
    }
}

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

let inputString = '';
let currentLine = 0;

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

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

    A();
});

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

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

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

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let res = [4];
        n -= 1;
        let i = 3;
        while(n > 0){
            let num = i*2;
            let flag = false;
            for(let j = 0; j < res.length; j++){
                if(num % res[j] === 0){
                    i++;
                    flag = true;
                    break;
                }
            }
            if(!flag){
                res.push(num);
                n--;
            }
        }
        console.log(res.join(' '));
    }
}

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

let inputString = '';
let currentLine = 0;

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

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

    A();
});

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

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

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

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let x = n;
        let res = [4];
        n -= 1;
        let i = 3;
        let f = 2;
        while(n > 0){
            let num = i*f;
            if(num > 4*x){
                f++;
                i = 2;
            }else{
                let flag = false;
                for(let j = 0; j < res.length; j++){
                    if(num % res[j] === 0){
                        i++;
                        flag = true;
                        break;
                    }
                }
                if(!flag){
                    res.push(num);
                    i++;
                    n--;
                }
            }
        }
        console.log(res.join(' '));
    }
}


You are given $$$n$$$ sticks with positive integral length $$$a_1, a_2, \ldots, a_n$$$.You can perform the following operation any number of times (possibly zero):   choose one stick, then either increase or decrease its length by $$$1$$$. After each operation, all sticks should have positive lengths. What is the minimum number of operations that you have to perform such that it is possible to select three of the $$$n$$$ sticks and use them without breaking to form an equilateral triangle?An equilateral triangle is a triangle where all of its three sides have the same length.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 300$$$) — the number of sticks. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the lengths of the sticks. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$300$$$.

For each test case, print one integer on a single line — the minimum number of operations to be made.

NoteIn the first test case, you can increase the length of the first stick by $$$1$$$, then decrease the length of the third stick by $$$1$$$. In total, you perform $$$2$$$ operations, such that the three sticks form an equilateral triangle of side length $$$2$$$.In the fourth test case, you can decrease the length of the seventh stick by $$$1$$$. An equilateral triangle of side length $$$1$$$ can be selected and formed by the second, fourth, and seventh sticks.

let buffer = '';

// process.stdin ->stream input
// process.stdin.on(event,callback function to process the data collected)
// event is the form in which data will be read
// data event type of stream takes data in a container form
// readable event type of stream takes data in form of chunks
// end event can be called after taking the input

process.stdin.on('data', data => {
    buffer = data.toString().trim();
    let line = buffer.split('\n');
    let tc = parseInt(line[0]);
    //console.log(tc);
    for(let t = 1; t<=tc; t++){
        let n = parseInt(line[2*t-1]);
        let a = line[2*t].split(' ');
        let b = [];
        for(let i = 0; i<n; i++){
            b.push(parseInt(a[i]));
        }
        let ans = parseInt(2e9);
        b.sort((c, d) => c-d);
        for(let i = 1; i<n-1; i++){
            ans = Math.min(ans,b[i+1]-b[i-1]);
        }
        console.log(ans);
    }
});

let buffer = '';

// process.stdin ->stream input
// process.stdin.on(event,callback function to process the data collected)
// event is the form in which data will be read
//
process.stdin.on('data', data => {
    buffer = data.toString().trim();
});

process.stdin.on('end',() => {
    let line = buffer.split('\n');
    let tc = parseInt(line[0]);
    //console.log(tc);
    for(let t = 1; t<=tc; t++){
        let n = parseInt(line[2*t-1]);
        let a = line[2*t].split(' ');
        let b = [];
        for(let i = 0; i<n; i++){
            b.push(parseInt(a[i]));
        }
        let ans = parseInt(2e9);
        b.sort((c, d) => c-d);
        for(let i = 1; i<n-1; i++){
            ans = Math.min(ans,b[i+1]-b[i-1]);
        }
        console.log(ans);
    }
});

let buff = '';

// process.stdin ->stream input
// process.stdin.on(event,callback function to process the data collected)
// event is the form in which data will be read
//
process.stdin.on('readable', () => {
    let chunk = process.stdin.read();
    if(chunk){buff += chunk;}
});

process.stdin.on('end',() => {
    let line = buff.split('\n');
    let tc = parseInt(line[0]);
    //console.log(tc);
    for(let t = 1; t<=tc; t++){
        let n = parseInt(line[2*t-1]);
        let a = line[2*t].split(' ');
        let b = [];
        for(let i = 0; i<n; i++){
            b.push(parseInt(a[i]));
        }
        let ans = parseInt(2e9);
        b.sort((c, d) => c-d);
        //console.log(b);
        for(let i = 1; i<n-1; i++){
            ans = Math.min(ans,b[i+1]-b[i-1]);
        }
        /*for(let i = 0; i<n; i++){
            for(let j = i+1; j<n; j++){
                for(let k = j+1; k<n; k++){
                    let p = parseInt(a[i]);
                    let q = parseInt(a[j]);
                    let r = parseInt(a[k]);
                    ans = Math.min(ans,Math.max(p,q,r)-Math.min(p,q,r));
                }
            }
        }*/
        console.log(ans);
    }
});

/* why are we here, just to suffer? */
let buf='';

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

process.stdin.on('end',function(){
    let line=buf.split('\n');
    let t=parseInt(line[0]);
    for(let tc=1;tc<=2*t;tc+=2) {
        let n=parseInt(line[tc]);
        let inp=line[tc+1].split(' ');
        a=[];
        for(let i=0;i<n;i++) {
            a.push(parseInt(inp[i]));
        }
        let ans=parseInt(1e9+7);
        for(let i=0;i<n;i++) {
            for(let j=i+1;j<n;j++) {
                for(let k=j+1;k<n;k++) {
                    ans=Math.min(ans,Math.max(a[i],Math.max(a[j],a[k])) - Math.min(a[i],Math.min(a[j],a[k])));
                }
            }
        }
        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] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var output = Math.pow(10, 15);
		for(var i = 0; i < N; i++){
			for(var j = i + 1; j < N; j++){
				for(var k = j + 1; k < N; k++){
					var V = [list[i], list[j], list[k]];
					V.sort(function(a,b){
						return a - b;
					});
					var b = (V[1] - V[0]) + (V[2] - V[1]);
					output = Math.min(output, b);
				}
			}
		}
		myout(output);
	}
}

'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 numSticks = Number(readline());
        let arr = readline().split(" ").map(x => parseInt(x));
        chooseSticks(arr)
    }

}
function chooseSticks(sticks) {
    let count = Infinity;

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

    for (let i = 2; i < sticks.length; i++) {
        count = Math.min(count, (sticks[i] - sticks[i-1]) + (sticks[i-1] - sticks[i-2]))
    }

    console.log(count)
}

"use strict";

const { Console } = require("console");
const fs = require("fs");
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 equilateral(cases) {
  for (let i = 0; i < cases.length; i++) {
    let minSum =
      Number(cases[i][1]) -
      Number(cases[i][0]) +
      (Number(cases[i][2]) - Number(cases[i][1]));
    for (let j = 0; j < cases[i].length && j + 2 < cases[i].length; j++) {
      const currSum =
        Number(cases[i][j + 1]) -
        Number(cases[i][j]) +
        (Number(cases[i][j + 2]) - Number(cases[i][j + 1]));
      minSum = Math.min(minSum, currSum);
    }
    console.log(minSum);
  }
}

function main() {
  const t = parseInt(readLine().trim());
  const cases = [];
  for (let i = 0; i < t * 2; i++) {
    const sticks = readLine().split(" ");
    if (i % 2 === 1) cases.push(sticks.sort((a, b) => a - b));
  }

  equilateral(cases);
}

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

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
     let t = parseInt(readline());
     while(t--){
          let n = parseInt(readline());
          let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
          arr.sort((a,b)=>a-b);
          let sum;
          let min = Infinity;
          for(let i=0;i<n-2;i++){
               sum = 0;
               let k = arr[i+1];
               sum = Math.abs(k-arr[i]) + Math.abs(k-arr[i+2]);
               min = Math.min(sum,min);
          }
          console.log(min);
     }
};
solve();

let readline = require("readline");

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

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

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

let solve = (input) => {
  for (let i = 1; i < input.length; i += 2) {
    let sticks = input[i + 1];
    sticks.sort((a, b) => a - b);
    let min = sticks[2] - sticks[0];

    for (let i = 1; i < sticks.length - 2; i++) {
      min = Math.min(min, sticks[i + 2] - sticks[i]);
    }
    console.log(min);
  }
};

'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);
        let minimum = Infinity;

        for (let i = 0; i < n; i++) {
            for (let j = 0; j < n; j++) {
                for (let k = 0; k < n; k++) {
                    if (i !== j && j !== k && i !== k) {
                        let min = Math.min(arr[i], arr[j], arr[k]);
                        let max = Math.max(arr[i], arr[j], arr[k]);
                        let actions = max - min;
                        if (actions < minimum) {
                            minimum = actions;
                        }
                    }
                }
            }
        }

        output(minimum);
    }
}

var t = +readline();

while (t--) {
  readline();
  solve(readline());
}

function solve(s) {
  var p = s
    .split(" ")
    .map((i) => +i)
    .sort((a, b) => a - b);

  var sm = [];
  for (var i = 0; i < p.length - 2; i++) {
    sm.push(Math.abs(p[i]-p[i+1])+Math.abs(p[i+1]-p[i+2]));
  }

  var mn = Number.MAX_SAFE_INTEGER;

  for (var i = 0; i < sm.length; i++) {
    var curr = Math.round(sm[i]);
    if (curr < mn) mn = curr;
  }

    print(mn);
//   console.log(mn);
}

let buffer = '';

// process.stdin ->stream input
// process.stdin.on(event,callback function to process the data collected)
// event is the form in which data will be read
//
process.stdin.on('data', data => {
    buffer = data.toString().trim();
});

process.stdin.on('close',() => {
    let line = buffer.split('\n');
    let tc = parseInt(line[0]);
    //console.log(tc);
    for(let t = 1; t<=tc; t++){
        let n = parseInt(line[2*t-1]);
        let a = line[2*t].split(' ');
        let b = [];
        for(let i = 0; i<n; i++){
            b.push(parseInt(a[i]));
        }
        let ans = parseInt(2e9);
        b.sort((c, d) => c-d);
        for(let i = 1; i<n-1; i++){
            ans = Math.min(ans,b[i+1]-b[i-1]);
        }
        console.log(ans);
    }
});

let buffer = '';

// process.stdin ->stream input
// process.stdin.on(event,callback function to process the data collected)
// event is the form in which data will be read
//
process.stdin.on('data', data => {
    buffer = data.toString().trim();
});

process.stdin.on('end',() => {
    let line = buffer.split('\n');
    let tc = parseInt(line[0]);
    //console.log(tc);
    for(let t = 1; t<=tc; t++){
        let n = parseInt(line[2*t-1]);
        let a = line[2*t].split(' ');
        let b = [];
        for(let i = 0; i<n; i++){
            b.push(parseInt(a[i]));
        }
        let ans = parseInt(2e9);
        b.sort((c, d) => c-d);
        for(let i = 1; i<n-1; i++){
            ans = Math.min(ans,b[i+1]-b[i-1]);
        }
    }
});

/* why are we here, just to suffer? */
let buf='';

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

process.stdin.on('end',function(){
    let line=buf.split('\n');
    let t=parseInt(line[0]);
    for(let tc=1;tc<=2*t;tc+=2) {
        let n=parseInt(line[tc]);
        let inp=line[tc+1].split(' ');
        a=[];
        for(let i=0;i<n;i++) {
            a.push(parseInt(inp[i]));
        }
        let ans=parseInt(1e9+7);
        for(let i=0;i<n;i++) {
            for(let j=i+1;j<n;j++) {
                for(let k=j+1;k<n;k++) {
                    let have=[a[i],a[j],a[k]];
                    have.sort();
                    ans=Math.min(ans,have[2]-have[0]);
                }
            }
        }
        console.log(ans);
    }
});

/* why are we here, just to suffer? */
const fs=require('fs');

const plsread=()=>{
    let BUFSIZE=1024;
    let buf=new Buffer(BUFSIZE);
    let bytesRead;
    while(true) {
        bytesRead = 0;
        bytesRead = fs.readSync(process.stdin.fd, buf, 0, BUFSIZE);
        if (bytesRead === 0) break;
        let bufstr=buf.toString('utf-8',0,bytesRead);
        // console.log('Bytes read: %s; content:\n%s', bytesRead, buf.toString('utf8', 0, bytesRead));
        return bufstr;
    }
};

const main=()=>{
    let inp=plsread().replace(/\r/g,' ').replace(/\n/g,'').split(' ');
    // console.log(inp.length);
    // console.log(inp);
    let ti=0,t=inp[ti++];
    while(t--) {
        let n=inp[ti++];
        let a=[];
        for(let i=0;i<n;i++) {
            a.push(inp[ti++]);
        }
        let ans=parseInt(1e9+7);
        for(let i=0;i<n;i++) {
            for(let j=i+1;j<n;j++) {
                for(let k=j+1;k<n;k++) {
                    ans=Math.min(ans,Math.max(a[i],Math.max(a[j],a[k])) - Math.min(a[i],Math.min(a[j],a[k])));
                }
            }
        }
        if(ans == 1000000007) {
            console.log(a);
        }
        console.log(ans);
    }
};

main();

/* why are we here, just to suffer? */
const fs=require('fs');

const plsread=()=>{
    let BUFSIZE=1024;
    let buf=new Buffer(BUFSIZE);
    let bytesRead;
    while(true) {
        bytesRead = 0;
        bytesRead = fs.readSync(process.stdin.fd, buf, 0, BUFSIZE);
        if (bytesRead === 0) break;
        let bufstr=buf.toString('utf-8',0,bytesRead);
        // console.log('Bytes read: %s; content:\n%s', bytesRead, buf.toString('utf8', 0, bytesRead));
        return bufstr;
    }
};

const main=()=>{
    let inp=plsread().replace(/\r/g,' ').replace(/\n/g,'').split(' ');
    console.log(inp.length);
    // console.log(inp);
    let ti=0,t=inp[ti++];
    while(t--) {
        let n=inp[ti++];
        let a=[];
        for(let i=0;i<n;i++) {
            a.push(inp[ti++]);
        }
        let ans=parseInt(1e9+7);
        for(let i=0;i<n;i++) {
            for(let j=i+1;j<n;j++) {
                for(let k=j+1;k<n;k++) {
                    ans=Math.min(ans,Math.max(a[i],Math.max(a[j],a[k])) - Math.min(a[i],Math.min(a[j],a[k])));
                }
            }
        }
        if(ans == 1000000007) {
            console.log(a);
        }
        console.log(ans);
    }
};

main();

/* why are we here, just to suffer? */
const fs=require('fs');

const plsread=()=>{
    let BUFSIZE=256;
    let buf=new Buffer(BUFSIZE);
    let bytesRead;
    while(true) {
        bytesRead = 0;
        bytesRead = fs.readSync(process.stdin.fd, buf, 0, BUFSIZE);
        if (bytesRead === 0) break;
        let bufstr=buf.toString('utf-8',0,bytesRead);
        // console.log('Bytes read: %s; content:\n%s', bytesRead, buf.toString('utf8', 0, bytesRead));
        return bufstr;
    }
};

const main=()=>{
    let inp=plsread().replace(/\r/g,' ').replace(/\n/g,'').split(' ');
    // console.log(inp);
    let ti=0,t=inp[ti++];
    while(t--) {
        let n=inp[ti++];
        let a=[];
        for(let i=0;i<n;i++) {
            a.push(inp[ti++]);
        }
        let ans=parseInt(1e9+7);
        for(let i=0;i<n;i++) {
            for(let j=i+1;j<n;j++) {
                for(let k=j+1;k<n;k++) {
                    ans=Math.min(ans,Math.max(a[i],Math.max(a[j],a[k])) - Math.min(a[i],Math.min(a[j],a[k])));
                }
            }
        }
        console.log(ans);
    }
};

main();

const fs=require('fs');

const plsread=()=>{
    let BUFSIZE=256;
    let buf=new Buffer(BUFSIZE);
    let bytesRead;
    while(true) {
        bytesRead = 0;
        bytesRead = fs.readSync(process.stdin.fd, buf, 0, BUFSIZE);
        if (bytesRead === 0) break;
        let bufstr=buf.toString('utf-8',0,bytesRead);
        // console.log('Bytes read: %s; content:\n%s', bytesRead, buf.toString('utf8', 0, bytesRead));
        return bufstr;
    }
};

const main=()=>{
    let inp=plsread().replace(/\r/g,' ').replace(/\n/g,'').split(' ');
    let ti=0,t=inp[ti++];
    while(t--) {
        let n=inp[ti++];
        let a=[];
        for(let i=0;i<n;i++) {
            a.push(inp[ti++]);
        }
        let ans=parseInt(1e9+7);
        for(let i=0;i<n;i++) {
            for(let j=i+1;j<n;j++) {
                for(let k=j+1;k<n;k++) {
                    let have=[a[i],a[j],a[k]];
                    have.sort();
                    ans=Math.min(ans,have[2]-have[0]);
                }
            }
        }
        console.log(ans);
    }
};

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 list = nextIntArray(N);
		list.sort(function(a,b){
			return a - b;
		});
		myout((list[1] - list[0]) + (list[2] - list[1]));
	}
}

var t = +readline();

while (t--) {
  readline();
  solve(readline());
}

function solve(s) {
  var p = s
    .split(" ")
    .map((i) => +i)
    .sort((a, b) => a - b);

  var sm = [];
  for (var i = 0; i < p.length - 2; i++) {
    sm.push((p[i] + p[i + 1] + p[i + 2]) / 3);
  }

  var mn = Number.MAX_SAFE_INTEGER;

  for (var i = 0; i < sm.length; i++) {
    var curr = Math.round(sm[i]);
    if (curr < mn) mn = curr;
  }

  print(mn);
}

var t = +readline();

while (t--) {
  readline();
  solve(readline());
}

function solve(s) {
  var p = s
    .split(" ")
    .map((i) => +i)
    .sort((a, b) => a - b);

  var sm = [];
  for (var i = 0; i < p.length - 2; i++) {
    sm.push((p[i] + p[i + 1] + p[i + 2]) / 3);
  }

  var mn = Number.MAX_SAFE_INTEGER;

  for (var i = 0; i < sm.length; i++) {
    var curr = Math.floor(sm[i]);
    if (curr < mn) mn = curr;
  }

  print(mn);
}