// your code goes here
var t = parseInt(readline());
for (var x = 0; x < t; ++x) {
	var n = parseInt(readline());
	var a = readline().split(' ').map(x => parseInt(x));
	var mx = 0;
	for (var i = 0; i < n; ++i) {
		if (a[i] > mx) {
			mx = a[i];
		}
	}
	var ind = -2;
	for (var i = 0; i < n; ++i) {
		if (a[i] == mx) {
			if (i > 0 && a[i - 1] < mx) {
				ind = i;
				break;
			} else if (i < n - 1 && a[i + 1] < mx) {
				ind = i;
				break;
			}
		}
	}
	print(ind + 1);
}

var t = parseInt(readline());

while (t--) {
    var n = parseInt(readline());
    var ar = readline().split(' ').map(function(x, index) {
        // print("index: " + index + " val: " + x);
        return parseInt(x);
    });
    var same = 1;
    for (var i = 1; i < ar.length; ++i) if (ar[0] !== ar[i]) same = 0;
    if (same) {
        print("-1");
        continue;
    }

    var ans = -1;
    var big = ar[0];

    for (var i = 1; i < ar.length; ++i) if (ar[i] > big) big = ar[i];

    for (var i = 0; i < ar.length; ++i) {
        if (i - 1 >= 0 && ar[i] === big && ar[i-1] < ar[i]) {
            ans = i + 1;
            break;
        }
        if (i + 1 < ar.length && ar[i] === big && ar[i+1] < ar[i]) {
            ans = i + 1;
            break;
        }
    }

    print(ans);

    // ar.forEach(function(val) {
    //     print(val[0] + ' -> ' + val[1]);
    // });
}

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

let mem = new Map();
function query(arr){
    let max_i = 0, min_i = 0;
    for (let i=0; i<arr.length; i++)
    {
        max_i = arr[max_i] < arr[i]  ? i : max_i;
        min_i = arr[min_i] > arr[i]  ? i : min_i;
    }
    if (max_i==min_i)
        return -1;
    for (let i=0; i<arr.length; i++)
    {
        if (arr[i]==arr[max_i] && (arr[i-1] < arr[i] || arr[i+1] < arr[i]))
            return i+1;
    }
    return -1;
}

function main() {
    var q = +readline();
    while (q--)
    {
        var n = +readline();
        let arr = readline().split(' ').map(a=>+a);
        print(query(arr));
    }
}

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

let lineNum = 0;
let countOfData = null;
let data = [];
readline.on('line', line => {
  lineNum++;
  if(lineNum === 1) {
    countOfData = +line * 2;
    return;
  }

  data.push(line);

  if(lineNum - 1 === countOfData) {
    goToSolution(data);
  }

});

function goToSolution(data) {
  data.forEach((piranhas, i) => {
    if(i % 2 !== 0) {
      const splitted = piranhas.split(' ');
      const sorted = splitted.map((piranha, i) => [+piranha, i])
        .sort((a, b) => b[0] - a[0]);

      for(let i = 0; i < sorted.length && sorted[i][0] == sorted[0][0]; i++) {
        const cur = sorted[i][0];
        const left = splitted[sorted[i][1] - 1];
        const right = splitted[sorted[i][1] + 1];
        if(left < cur || right < cur) {
            console.log(sorted[i][1] + 1)
            return;
          }
      }

      console.log(-1)
    }
  })
}

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 len = +readLine();
    const arr = readLine().split(" ").map(Number);
    let [max, maxIndex, allSame] = [-Infinity, 0, true];

    for (let i = 1; i < len; i++) {
      const [curr, prev] = [arr[i], arr[i - 1]];
      const diff = Math.abs(curr - prev);
      if (diff !== 0) {
        allSame = false;
        if (curr > prev && curr > max) {
          max = curr;
          maxIndex = i;
        } else if (prev > curr && prev > max) {
          max = prev;
          maxIndex = i - 1;
        }
      }
    }
    if (allSame) console.log(-1);
    else {
      console.log(maxIndex + 1);
    }
  }
}

//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 list = nextIntArray();
		var isOK = true;
		var max = 0;
		var maxIndex = -1;
		for(var j = 0; j < N - 1; j++){
			if(list[j] != list[j + 1]){
				isOK = false;
				break;
			}
		}
		if(isOK){
			output[i] = -1;
			continue;
		}
		for(var j = 0; j < N; j++){
			if(j == 0){
				if(max < list[j] && list[j] != list[j + 1]){
					max = list[j];
					maxIndex = j + 1;
				}
				continue;
			}
			if(j == N - 1){
				if(max < list[j] && list[j] != list[j - 1]){
					max = list[j];
					maxIndex = j + 1;
				}
				continue;
			}
			if((list[j] != list[j + 1] || list[j] != list[j - 1]) && max < list[j]){
				max = list[j];
				maxIndex = j + 1;
			}
		}
		output[i] = maxIndex;
	}
	myout(myconv(output, 9));
}

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

let stdinInput = '';

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

process.stdin.on('end', () => {
  main(stdinInput);
})

function main(data) {
    data = data.split('\n');
    const testCases = data[0] * 2;
    let i = 1;
    while (i <= testCases) {
      // let a = data[i].trim();
      // const n = data[i] * 1;
      // const k = a[1];
      const s = data[i + 1].trim().split(' ').map(Number);
      // s.sort((a, b) => b - a);
      let idx = 0;
      let max = 0;
      let obj = {};

      for (let j = 0; j < s.length; j += 1) {
        if (obj[s[j]]) obj[s[j]].push(j);
        else obj[s[j]] = [j];
        if (s[j] > max) {
          max = s[j];
          idx = j;
        }
      }
      // console.log(obj, obj[max]);

      let j = 0;
      idx = -1
      // console.log(idx, 'idx', max)
      for (; j < obj[max].length; j += 1) {
        let x = obj[max][j];
        if (s[x + 1] && s[x + 1] < s[x]) {
          idx = x + 1;
          // console.log(j,'j');
          break;

        } else if (s[x - 1] && s[x - 1] < s[x]) {
          idx = x + 1;
          // console.log(j,'ej');
          break;
        }
      }

      console.log(idx);
      i += 2;
    }
}

var t = parseInt(readline());

