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
}

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

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

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


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

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


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

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

})();

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

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

})();


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

}

//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;}

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

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

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


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

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


var n = readline().split(' ')[0];
var s = readline().split(' ')[0];
var a = "";
var b = "";
for (var i = 0; i < n; i++) {
	if (i%2 == 0)
    	a += s[i];
    else
    	b = s[i]+b;
}
a = b+a;
if (s.length % 2 == 0)
 a = a.split("").reverse().join("");
print(a)

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

let currentLine = 0;
let inputString = "";

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

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

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

/******** Main function*************/

function main() {
  var n = +readLine();
  var str = readLine().split("");

  var newStr = [];

  if (n % 2 == 1) {
    for (var i = 1; i <= n; i++) {
      if (i % 2 == 1) {
        newStr.push(str[i - 1]);
      }
      if (i % 2 === 0) {
        newStr.unshift(str[i - 1]);
      }
    }
  }
  if (n % 2 === 0) {
    for (var j = 1; j <= n; j++) {
      if (j % 2 === 0) {
        newStr.push(str[j - 1]);
      }
      if (j % 2 == 1) {
        newStr.unshift(str[j - 1]);
      }
    }
  }

  console.log(newStr.join(""));
}

var l = readline();
l = parseInt(l);

var w = readline();
var a = w.split('');

var r = '';
var p = 'd';
if (l % 2) {
    p = 's';
}
a.forEach(l => {
    if (p == 's') {
        r = r + l;
        p = 'd';
    } else {
        r = l + r;
        p = 's';
    }
});

print(r);

var n = parseInt(readline());
var s = readline();
var result = [];
var c = 0;
var stringResult = "";

var median = Math.ceil(n / 2) - 1;
result[median] = s[0];

if(n % 2 == 1)
{
    for(var i = 1; i < median + 1; i++)
    {
        result[median - i] = s[i + c];
        result[median + i] = s[i + 1 + c];
        c++;
    }
}
else
{
    for(var i = 1; i < median + 1; i++)
    {
        result[median + i] = s[i + c];
        result[median - i] = s[i + 1 + c];
        c++;
    }
    result[n - 1] = s[n - 1];
}

for(var i = 0; i < n; i++)
    stringResult += result[i];

print(stringResult);

var n=parseInt(readline());
var inp=readline(),op="";
var i=n-2;
if(inp.length%2===0){
while(i>=0){
op+=inp[i];
i-=2;
}i=1;while(i<n){
	op+=inp[i];
	i+=2;
}
}else{
while(i>0){
op+=inp[i];
i-=2;
}i=0;while(i<n){
	op+=inp[i];
	i+=2;
}
}

print(op);

function decodeWord(encodedWord, lengthOfWord){
    var arrayForWord = Array(lengthOfWord);
    var left = 0;
    var right = lengthOfWord-1;
    var first = false;
    var last = true;

    for(var i=encodedWord.length-1; i>=0; i--){
        if(first === false && last === true){
            arrayForWord[right] = encodedWord[i];
            right--;
            first = true;
            last = false;

        }else if( first === true && last === false){
            arrayForWord[left] = encodedWord[i];
            left++;

            first = false;
            last = true;
        }

    }

    print( arrayForWord.join('') );

}
var length = readline();
var input = readline();
decodeWord(input, length)

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

var res = '';

for (var i = 0; i < len; i++) {
  if (len%2 === 0) {
    i%2 !== 0 ? res += str[i] : res = str[i] + res;
  } else {
    i%2 === 0 ? res += str[i] : res = str[i] + res;
  }
}

print(res);

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

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

  const arr = [...str];
  let ans = arr[0];
  arr.shift();

  while (arr.length) {
    if (arr.length % 2 === 0) {
      ans = arr[0] + ans;
    }
    else {
      ans = ans + arr[0];
    }

    arr.shift();
  }

  console.log(ans);

  c++;
});

const input = [];

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

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

function removeLetter(str, pos) {
    return str.substring(0, pos-1)+str.substring(pos);
}

RL.on('close', () => {
    const n = parseInt(input[0], 10);
    let str = input[1];

    let answer = ''; let mode = (str.length % 2 === 0) ? 1 : 0;
    for(let i = 0; i < n; i += 1) {
        if(mode && i !== 0){
            answer = str.charAt(i) + answer;
            mode = !mode;
        } else if (!mode  && i !== 0) {
            answer += str.charAt(i);
            mode = !mode;
        } else if(i === 0) {
            answer = str.charAt(0);
        }
    }
    global.console.log(answer.split("").reverse().join(""));
});

var s = readline().split(' ')[0];
var a = "";
var b = "";
for (var i = 0; i < s.length; i++) {
	if (i%2 == 0)
    	a += s[i];
    else
    	b = s[i]+b;
}
print(b+a)

var n = readline().split(' ')[0];
var s = readline().split(' ')[0];
var a = "";
var b = "";
for (var i = 0; i < n; i++) {
	if (i%2 == 0)
    	a += s[i];
    else
    	b = s[i]+b;
}
print(b+a)

var n = parseInt(readline());
var s = readline();
var result = ["a", "a", "a", "a", "a"];
var c = 0;
var stringResult = "";

var median = Math.ceil(n / 2) - 1;
result[median] = s[0];

if(n % 2 == 1)
{
    for(var i = 0; i < median + 1; i++)
    {
        result[median - i] = s[i + c];
        result[median + i] = s[i + 1 + c];
        c++;
    }
}
else
{
    for(var i = 0; i < median + 1; i++)
    {
        result[median + i] = s[i + c];
        result[median - i] = s[i + 1 + c];
        c++;
    }
    result[n - 1] = s[n - 1];
}

for(var i = 0; i < n; i++)
    stringResult += result[i];

print(stringResult);

var n = parseInt(readline());
var s = readline();
var result = [];
var c = 0;
var stringResult = "";

var median = Math.ceil(n / 2) - 1;
result[median] = s[0];

if(n % 2 == 1)
{
    for(var i = 0; i < median + 1; i++)
    {
        result[median - i] = s[i + c];
        result[median + i] = s[i + 1 + c];
        c += 1;
    }
}
else
{
    for(var i = 0; i < median + 1; i++)
    {
        result[median + i] = s[i + c];
        result[median - i] = s[i + 1 + c];
        c += 1;
    }
    result[n - 1] = s[n - 1];
}

for(var i = 0; i < n; i++)
    stringResult += result[i];

print(stringResult);