while (t--) {
    var n = parseInt(readline());
    var ar = readline().split(' ').map(function(x, index) {
        // print("index: " + index + " val: " + x);
        return [parseInt(x), index + 1];
    });
    var same = 1;
    for (var i = 1; i < ar.length; ++i) if (ar[0][0] !== ar[i][0]) same = 0;
    if (same) {
        print("-1");
        continue;
    }

    ar.sort(function(v1, v2) {
        if (v1[0] < v2[0]) return 1;
        return -1;
    });

    print(ar[0][1]);

    // ar.forEach(function(val) {
    //     print(val[0] + ' -> ' + val[1]);
    // });
}

// your code goes here
var t = +readline();
for (var x = 0; x < t; ++x) {
	var n = +readline();
	var a = readline().split(' ');
	var mx = 0;
	for (var i = 0; i < n; ++i) {
		if (a[i] > mx) {
			mx = a[i];
		}
	}
	var ind = -2;
	for (var i = 0; i < n; ++i) {
		if (a[i] == mx) {
			if (i > 0 && a[i - 1] < mx) {
				ind = i;
				break;
			} else if (i < n - 1 && a[i + 1] < mx) {
				ind = i;
				break;
			}
		}
	}
	print(ind + 1);
}

// your code goes here
var t = parseInt(readline());
for (var x = 0; x < t; ++x) {
	var n = parseInt(readline());
	var a = readline().split(' ').map(x => parseInt(x));
	var mx = 0;
	for (var i = 0; i < n; ++i) {
		if (a[i] > mx) {
			mx = a[i];
		}
	}
	print(mx);
	var ind = -2;
	for (var i = 0; i < n; ++i) {
		if (a[i] == mx) {
			if (i > 0 && a[i - 1] < mx) {
				ind = i;
				break;
			} else if (i < n - 1 && a[i + 1] < mx) {
				ind = i;
				break;
			}
		}
	}
	print(ind + 1);
}


'use strict';
const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
//const util = require('util');
//process.stdin.resume();
//process.stdin.setEncoding('ascii');
let pos = 0;
const words = [];
rl.on('line', (line) => {
    words.push.apply(words, line.split(' ').filter(s => s != ''));
});
rl.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
// function printf<T extends readonly unknown[]>(...args: [...T]) {
//   process.stdout.write(util.format(...args));
// //  console.log(...args);
// }
function nextInt() {
    return Math.trunc(Number(words[pos++]));
}
function nextStr() {
    return words[pos++];
}
function af(l) {
    return Array.from({ length: l });
}
const INF = Number.MAX_SAFE_INTEGER;
const INIT = -1;
let n;
let k;
let adjList;
let ld;
function diam() {
    let dist = af(n + 1).fill(INIT);
    dist[1] = 0;
    let q = [1];
    for (let i = 0; i < q.length; i++) {
        let u = q[i];
        for (let v of adjList[u]) {
            if (dist[v] == INIT) {
                dist[v] = dist[u] + 1;
                q.push(v);
            }
        }
    }
    let s = INIT;
    let mx = INIT;
    for (let u = 1; u <= n; u++) {
        if (mx < dist[u]) {
            mx = dist[u];
            s = u;
        }
    }
    check(s != INIT);
    const p = af(n + 1).fill(INIT);
    dist.fill(INIT);
    dist[s] = 0;
    q = [s];
    for (let i = 0; i < q.length; i++) {
        let u = q[i];
        for (let v of adjList[u]) {
            if (dist[v] == INIT) {
                dist[v] = dist[u] + 1;
                p[v] = u;
                q.push(v);
            }
        }
    }
    let t = INIT;
    mx = INIT;
    for (let u = 1; u <= n; u++) {
        if (mx < dist[u]) {
            mx = dist[u];
            t = u;
        }
    }
    check(t != INIT);
    const rv = [t];
    for (let i = 0; i < mx; i++) {
        rv.push(p[t]);
        t = p[t];
    }
    return rv;
}
function getLd(s, ex) {
    const dist = af(n + 1).fill(INIT);
    const p = af(n + 1).fill(INIT);
    if (ex != INIT) {
        dist[ex] = 0;
    }
    dist[s] = 0;
    const q = [s];
    const topo = [];
    for (let i = 0; i < q.length; i++) {
        let u = q[i];
        for (let v of adjList[u]) {
            if (dist[v] == INIT) {
                dist[v] = dist[u] + 1;
                p[v] = u;
                q.push(v);
            }
        }
        topo.push(u);
    }
    for (let i = topo.length - 1; i > 0; i--) {
        let u = topo[i];
        ld[p[u]] = Math.max(ld[p[u]], ld[u] + 1);
    }
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        k = nextInt();
        adjList = Array.from({ length: n + 1 });
        for (let i = 0; i <= n; i++) {
            adjList[i] = [];
        }
        for (let i = 0; i + 1 < n; i++) {
            let u = nextInt();
            let v = nextInt();
            adjList[u].push(v);
            adjList[v].push(u);
        }
        // for (let u = 1; u <= n; u++) {
        //   for (let v of adjList[u]) {
        //     if (u > v) continue;
        //     console.log('u %d v %d', u, v);
        //   }
        // }
        const path = diam();
        let pathlen = path.length;
        ld = af(n + 1).fill(0);
        if ((pathlen % 2) == 0) {
            let r1 = path[Math.trunc(pathlen / 2)];
            let r2 = path[Math.trunc(pathlen / 2) - 1];
            getLd(r1, r2);
            getLd(r2, r1);
        }
        else {
            let root = path[Math.trunc(pathlen / 2)];
            getLd(root, INIT);
        }
        let ans = 0;
        for (let u = 1; u <= n; u++) {
            if (ld[u] >= k) {
                ans++;
            }
        }
        console.log(ans);
    }
}

const readline = require('readline')

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

function solve(n, k, edges) {
    if (n === 1) return 0
    // console.log(edges)
    const adj = {}
    const d = []
    edges.forEach(([a, b]) => {
        adj[a] = adj[a] || []
        adj[b] = adj[b] || []
        adj[a].push(b)
        adj[b].push(a)
        d[a] = (d[a] || 0) + 1
        d[b] = (d[b] || 0) + 1
    })

    let q = []
    for (let u = 1; u <= n; u++) {
        if (d[u] === 1) q.push(u)
    }
// console.log(d)
    let ans = n
    const visited = {}
    for (let i = 0; i < k; i++) {
        const next = []
        for (let j = 0; j < q.length; j++) {
            const u = q[j]
            if (visited[u]) continue
            visited[u] = 1
            ans--

            (adj[u] || []).forEach(v => {
                if (!visited[v] && --d[v] === 1) {
                    next.push(v)
                }
            })
        }
        q = next
        if (!q.length) break
    }
    return ans
}

'use strict';
const readline = require('readline');
const util = require('util');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let pos = 0;
const words = [];
rl.on('line', (line) => {
    words.push.apply(words, line.split(' ').filter(s => s != ''));
});
rl.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
    //  console.log(...args);
}
function nextInt() {
    return Math.trunc(Number(words[pos++]));
}
function nextStr() {
    return words[pos++];
}
function af(l) {
    return Array.from({ length: l });
}
const INF = Number.MAX_SAFE_INTEGER;
const INIT = -1;
let n;
let k;
let adjList;
let ld;
function diam() {
    let dist = af(n + 1).fill(INIT);
    dist[1] = 0;
    let q = [1];
    for (let i = 0; i < q.length; i++) {
        let u = q[i];
        for (let v of adjList[u]) {
            if (dist[v] == INIT) {
                dist[v] = dist[u] + 1;
                q.push(v);
            }
        }
    }
    let s = INIT;
    let mx = INIT;
    for (let u = 1; u <= n; u++) {
        if (mx < dist[u]) {
            mx = dist[u];
            s = u;
        }
    }
    check(s != INIT);
    const p = af(n + 1).fill(INIT);
    dist.fill(INIT);
    dist[s] = 0;
    q = [s];
    for (let i = 0; i < q.length; i++) {
        let u = q[i];
        for (let v of adjList[u]) {
            if (dist[v] == INIT) {
                dist[v] = dist[u] + 1;
                p[v] = u;
                q.push(v);
            }
        }
    }
    let t = INIT;
    mx = INIT;
    for (let u = 1; u <= n; u++) {
        if (mx < dist[u]) {
            mx = dist[u];
            t = u;
        }
    }
    check(t != INIT);
    const rv = [t];
    for (let i = 0; i < mx; i++) {
        rv.push(p[t]);
        t = p[t];
    }
    return rv;
}
function getLd(s, ex) {
    const dist = af(n + 1).fill(INIT);
    const p = af(n + 1).fill(INIT);
    if (ex != INIT) {
        dist[ex] = 0;
    }
    dist[s] = 0;
    const q = [s];
    const topo = [];
    for (let i = 0; i < q.length; i++) {
        let u = q[i];
        for (let v of adjList[u]) {
            if (dist[v] == INIT) {
                dist[v] = dist[u] + 1;
                p[v] = u;
                q.push(v);
            }
        }
        topo.push(u);
    }
    for (let i = topo.length - 1; i > 0; i--) {
        let u = topo[i];
        ld[p[u]] = Math.max(ld[p[u]], ld[u] + 1);
    }
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        k = nextInt();
        adjList = Array.from({ length: n + 1 });
        for (let i = 0; i <= n; i++) {
            adjList[i] = [];
        }
        for (let i = 0; i + 1 < n; i++) {
            let u = nextInt();
            let v = nextInt();
            adjList[u].push(v);
            adjList[v].push(u);
        }
        // for (let u = 1; u <= n; u++) {
        //   for (let v of adjList[u]) {
        //     if (u > v) continue;
        //     console.log('u %d v %d', u, v);
        //   }
        // }
        const path = diam();
        let pathlen = path.length;
        ld = af(n + 1).fill(0);
        if ((pathlen % 2) == 0) {
            let r1 = path[Math.trunc(pathlen / 2)];
            let r2 = path[Math.trunc(pathlen / 2) - 1];
            getLd(r1, r2);
            getLd(r2, r1);
        }
        else {
            let root = path[Math.trunc(pathlen / 2)];
            getLd(root, INIT);
        }
        let ans = 0;
        for (let u = 1; u <= n; u++) {
            if (ld[u] >= k) {
                ans++;
            }
        }
        printf("%d\n", ans);
    }
}

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

let n, k, g, rem, layer;

//q.push(x)
//q.shift() -> remove and return the leftmost element
//q.peek() -> return the leftmost element
//q.size()

class Queue {
	constructor () {
		this.a = [];
		this.p = 0;
	}

	push = (x) => this.a.push(x);
	shift = () => this.size() ? this.a[this.p++] : -1;
	peek = () => this.size() ? this.a[this.p] : -1;
	size  = () => this.a.length - this.p;
}

function main () {
	let T = rn();
	while (T--) {
		rl();
		[n, k] = rna();
		g = Array.from(Array(n), _ => []);
		rem = Array(n).fill(0);
		for (let i = 0; i < n - 1; i++) {
			let [u, v] = rna(); u--, v--;
			g[u].push(v);
			g[v].push(u);
			rem[u]++;
			rem[v]++;
		}
		layer = Array(n).fill(1);

		const q = new Queue();
		for (let i = 0; i < n; i++) if (rem[i] == 1) q.push(i);
		while (q.size()) {
			const u = q.shift();
			for (const v of g[u]) {
				rem[v]--;
				if (rem[v] == 1) {
					layer[v] = layer[u] + 1;
					q.push(v);
				}
			}
		}

		let ans = 0;
		for (let i = 0; i < n; i++) ans += layer[i] > k;
		console.log(ans);
	}
}

const readline = require('readline')

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

function solve(n, k, edges) {
    if (n === 1) return 0
    // console.log(edges)
    const adj = {}
    edges.forEach(([a, b]) => {
        adj[a] = adj[a] || []
        adj[b] = adj[b] || []
        adj[a].push(b)
        adj[b].push(a)
    })
// return
    let u = 1
    // let p = -1
    // while (1) {
    //     const has = (adj[u] || []).some(v => {
    //         if (v !== p) {
    //             p = u
    //             u = v
    //             return true
    //         }
    //     })
    //     if (!has) break
    // }
    // return
    const [hs, haschild] = dfs(adj, u, {}, k)
// console.log(u, hs, haschild)
    return dfs2(adj, u, {}, k, hs, haschild)
    // let ans = n
    // for (let i = 1; i <= n; i++) {
    //     if (removed[i]) ans--
    // }
    // return ans
}
function dfs(adj, r, visited, k) {
    const stack = [[r, 0, -1]]
    const hs = []
    const haschild = []
    while (stack.length) {
        const [u, i, p] = stack[stack.length - 1]
        // visited[u] = 1

        const nb = adj[u] || []
        if (!i) {
            // first visited
        }
        if (i < nb.length) {
            stack[stack.length - 1][1]++
            const v = nb[i]
            // if (!visited[v]) { // has circle
            if (v !== p) {
                stack.push([v, 0, u])
            }
        } else {
            // last visited
            hs[u] = 1
            haschild[u] = 0
            ;(adj[u] || []).forEach(v => {
                if (v !== p) {
                    hs[u] = Math.max(hs[u], hs[v] + 1)
                    if (hs[v] >= k) haschild[u]++
                }
            })
            // if (hs[u] <= k) removed[u] = 1
            stack.pop()
        }
    }
    return [hs, haschild]
}
function dfs2(adj, r, visited, k, hs, haschild) {
    const stack = [[r, 0, -1]]
    let count = 0
    while (stack.length) {
        const [u, i, p] = stack[stack.length - 1]
        // visited[u] = 1

        const nb = adj[u] || []
        if (!i) {
            // first visited
            const rh = hs[r] - hs[u] + 1
            if (hs[u] > k && (rh > k || (rh === k && haschild[u] > 1))) {
                // console.log('left', u)
                count++
            }
        }
        if (i < nb.length) {
            stack[stack.length - 1][1]++
            const v = nb[i]
            // if (!visited[v]) { // has circle
            if (v !== p) {
                stack.push([v, 0, u])
            }
        } else {
            // last visited
            stack.pop()
        }
    }
    return count
}

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++]
    // if (t === 6) {
    //     console.log([7, 0, 0, 3, 1, 2].join('\n'))
    //     return
    // }
    const output = []
    for (let i = 0; i < t; i++) {
        l++
        const [n, k] = lines[l++].trim().split(' ').map(Number)
        const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))
        l += n - 1
        console.log(solve(n, k, edges))
        // output[i] = solve(n, k, edges)
    }
    // console.log(output.join('\n'))
// })()
})

function solve(n, k, edges) {
    if (n === 1) return 0
    // console.log(edges)
    const adj = {}
    edges.forEach(([a, b]) => {
        adj[a] = adj[a] || []
        adj[b] = adj[b] || []
        adj[a].push(b)
        adj[b].push(a)
    })
// return
    let u = 1
    // let p = -1
    // while (1) {
    //     const has = (adj[u] || []).some(v => {
    //         if (v !== p) {
    //             p = u
    //             u = v
    //             return true
    //         }
    //     })
    //     if (!has) break
    // }
    // return
    const [hs, haschild] = dfs(adj, u, {}, k)
// console.log(u, hs, haschild)
    return dfs2(adj, u, {}, k, hs, haschild)
    // let ans = n
    // for (let i = 1; i <= n; i++) {
    //     if (removed[i]) ans--
    // }
    // return ans
}
function dfs(adj, r, visited, k) {
    const stack = [[r, 0, -1]]
    const hs = []
    const haschild = []
    while (stack.length) {
        const [u, i, p] = stack[stack.length - 1]
        // visited[u] = 1

        const nb = adj[u] || []
        if (!i) {
            // first visited
        }
        if (i < nb.length) {
            stack[stack.length - 1][1]++
            const v = nb[i]
            // if (!visited[v]) { // has circle
            if (v !== p) {
                stack.push([v, 0, u])
            }
        } else {
            // last visited
            hs[u] = 1
            haschild[u] = 0
            ;(adj[u] || []).forEach(v => {
                if (v !== p) {
                    hs[u] = Math.max(hs[u], hs[v] + 1)
                    if (hs[v] >= k) haschild[u]++
                }
            })
            // if (hs[u] <= k) removed[u] = 1
            stack.pop()
        }
    }
    return [hs, haschild]
}
function dfs2(adj, r, visited, k, hs, haschild) {
    const stack = [[r, 0, -1]]
    let count = 0
    while (stack.length) {
        const [u, i, p] = stack[stack.length - 1]
        // visited[u] = 1

        const nb = adj[u] || []
        if (!i) {
            // first visited
            const rh = hs[r] - hs[u] + 1
            if (hs[u] > k && (rh > k || (haschild[u] > 1))) {
                // console.log('left', u)
                count++
            }
        }
        if (i < nb.length) {
            stack[stack.length - 1][1]++
            const v = nb[i]
            // if (!visited[v]) { // has circle
            if (v !== p) {
                stack.push([v, 0, u])
            }
        } else {
            // last visited
            stack.pop()
        }
    }
    return count
}

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++]
    // if (t === 6) {
    //     console.log([7, 0, 0, 3, 1, 2].join('\n'))
    //     return
    // }
    const output = []
    for (let i = 0; i < t; i++) {
        l++
        const [n, k] = lines[l++].trim().split(' ').map(Number)
        const edges = lines.slice(l, l + n - 1).map(str => str.trim().split(' ').map(Number))
        l += n - 1
        console.log(solve(n, k, edges))
        // output[i] = solve(n, k, edges)
    }
    // console.log(output.join('\n'))
// })()
})

function solve(n, k, edges) {
    if (n === 1) return k < 1 ? 1 : 0
    // console.log(edges)
    const adj = {}
    edges.forEach(([a, b]) => {
        adj[a] = adj[a] || []
        adj[b] = adj[b] || []
        adj[a].push(b)
        adj[b].push(a)
    })
// return
    let u = 1
    let p = -1
    while (1) {
        const has = adj[u].some(v => {
            if (v !== p) {
                p = u
                u = v
                return true
            }
        })
        if (!has) break
    }
    // return
    const hs = dfs(adj, u, {})
// console.log(u, hs)
    return dfs2(adj, u, {}, hs, k)
}
function dfs(adj, r, visited) {
    const stack = [[r, 0, -1]]
    const hs = []
    while (stack.length) {
        const [u, i, p] = stack[stack.length - 1]
        // visited[u] = 1

        const nb = adj[u] || []
        if (!i) {
            // first visited
        }
        if (i < nb.length) {
            stack[stack.length - 1][1]++
            const v = nb[i]
            // if (!visited[v]) { // has circle
            if (v !== p) {
                stack.push([v, 0, u])
            }
        } else {
            // last visited
            hs[u] = 1
            ;(adj[u] || []).forEach(v => {
                if (v !== p) hs[u] = Math.max(hs[u], hs[v] + 1)
            })
            stack.pop()
        }
    }
    return hs
}
function dfs2(adj, r, visited, hs, k) {
    const stack = [[r, 0, -1]]
    let count = 0
    while (stack.length) {
        const [u, i, p] = stack[stack.length - 1]
        // visited[u] = 1

        const nb = adj[u] || []
        if (!i) {
            // first visited
            if (hs[u] > k && hs[r] - hs[u] + 1 > k) {
                count++
            }
        }
        if (i < nb.length) {
            stack[stack.length - 1][1]++
            const v = nb[i]
            // if (!visited[v]) { // has circle
            if (v !== p) {
                stack.push([v, 0, u])
            }
        } else {
            // last visited
            stack.pop()
        }
    }
    return count
}

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

let n, k;
let g;
let mp = [];
let ans = 0;

const key = (x, y) => x + ',' + y;

function dfs (u=0, p=-1) {
	let mx = 0;
	for (const c of g[u]) {
		if (c == p) continue;
		const tm = dfs(c, u);
		mp[key(c, u)] = tm + 1;
		//console.log('***', c, u, mp[key(c, u)]);
		mx = Math.max(mx, tm);
	}
	return mx + 1;
}

function dfs2 (u=0, p=-1, inCost=0) {
	mp[key(p, u)] = inCost;

	const cur = [];
	cur.push(1);
	for (const c of g[u]) {
		cur.push(mp[key(c, u)]);
		//console.log(c, u, mp[key(c, u)]);
	}
	cur.sort((x, y) => y - x);

	//console.log({u, cur, k})
	if (cur[1] <= k) ans--;

	for (const c of g[u]) {
		if (c == p) continue;
		const outCost = mp[key(c, u)] == cur[0] ? cur[1] : cur[0];
		dfs2(c, u, outCost + 1);
	}
}

function main () {
	let T = rn();
	while (T--) {
		rl();
		[n, k] = rna();
		g = Array.from(Array(n), _ => []);
		for (let i = 0; i < n - 1; i++) {
			let [u, v] = rna(); u--, v--;
			g[u].push(v);
			g[v].push(u);
		}

		mp = [];
		ans = n;
		dfs();
		dfs2();

		console.log(ans);
	}
}


function solve(input) {
    input.forEach(e => {
        const dots = e.map(data => data.split(' '));
        // console.log(dots)

        const setDotsY = new Set(dots.map(data => data[1]));
        const arrDotsY = [...setDotsY];
        if (arrDotsY.length === 2) {
            const a = countObj(dots.map(data => data[1]), arrDotsY[0]);
            const b = countObj(dots.map(data => data[1]), arrDotsY[1]);
            if (a > b) {
                if (parseInt(arrDotsY[0]) > parseInt(arrDotsY[1])) {
                    const x = dots.filter(data => data[1] === arrDotsY[0])
                    console.log(Math.abs(x[0][0] - x[1][0]))
                } else console.log(0);
            } else {
                if (parseInt(arrDotsY[1]) > parseInt(arrDotsY[0])) {
                    const x = dots.filter(data => data[1] === arrDotsY[1])
                    console.log(Math.abs(x[0][0] - x[1][0]))
                }
                else console.log(0);
            }
        } else if (arrDotsY.length === 1) {
            console.log(0)
        } else {
            console.log(0);
        }
    });
}

const countObj = (arr, val)  => arr.reduce((a, v) => (v == val ? a + 1 : a), 0);

/** =========== DEFAULT FORMAT ==============
 *
 *  */
function set_n_line() {
    // set return 0 if the problem needs dynamic n line inputs
    // set return n > 0 if the problem needs fixed n  line inputs
    return 3
}
const readline = require('readline').createInterface({ input: process.stdin });
let inputs = []; let sub_input = []; let t = 0; let n_line_subinput = set_n_line();
function fillInput(line) {
    // dynamic n_line
    if (n_line_subinput == 0) n_line_subinput = parseInt(line)
    else if (sub_input.length < n_line_subinput) {
        sub_input.push(line)
        if (sub_input.length == n_line_subinput) {
            inputs.push(sub_input); sub_input = [];
            n_line_subinput = set_n_line();
        }
    }
}

readline.on('line', line => {
    if (t == 0) t = parseInt(line)
    else if (inputs.length < t) {
        fillInput(line)
        if (inputs.length == t) { solve(inputs);readline.close() }
    }
});
/* =========== DEFAULT FORMAT END ============== */

'use strict';

function solve(a) {
  for (let i = 0; i < 3; i++) {
    const x = a[i];
    for (let j = i + 1; j < 3; j++) {
      const y = a[j],
            z = a.find((_, k) => k !== i && k !== j);
      if (x[1] === y[1] && x[1] !== 0 && z[1] < x[1]) return Math.abs(x[0] - y[0]);
    }
  }
  return 0;
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const a = [];
      let tmp = 3;
      while (tmp--) {
        a.push((await read()).split(' ').map(Number));
      }
      res[i] = solve(a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

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 [x1, y1] = readline().split(' ').map(Number);
        let [x2, y2] = readline().split(' ').map(Number);
        let [x3, y3] = readline().split(' ').map(Number);

        if (y1 !== y2 && y1 !== y3 && y2 !== y3) {
            output(0);
        } else if (y1 === y2 && y3 < y1) {
            output(Math.abs(x1 - x2));
        } else if (y1 === y3 && y2 < y1) {
            output(Math.abs(x1 - x3));
        } else if (y2 === y3 && y1 < y2) {
            output(Math.abs(x2 - x3));
        } else {
            output(0);
        }
    }
}

'use strict';
const { throws } = require('assert');

 /*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 MOD = 1e9+7;

let sqr = x=>x*x;
let dist = (p1, p2)=>{
  return Math.sqrt(sqr(p1.x-p2.x)+sqr(p1.y-p2.y));
};

const calc = (arr)=>{
  let ans = 0;
  for (let i=0; i<3; i++){
    for (let j=i+1; j<3; j++){
      if (arr[i].y==arr[j].y){
        for (let k=0; k<3; k++){
          if (k==i || k==j) continue;
          if (arr[k].y<arr[j].y){
            ans += dist(arr[i], arr[j])
          }
        }
      }
    }
  }
  return ans;
};

function main() {
    let T = +readline()
    while (T--){
      let arr = [];
      for (let i=0; i<3; i++){
        let [x, y] = ra();
        arr.push({x, y});
      }
      print(calc(arr));
    }
}

E.calc = calc;

//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 x1 = nextInt();
		var y1 = nextInt();
		var x2 = nextInt();
		var y2 = nextInt();
		var x3 = nextInt();
		var y3 = nextInt();
		if(y1 == y2){
			if(y3 < y1){
				myout(Math.abs(x1 - x2));
			}else{
				myout(0);
			}
		}else if(y1 == y3){
			if(y2 < y1){
				myout(Math.abs(x1 - x3));
			}else{
				myout(0);
			}
		}else if(y2 == y3){
			if(y1 < y2){
				myout(Math.abs(x2 - x3));
			}else{
				myout(0);
			}
		}else{
			myout(0);
		}
	}
}

function solve(input) {
    input.forEach(e => {
        const dots = e.map(data => data.split(' '));
        // console.log(dots)

        const setDotsY = new Set(dots.map(data => data[1]));
        const arrDotsY = [...setDotsY];
        if (arrDotsY.length === 2) {
            const a = countObj(dots.map(data => data[1]), arrDotsY[0]);
            const b = countObj(dots.map(data => data[1]), arrDotsY[1]);
            if (a > b) {
                if (parseInt(arrDotsY[0]) > parseInt(arrDotsY[1])) console.log(arrDotsY[0])
                else console.log(0);
            } else {
                if (parseInt(arrDotsY[1]) > parseInt(arrDotsY[0])) console.log(arrDotsY[1])
                else console.log(0);
            }
        } else if (arrDotsY.length === 1) {
            console.log(0)
        } else {
            console.log(0);
        }
    });
}

const countObj = (arr, val)  => arr.reduce((a, v) => (v == val ? a + 1 : a), 0);

/** =========== DEFAULT FORMAT ==============
 *
 *  */
function set_n_line() {
    // set return 0 if the problem needs dynamic n line inputs
    // set return n > 0 if the problem needs fixed n  line inputs
    return 3
}
const readline = require('readline').createInterface({ input: process.stdin });
let inputs = []; let sub_input = []; let t = 0; let n_line_subinput = set_n_line();
function fillInput(line) {
    // dynamic n_line
    if (n_line_subinput == 0) n_line_subinput = parseInt(line)
    else if (sub_input.length < n_line_subinput) {
        sub_input.push(line)
        if (sub_input.length == n_line_subinput) {
            inputs.push(sub_input); sub_input = [];
            n_line_subinput = set_n_line();
        }
    }
}

readline.on('line', line => {
    if (t == 0) t = parseInt(line)
    else if (inputs.length < t) {
        fillInput(line)
        if (inputs.length == t) { solve(inputs);readline.close() }
    }
});
/* =========== DEFAULT FORMAT END ============== */

function solve(input) {
    input.forEach(e => {
        const dots = e.map(data => data.split(' '));
        // console.log(dots)

        const setDotsY = new Set(dots.map(data => data[1]));
        const arrDotsY = [...setDotsY];
        if (arrDotsY.length === 2) {
            const a = countObj(dots.map(data => data[1]), arrDotsY[0]);
            const b = countObj(dots.map(data => data[1]), arrDotsY[1]);
            if (a > b) {
                if (parseInt(arrDotsY[0]) > parseInt(arrDotsY[1])) console.log(arrDotsY[0])
                else console.log(0);
            } else {
                if (parseInt(arrDotsY[1]) > parseInt(arrDotsY[0])) console.log(arrDotsY[1])
                else console.log(0);
            }
        } else if (arrDotsY.length === 1) {
            console.log(arrDotsY[0])
        } else {
            console.log(0);
        }
    });
}

const countObj = (arr, val)  => arr.reduce((a, v) => (v == val ? a + 1 : a), 0);

/** =========== DEFAULT FORMAT ==============
 *
 *  */
function set_n_line() {
    // set return 0 if the problem needs dynamic n line inputs
    // set return n > 0 if the problem needs fixed n  line inputs
    return 3
}
const readline = require('readline').createInterface({ input: process.stdin });
let inputs = []; let sub_input = []; let t = 0; let n_line_subinput = set_n_line();
function fillInput(line) {
    // dynamic n_line
    if (n_line_subinput == 0) n_line_subinput = parseInt(line)
    else if (sub_input.length < n_line_subinput) {
        sub_input.push(line)
        if (sub_input.length == n_line_subinput) {
            inputs.push(sub_input); sub_input = [];
            n_line_subinput = set_n_line();
        }
    }
}

readline.on('line', line => {
    if (t == 0) t = parseInt(line)
    else if (inputs.length < t) {
        fillInput(line)
        if (inputs.length == t) { solve(inputs);readline.close() }
    }
});
/* =========== DEFAULT FORMAT END ============== */

function solve(input) {
    input.forEach(e => {
        const dots = e.map(data => data.split(' '));
        // console.log(dots)

        const setDotsY = new Set(dots.map(data => data[1]));
        const arrDotsY = [...setDotsY];
        if (arrDotsY.length === 2) {
            const a = countObj(dots.map(data => data[1]), arrDotsY[0]);
            const b = countObj(dots.map(data => data[1]), arrDotsY[1]);
            if (a > b) {
                console.log(arrDotsY[0])
            } else {
                console.log(arrDotsY[1])
            }
        } else if (arrDotsY.length === 1) {
            console.log(arrDotsY[0])
        } else {
            console.log(0);
        }
    });
}

const countObj = (arr, val)  => arr.reduce((a, v) => (v == val ? a + 1 : a), 0);

/** =========== DEFAULT FORMAT ==============
 *
 *  */
function set_n_line() {
    // set return 0 if the problem needs dynamic n line inputs
    // set return n > 0 if the problem needs fixed n  line inputs
    return 3
}
const readline = require('readline').createInterface({ input: process.stdin });
let inputs = []; let sub_input = []; let t = 0; let n_line_subinput = set_n_line();
function fillInput(line) {
    // dynamic n_line
    if (n_line_subinput == 0) n_line_subinput = parseInt(line)
    else if (sub_input.length < n_line_subinput) {
        sub_input.push(line)
        if (sub_input.length == n_line_subinput) {
            inputs.push(sub_input); sub_input = [];
            n_line_subinput = set_n_line();
        }
    }
}

readline.on('line', line => {
    if (t == 0) t = parseInt(line)
    else if (inputs.length < t) {
        fillInput(line)
        if (inputs.length == t) { solve(inputs);readline.close() }
    }
});
/* =========== DEFAULT FORMAT END ============== */

'use strict';

function solve(a) {
  for (let i = 0; i < 3; i++) {
    const x = a[i];
    for (let j = i + 1; j < 3; j++) {
      const y = a[j];
      if (x[1] === y[1] && x[1] !== 0) return Math.abs(x[0] - y[0]);
    }
  }
  return 0;
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const a = [];
      let tmp = 3;
      while (tmp--) {
        a.push((await read()).split(' ').map(Number));
      }
      res[i] = solve(a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});


const readline = require('readline');

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

let counter=0, N

rl.on('line', (input) => {
   if(counter==0){
      N=parseInt(input);
      counter++;
   }
   else
   {
       let ans="NO", helper="";
       for(let i=0; i<N-1; i++){
           if(input[i]!=input[i+1]){
               ans="YES";
               helper=input.substr(i,2);
;               break;
           }
       }
       console.log(ans);
       console.log(helper);
       rl.close();
   }

  });

const readline = require('readline');

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

let n;
rl.on('line', function(line){
	if (!n) {
		n = parseInt(line);
	} else {
		const s = line;
		let i = 0;
		while (s[i] === s[i + 1] && i < s.length) {
			i++;
		}
		if (i < s.length - 1) {
			console.log('YES');
			console.log(s.substr(i, 2));
		} else {
			console.log('NO');
		}
		rl.close();
	}
});

process.stdin.on('data', function(chunk){
	var lns = chunk.toString().replace(/\r/g, "").split(/\n/),r;
	(r = lns[1].match(/(.)(?!\1)/g)).length > 1 ? console.log('YES\n' + r[0] + r[1]) : console.log('NO');
});

var length = readline();
var text = readline();
  var answer = "";
  for (var i = 0; i < length - 1; i ++) {
      var firstChar = text.charAt(i);
      var secondChar = text.charAt(i + 1);

    if (firstChar != secondChar) {
      answer = firstChar + secondChar;
      break;
    }
  }

  if (answer === "") {
    write("NO");
  } else {
    write("YES\n");
    write(answer);
  }

readline();
var str = readline(), answer;
for(var i = 1; i < str.length; i++) {
    if(str[i] !== str[i-1]) {
        answer = str[i-1] + str[i];
        break;
    }
}

if(answer) {
    print('YES');
    print(answer);
} else {
    print('NO');
}

process.stdin.on('data', function(chunk){
	var lns = chunk.toString().replace(/\r/g, "").split(/\n/),r;
	(r = lns[1].match(/(.)(?!\1)(?!$)/g)) ? console.log('YES\n' + r[1] + r[2]) : console.log('NO');
});

var length = readline();
var text = readline();
var charStartIndex = 97;
var charIndexArray = [];

for (var i = 0; i < length; i ++) {
    var charCode = text.charAt(i).charCodeAt(0);
    if (charIndexArray[charCode - charStartIndex] === undefined) {
       charIndexArray[charCode - charStartIndex] = 1;
    } else {
       charIndexArray[charCode - charStartIndex] += 1;
    }
}

var answer = "";
for (var i = 0; i < charIndexArray.length; i ++) {
  if (charIndexArray[i] <= charIndexArray.length / 2) {
    answer = String.fromCharCode(charIndexArray[i] + 97);
    break;
  }
}

if (answer === "") {
  write("NO");
} else {
  write("YES");
  write(answer);
}

var length = readline();
var text = readline();
var charStartIndex = 97;
var charIndexArray = [];

for (var i = 0; i < length; i ++) {
    var charCode = text.charAt(i).charCodeAt(0);
    if (charIndexArray[charCode - charStartIndex] === undefined) {
       charIndexArray[charCode - charStartIndex] = 1;
    } else {
       charIndexArray[charCode - charStartIndex] += 1;
    }
}

var answer = "";
for (var i = 0; i < charIndexArray.length; i ++) {
  if (charIndexArray[i] <= charIndexArray.length / 2) {
    answer = String.fromCharCode(charIndexArray[i] + 97);
    break;
  }
}

if (answer === "") {
  write("NO");
} else {
  write("YES\n");
  write(answer);
}

var length = readline();
var text = readline();
var charStartIndex = 97;
var charIndexArray = [];

for (var i = 0; i < length; i ++) {
    var charCode = text.charAt(i).charCodeAt(0);
    if (charIndexArray[charCode - charStartIndex] === undefined) {
       charIndexArray[charCode - charStartIndex] = 1;
    } else {
       charIndexArray[charCode - charStartIndex] += 1;
    }
}

for (var i = 0; i < charIndexArray.length; i ++) {
  if (charIndexArray[i] <= charIndexArray.length / 2) {
    write("YES");
    write(String.fromCharCode(charIndexArray[i] + 97));
  }
}

write("NO");


const fs = require("fs");

const input = fs.readFileSync(0, "utf8").trim().split("\n");

const testCases = [];
let T;

const gcd = (a, b) => (b ? gcd(b, a % b) : a);

function parseInput() {
  T = parseInt(input[0]);
  let index = 0;

  for (let i = 0; i < T; i++) {
    index++;
    const n = parseInt(input[index]);
    index++;
    const a = input[index].split(" ").map((item) => parseInt(item));
    const testCase = {
      n,
      a,
    };

    testCases.push(testCase);
  }
}

function solution(testCase) {
  const { n, a } = testCase;
  // console.log(n, a);
  let g = a[0];
  for (let i = 1; i < n; i++) g = gcd(g, a[i]);

  if (g == 1) {
    console.log(0);
    return;
  }

  for (let i = 0; i < n; i++) {
    a[i] = gcd(g, i + 1);
  }

  let result = Infinity;

  const check = (gg, ind, val) => {
    // console.log("check", gg, ind, val);
    if (gg == 1) {
      if (val < result) result = val;
      return;
    }
    if (ind == 0) return;

    check(gg, ind - 1, val);
    check(gcd(gg, a[ind - 1]), ind - 1, val + n - ind + 1);
  };

  check(g, n, 0);
  console.log(result);
}

parseInput();

testCases.forEach(solution);

function solve() {
    var n = Number(read());
    var a = readArray(Number);
    var allGcd = a[0];
    for (var i = 1; i < n; i++) {
        allGcd = gcd(allGcd, a[i]);
    }
    if (allGcd === 1) {
        write(0);
        return;
    }
    if (gcd(allGcd, n) === 1) {
        write(1);
        return;
    }
    if (gcd(allGcd, n - 1) === 1) {
        write(2);
        return;
    }
    write(3);
}

function start() {
    var T = 1;
    T = Number(read());
    for (var t = 0; t < T; t++) {
        solve();
    }
    writeAns();
}

function gcd(a, b) {
    if (b === 0) {
        return a;
    }
    return gcd(b, a % b)
}

var MEMORY;
var MEMORY_INDEX = 0;
var ANS = '';

try {
    initInput(start);
} catch (e) {
    console.log(e);
}
function readArray(f) {
    return read().split(' ').map(f);
}

function sortNumbers(a, b) {
    return a - b;
}
function sortNumbersDec(a, b) {
    return b - a;
}
var ANS;
// вывод через ANS быстрее, но ест кучу памяти.
// К тому же, максимальная длина строки - 2097151.
function write(value) {
    // console.log(value);
    ANS += value + '\n';
}
function writeAns() {
    if (ANS) {
        console.log(ANS);
    }
}
function read() {
    return MEMORY[MEMORY_INDEX++];
}
function initInput(callback) {
    var fs = require('fs');
    var isLocalStart = process.argv[2] === 'lorelvate';
    if (!isLocalStart) {
        MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
        callback();
        return;
    }
    var path = require('path');
    fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {
        if (err) {
            write(err);
            return;
        }
        MEMORY = data.split('\r\n');
        callback();
    });
}

const fs = require("fs");

const input = fs.readFileSync(0, "utf8").trim().split("\n");

const testCases = [];
let T;

const gcd = (a, b) => (b ? gcd(b, a % b) : a);

function parseInput() {
  T = parseInt(input[0]);
  let index = 0;

  for (let i = 0; i < T; i++) {
    index++;
    const n = parseInt(input[index]);
    index++;
    const a = input[index].split(" ").map((item) => parseInt(item));
    const testCase = {
      n,
      a,
    };

    testCases.push(testCase);
  }
}

function solution(testCase) {
  const { n, a } = testCase;
  // console.log(n, a);

  let g = a[0];
  for (let i = 1; i < n; i++) g = gcd(g, a[i]);

  // console.log("gcd", g);

  let result = 0;
  let i = n;
  while (g != 1) {
    // console.log("while", i);
    const gg = gcd(g, i);
    if (gg != g) {
      // console.log("Found", g, gg, i, n, n - i + 1);
      g = gg;
      result += n - i + 1;
    }
    i--;
  }

  console.log(result);
}

parseInput();

testCases.forEach(solution);


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

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

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

		let ones = 0, zeros = 0;
		for (let i = 0; i < n; i++) {
			ones += a[i] == 1;
			zeros += a[i] == 0;
		}

		const ans = BigInt(ones) << BigInt(zeros);

		console.log(ans.toString());
	}
}

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) {
    let c0 = 0
    let c1 = 0
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] === 0) c0++
        if (arr[i] === 1) c1++
    }
    let ans = BigInt(c1)
    for (let i = 0; i < c0; i++) {
        ans = ans * 2n
    }
    return ans.toString()
}

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

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

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

		let ones = 0, zeros = 0;
		for (let i = 0; i < n; i++) {
			ones += a[i] == 1;
			zeros += a[i] == 0;
		}

		const ans = BigInt(ones)*1n<<BigInt(zeros);

		console.log(ans.toString());
	}
}

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

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

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

		let ones = 0, zeros = 0;
		for (let i = 0; i < n; i++) {
			ones += a[i] == 1;
			zeros += a[i] == 0;
		}

		const ans = BigInt(ones)*2n**BigInt(zeros);

		console.log(ans.toString());
	}
}

function solve() {
   read();
   let c1 = 0n;
   let c0 = 0n;
   readArray((value) => {
      if (value === '0') {
         c0 += 1n;
      }
      if (value === '1') {
         c1 += 1n;
      }
   });
   write(c1 * (1n << c0));
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function init() {
   try {
      var T;
      T = 1;
      T = Number(read());
      for (var t = 0; t < T; t++) {
         solve();
      }
   } catch (e) {
      write(e);
   }
}

function readArray(mapF) {
   var res = read().split(' ');
   if (mapF) {
      res = res.map(mapF);
   }
   return res;
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }
   MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\r\n');
}
init();

function write(value) {
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   if (isNode) {
      return MEMORY;
   }
   var res = [];
   var x;
   while (x = read()) {
      res.push(x);
   }
   return res;
}

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

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

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

		let ones = 0, zeros = 0;
		for (let i = 0; i < n; i++) {
			ones += a[i] == 1;
			zeros += a[i] == 0;
		}

		const ans = ones*2**zeros;

		console.log(ans);
	}
}

function solve() {
   read();
   let c1 = 0n;
   let c0 = 0n;
   readArray((value) => {
      if (value === '0') {
         c0 += 1n;
      }
      if (value === '1') {
         c1 += 1n;
      }
   });
   const d = c0 === 0n ? 1n : (c0 << 1n);
   write(c1 * d);
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function init() {
   try {
      var T;
      T = 1;
      T = Number(read());
      for (var t = 0; t < T; t++) {
         solve();
      }
   } catch (e) {
      write(e);
   }
}

function readArray(mapF) {
   var res = read().split(' ');
   if (mapF) {
      res = res.map(mapF);
   }
   return res;
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }
   MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\r\n');
}
init();

function write(value) {
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   if (isNode) {
      return MEMORY;
   }
   var res = [];
   var x;
   while (x = read()) {
      res.push(x);
   }
   return res;
}

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) {
    let c0 = 0
    let c1 = 0
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] === 0) c0++
        if (arr[i] === 1) c1++
    }
    return c1 * Math.pow(2, c0)
}