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] * 1;
  let i = 1;
  while (i <= testCases) {
    let int = data[i].split(' ');
    let s = int[0] * 1;
    let d = int[1] * 1;
    console.log(Math.min(s,d, Math.floor((s+d)/3)));
    i += 1;
  }
}

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

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array(t);
  for(var i = 0; i < t; i++){
    var one = nextIntArray();
    var a = Math.min(one[0],one[1]);
    var b = Math.max(one[0],one[1]);
    if(a * 2 <= b){
      output[i] = a;
      continue;
    }
    var count = b - a;
    var tmp = b;
    b -= (tmp - a) * 2;
    a -= (tmp - a);
    //myerr({a,b});
    count += 2 * Math.floor(a / 3);
    var tmp = a;
    a -= Math.floor(tmp / 3) * 3;
    b -= Math.floor(tmp / 3) * 3;
    //myerr({a,b});
    if(a > 0 && b > 1){
      count++;
    }
    output[i] = count;
  }
  myout(myconv(output,9));
}

"use strict";

//readline().split(' ').map(Number);

function sec(){
    var arr = readline().split(' ').map(Number);
    var ans = Math.min(arr[0],arr[1],parseInt((arr[0]+arr[1])/3));
    /*
    var ans = 0;
    while (arr[0]>0 && arr[1]>0){
        //print(arr[0]+' '+arr[1]);
        if(arr[0]>=arr[1]){
            ans += parseInt(arr[0]/2);
            arr[1] -= parseInt(arr[0]/2);
            arr[0] -= parseInt(arr[0]/2)*2;
        }
        else if(arr[0]<arr[1]){
            ans += parseInt(arr[1]/2);
            arr[0] -= parseInt(arr[1]/2);
            arr[1] -= parseInt(arr[1]/2)*2;
        }
    }*/
    print(ans);
}

function main(){
    var t = readline();
    while(t--){
        sec();
    }
}

main();

const data = [];

//const fs = require('fs');
//const inputStream = fs.createReadStream("./in.txt");
const inputStream = process.stdin;

class DoubleIter {
    constructor(iter) {
        this.iter = iter.values();
        this.current = this.iter.next();
        this.iterOfCurrent = this.current.value.values();
    }

    [Symbol.iterator]() {
        return {
            next: () => {
                let { value, done } = this.iterOfCurrent.next();
                if (!done) {
                    return {value, done}
                } else {
                    do {
                        this.current = this.iter.next();
                        if (this.current.done)
                            return { value: undefined, done: true };
                        this.iterOfCurrent = this.current.value.values();
                        ({ value, done } = this.iterOfCurrent.next());
                    } while (done);
                    return {value, done};
                }
            }
        }
    }
}

class Scanner {
    constructor(iterable) {
        this.iter = iterable[Symbol.iterator]();
    }

    getWord() {
        const res = [];
        let {value, done} = this.iter.next();
        while (!done && !this.isLetter(value))
            ({value, done} = this.iter.next());
        if (!done) {
            while (!done && this.isLetter(value)) {
                res.push(value);
                ({value, done} = this.iter.next());
            }
        }
        return String.fromCharCode(...res);
    }

    isLetter(char) {
        return (
            (48 <= char && char <= 57) || // 0-9
            (97 <= char && char <= 122) || // a-z
            (65 <= char && char <= 90) // A-Z
        );
    }
}

inputStream.on("data", (chunk) => {
    data.push(chunk);
});

inputStream.on("end", () => {
    start();
});

function start() {
    const scan = new Scanner(new DoubleIter(data));
    const t = +scan.getWord();
    for (let i = 0; i < t; i++) {
        let a = +scan.getWord();
        let b = +scan.getWord();
        //console.log(a, b);
        if (a > b) {
            const t = a;
            a = b;
            b = t;
        }
        const mid = (2*a - b) / 3;
        const x1 = Math.floor(mid);
        let res1 = ~~((x1 + b) / 2);
        const x2 = Math.ceil(mid);
        let res2 = a - x2;
        if (x1 < 0)
            res1 = 0;
        if (x2 < 0)
            res2 = a;
        const mx = Math.max(res1, res2);

        process.stdout.write(mx.toString() + '\n');
    }
    process.stdout.end()
}

function func(a, b, c) {
    a -= c;
    b -= c;
    return Math.min(c, Math.max(a, b));
}

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");
    let testCases = data[0] * 1;
    let i = 1;
    while (i <= testCases) {
        let line = data[i].split(" ");
        let stick = line[0] * 1;
        let diamonds = line[1] * 1;
        console.log(Math.min(stick, Math.min(diamonds, Math.floor((stick + diamonds) / 3))));
        i += 1;
    }
}

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

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array(t);
  for(var i = 0; i < t; i++){
    var one = nextIntArray();
    one.sort(function(mae,ato){
    	return mae - ato;
    });
    var a = one[0];
    var b = one[1];
    if(a * 2 <= b){
      output[i] = a;
      continue;
    }
    var count = 2 * Math.floor(Math.min(a, b) / 3);
    var tmp = a;
    a -= Math.floor(tmp / 3) * 3;
    b -= Math.floor(tmp / 3) * 3;
    //myerr({a,b});
    if(a > 0 && b > 1){
      count++;
    }
    output[i] = count;
  }
  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] * 1;
  let i = 1;
  while (i <= testCases) {
    let int = data[i].split(' ');
    let s = int[0] * 1;
    let d = int[1] * 1;

    let e = 0;
    if (s === 0 || d === 0) {
      console.log(e);
    } else console.log(Math.floor((s + d) / 3));
    i += 1;
  }
}

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] * 1;
  let i = 1;
  while (i <= testCases) {
    let int = data[i].split(' ');
    let s = int[0] * 1;
    let d = int[1] * 1;
    let e = 0;
    if (s === 0 || d === 0) {
      console.log(e);
    } else if (s === d) {
      while (s > 1) {
        s -= e % 2 ? 2 : 1;
        e += 1;
      }
      console.log(e);
    } else if (d > s) {
      e = Math.floor(d / 2);
      const diff = s - e;
      if (diff === 0 || diff === 1) console.log(e);
      else if (diff > 1) console.log(e + 1);
      else if (s % 2) console.log(s + 1);
      else console.log(s);
    } else {
      e = Math.floor(s / 2);
      const diff = d - e;
      if (diff === 0 || diff === 1) console.log(e);
      else if (diff > 1) console.log(e + 1);
      else if (d % 2) console.log(d + 1);
      else console.log(d);
    }
    i += 1;
  }
}

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] * 1;
  let i = 1;
  while (i <= testCases) {
    let int = data[i].split(' ');
    let s = int[0] * 1;
    let d = int[1] * 1;
    let e = 0;
    if (s === 0 || d === 0) {
      console.log(e);
    } else if (s === d) {
      while (s > 1) {
        s -= e % 2 ? 2 : 1;
        e += 1;
      }
      console.log(e);
    } else if (d > s) {
      e = Math.floor(d / 2);
      const diff = s - e;
      if (diff === 0 || diff === 1) console.log(e);
      else console.log(e + 1);
    } else {
      e = Math.floor(s / 2);
      const diff = d - e;
      if (diff === 0 || diff === 1) console.log(e);
      else console.log(e + 1);
    }
    i += 1;
  }
}

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] * 1;
  let i = 1;
  while (i <= testCases) {
    let int = data[i].split(' ');
    let s = int[0] * 1;
    let d = int[1] * 1;
    console.log(s,d, Math.floor((s+d)/3))
    i += 1;
  }
}

const data = [];

class DoubleIter {
    constructor(iter) {
        this.iter = iter.values();
        this.current = this.iter.next();
        this.iterOfCurrent = this.current.value.values();
    }

    [Symbol.iterator]() {
        return {
            next: () => {
                let { value, done } = this.iterOfCurrent.next();
                if (!done) {
                    return {value, done}
                } else {
                    do {
                        this.current = this.iter.next();
                        if (this.current.done)
                            return { value: undefined, done: true };
                        this.iterOfCurrent = this.current.value.values();
                        ({ value, done } = this.iterOfCurrent.next());
                    } while (done);
                    return {value, done};
                }
            }
        }
    }
}

class Scanner {
    constructor(iterable) {
        this.iter = iterable[Symbol.iterator]();
    }

    getWord() {
        const res = [];
        let {value, done} = this.iter.next();
        while (!done && !this.isLetter(value))
            ({value, done} = this.iter.next());
        if (!done) {
            while (!done && this.isLetter(value)) {
                res.push(value);
                ({value, done} = this.iter.next());
            }
        }
        return String.fromCharCode(...res);
    }

    isLetter(char) {
        return (
            (48 <= char && char <= 57) || // 0-9
            (97 <= char && char <= 122) || // a-z
            (65 <= char && char <= 90) // A-Z
        );
    }
}

process.stdin.on("data", (chunk) => {
    data.push(chunk);
});

process.stdin.on("end", () => {
    start();
});

function start() {
    const scan = new Scanner(new DoubleIter(data));
    const t = +scan.getWord();
    for (let i = 0; i < t; i++) {
        let a = +scan.getWord();
        let b = +scan.getWord();
        //console.log(a, b);
        if (a > b) {
            const t = a;
            a = b;
            b = t;
        }
        const mid = (2*a - b) / 3;
        const x1 = Math.floor(mid);
        let res1 = ~~((x1 + b) / 2);
        const x2 = Math.ceil(mid);
        let res2 = a - x2;
        if (x1 < 0)
            res1 = 0;
        if (x2 < 0)
            res2 = 0;
        const mx = Math.max(res1, res2);

        process.stdout.write(mx.toString() + '\n');
    }
    process.stdout.end()
}

function func(a, b, c) {
    a -= c;
    b -= c;
    return Math.min(c, Math.max(a, b));
}

const data = [];

class DoubleIter {
    constructor(iter) {
        this.iter = iter.values();
        this.current = this.iter.next();
        this.iterOfCurrent = this.current.value.values();
    }

    [Symbol.iterator]() {
        return {
            next: () => {
                let { value, done } = this.iterOfCurrent.next();
                if (!done) {
                    return {value, done}
                } else {
                    do {
                        this.current = this.iter.next();
                        if (this.current.done)
                            return { value: undefined, done: true };
                        this.iterOfCurrent = this.current.value.values();
                        ({ value, done } = this.iterOfCurrent.next());
                    } while (done);
                    return {value, done};
                }
            }
        }
    }
}

class Scanner {
    constructor(iterable) {
        this.iter = iterable[Symbol.iterator]();
    }

    getWord() {
        const res = [];
        let {value, done} = this.iter.next();
        while (!done && !this.isLetter(value))
            ({value, done} = this.iter.next());
        if (!done) {
            while (!done && this.isLetter(value)) {
                res.push(value);
                ({value, done} = this.iter.next());
            }
        }
        return String.fromCharCode(...res);
    }

    isLetter(char) {
        return (
            (48 <= char && char <= 57) || // 0-9
            (97 <= char && char <= 122) || // a-z
            (65 <= char && char <= 90) // A-Z
        );
    }
}

process.stdin.on("data", (chunk) => {
    data.push(chunk);
});

process.stdin.on("end", () => {
    start();
});

function start() {
    const scan = new Scanner(new DoubleIter(data));
    const t = +scan.getWord();
    for (let i = 0; i < t; i++) {
        let a = +scan.getWord();
        let b = +scan.getWord();
        //console.log(a, b);
        if (a > b) {
            const t = a;
            a = b;
            b = t;
        }
        const mid = (2*a - b) / 3;
        const x1 = Math.floor(mid);
        let res1 = ~~((x1 + b) / 2);
        const x2 = Math.ceil(mid);
        let res2 = 2 - x2;
        if (x1 < 0)
            res1 = 0;
        if (x2 < 0)
            res2 = 0;
        const mx = Math.max(res1, res2);

        process.stdout.write(mx.toString() + '\n');
    }
    process.stdout.end()
}

function func(a, b, c) {
    a -= c;
    b -= c;
    return Math.min(c, Math.max(a, b));
}

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");
    let testCases = data[0] * 1;
    let i = 1;
    while (i <= testCases) {
        let line = data[i].split(" ");
        let stick = line[0] * 1;
        let diamonds = line[0] * 1;
         console.log(Math.min(stick,Math.min(diamonds,Math.floor( (stick + diamonds) / 3))));
         i+=1;
    }
}

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");
    let testCases = data[0] * 1;
    let i = 1;
    while (testCases--) {
        let line = data[i].split("\n");
        let stick = line[0] * 1;
        let diamonds = line[0] * 1;
        let polycrap = Math.min(stick, Math.floor(diamonds / 2));

        let stickTemp = polycrap - stick;
        let diamondsTemp = polycrap - Math.floor(diamonds / 2);
        let remains = Math.min(Math.floor(stickTemp / 2), diamondsTemp);
        let polyAnswer = remains + polycrap;

        let swords = Math.min(Math.floor(stick / 2), diamonds);
        diamondsTemp = swords - diamonds;
         stickTemp = swords - Math.floor(stick / 2);
         remains = Math.min(Math.floor(diamondsTemp / 2), stickTemp);
         let swordsAnswer  = remains + polycrap;
         console.log(Math.min(swordsAnswer,polyAnswer));
         i+=1;
    }
}

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");
    let testCases = data[0] * 1;
    let i = 1;
    while (i <= testCases) {
        let line = data[i].split("\n");
        let stick = line[0] * 1;
        let diamonds = line[0] * 1;
         console.log(Math.min(stick,Math.min(diamonds,Math.floor( (stick + diamonds) / 3))));
         i+=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();
    });

    F();
});

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 F(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [n0, n1, n2] = ti(readline().split(' '));
        let s = '';
        if(n2 !== 0){
            for(let i = 0; i <= n2; i++){
                s += '1';
            }
        }

        if(n0 !== 0){
            s += '0';
            for(let i = 0; i < n0; i++)
                s += '0';
        }

        if(n1 !== 0){
            let p = s.length !== 0 ? s[s.length-1] : '';
            if(n2 !== 0 && n0 !== 0)
                n1 -= 1;
            if(n0 === 0 && n2 === 0)
                n1 += 1;

            for(let i = 0; i < n1; i++){
                if(p === '0'){
                    s += '1';
                    p = '1';
                }else{
                    s += '0';
                    p = '0';
                }
            }
        }

        console.log(s);
    }
}

'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 cases = parseInt(readline(), 10);
    for (var X = 0; X < cases; X++) {
      let [n0,n1,n2] = readline().split(" ").map(e => parseInt(e));
      //console.log({n1,n2,n3})

      let zz = [];
      for (var i = 0; i < n0; i++) {
        zz.push('00');
      }

      let ee = [];
      for (var i = 0; i < n2; i++) {
        ee.push('11');
      }

      let mid = [];
      for (var i = 0; i < n1; i++) {
        if (i % 2 == 0) {
          mid.unshift('10');
        } else {
          mid.unshift('01');
        }
      }

      // console.log({
      //   zz,
      //   mid,
      //   ee,
      // })

      let res = [...ee, ...mid, ...zz];
      if (n1 % 2 == 0 && n1 >= 2) {
        mid.splice(1, 0, ...ee)
        res = [...mid, ...zz];
      }

      //console.log(res);

      let output = "";
      for (var k = 0; k < res.length; k++) {
        if (k == 0) {
          output += res[k];
        } else {
          output += res[k][1];
        }
      }

      console.log(output);

      //break;

    }

}

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

    F();
});

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 F(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [n0, n1, n2] = ti(readline().split(' '));
        let s = '';
        if(n2 !== 0){
            for(let i = 0; i <= n2; i++){
                s += '1';
            }
        }

        if(n0 !== 0){
            s += '0';
            for(let i = 0; i < n0; i++)
                s += '0';

            let p = s[s.length-1];
            for(let i = 0; i < n1-1; i++){
                if(p === '0'){
                    s += '1';
                    p = '1';
                }
                else{
                    s += '0';
                    p = '0';
                }
            }
        }else{
            if(n1 !== 0){
                s += '0';
                let p = '0';
                for(let i = 0; i < n1-1; i++){
                    if(p === '0'){
                        s += '1';
                        p = '1';
                    }
                    else{
                        s += '0';
                        p = '0';
                    }
                }
            }
        }

        console.log(s);
    }
}

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

    F();
});

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 F(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [n0, n1, n2] = ti(readline().split(' '));
        let s = '1';
        for(let i = 0; i < n2; i++){
            s += '1';
        }

        if(n0 !== 0){
            s += '0';
            for(let i = 0; i < n0; i++)
                s += '0';

            let p = s[s.length-1];
            for(let i = 0; i < n1-1; i++){
                if(p === '0'){
                    s += '1';
                    p = '1';
                }
                else{
                    s += '0';
                    p = '0';
                }
            }
        }else{
            if(n1 !== 0){
                s += '0';
                let p = '0';
                for(let i = 0; i < n1-1; i++){
                    if(p === '0'){
                        s += '1';
                        p = '1';
                    }
                    else{
                        s += '0';
                        p = '0';
                    }
                }
            }
        }

        console.log(s);
    }
}


var count = Number(readline());
for(var i=0; i<count; i++){
    var args = readline().split(" ");
    var x = Number(args[0]);
    var y = Number(args[1]);
    print(
        ((y==1)||(x>3)||(y<=x)||((x==2)&&(y==3)))
        ? "YES" : "NO");
}

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  const t = parseInt(arr.shift())

  for(let i = 0; i < t; i++) {
    const arrT = arr[i].split(' ').map(a => parseInt(a))
    const x = arrT[0]
    const y = arrT[1]

    if(x >= y) console.log('YES')

    else {
      if(x == 2 && y == 3) console.log('YES')
      else if(x > 3) console.log('YES')
      else console.log('NO')
    }
  }
})

// var num = readline().split(" ").map(x => parseInt(x)); // num will be an array [1,2,3]
// var x = num[0]; // to store values in different variables.
// var y= num[1];
// var z= num[2];

// var num2= readline(); // reads next line.

// print(num2)

// let input = document.querySelector('.input pre').textContent.split('\n')

// const readline = () => input.shift()

// const print = console.log

// begin solution

const solution = (x, y) => 3 < x || y <= x || x === 2 && y === 3

const uglySolution = (x, y) => solution(x, y) ? 'yes' : 'no'

// boilerplate

const inputCount = readline()

for (var i = 0; i < inputCount; i++) {
    print(uglySolution.apply(this, (readline().split(' ').map(Number))))
}

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

// thats all what you have to write to get input from stdin, using readLine.

// Main code runs in main();

function main() {
    const n = +readline();

    for (let i = 0; i < n; i++) {
        let res = false;
        const [x, y] = readline().split(" ").map(t => parseInt(t));
        if (x > 3) res = true;
        else if (x === 1) {
            res = y === 1 ? true : false;
        } else res = y < 4;
        console.log(res ? "YES" : "NO");
    }
}

let fs = require('fs');
let txt = fs.readFileSync(0, 'utf-8').split("\r\n").filter(data=>{return data.length>0});
txt.shift()
txt.forEach((data) => {
    let info = data.split(" ")
    magic(info[0] * 1, info[1] * 1);
})

function magic(a,b){
    while (a!=b){
        if(a>b){
            console.log("YES");
            return;
        }else{
            if(a%2==1){
                if(a!=(a-1)*3/2 && (a-1)*3/2!=0){
                    --a;
                }else{
                    console.log("NO");
                    return;
                }
            }else{
                a=a*3/2;
            }
        }
    }
    console.log("YES");
}

const fs = require('fs');
const stdinBuffer = fs.readFileSync(0);
const inputString = stdinBuffer.toString();

const [count, ...data] = inputString.split('\n');

data.length = Math.min(parseInt(count, 10), data.length);

function find(dataString) {
  const [current, desired] = dataString.split(' ').map(x => { return parseInt(x, 10) });

  if (current === desired) return 'yes';
  if (current === 2 && desired <= 3) return 'yes';
  if (current === 3 && desired < 3) return 'yes';
  if (current >= 4) return 'yes';

  return 'no';
}
process.stdout.write(`${data.map(find).join('\n')}`);

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

// thats all what you have to write to get input from stdin, using readLine.

// Main code runs in main();

function main() {
    const n = +readline();
    let res = false;
    for (let i = 0; i < n; i++) {
        const [x, y] = readline().split(" ").map(t => parseInt(t));
        if (x > 3) res = true;
        else if (x === 1) {
            res = y === 1 ? true : false;
        } else res = y < 4;
    }
    console.log(res ? "YES" : "NO");
}

const fs = require('fs');
const stdinBuffer = fs.readFileSync(0);
const inputString = stdinBuffer.toString();

const [count, ...data] = inputString.split('\n');

data.length = Math.min(parseInt(count, 10), data.length);

function find(dataString) {
  const [current, desired] = dataString.split(' ').map(x => { return parseInt(x, 10) });

  if (current === desired) return 'yes';
  if (current === 2 && desired === 3) return 'yes';
  if (current === 3 && desired < 3) return 'yes';
  if (current >= 4) return 'yes';

  return 'no';
}

process.stdout.write(`${data.map(find).join('\n')}`);

const fs = require('fs');
const stdinBuffer = fs.readFileSync(0);
const inputString = stdinBuffer.toString();

const [count, ...data] = inputString.split('\n');

data.length = parseInt(count, 10);

function find(dataString) {
  const [current, desired] = dataString.split(' ').map(x => { return parseInt(x, 10) });

  if (current === desired) return 'yes';
  if (current === 2 && desired === 3) return 'yes';
  if (current === 3 && desired < 3) return 'yes';
  if (current >= 4) return 'yes';

  return 'no';
}

process.stdout.write(`${data.map(find).join('\n')}`);

const fs = require('fs');
const stdinBuffer = fs.readFileSync(0);
const inputString = stdinBuffer.toString();

const [count, ...data] = inputString.split('\n');

data.length = parseInt(count, 10);

function find(dataString) {
  const [current, desired] = dataString.split(' ').map(x => { return parseInt(x, 10) });

  if (current === desired) return 'yes';

  if (current > desired && current > 1) return 'yes';

  if (desired > current && current % 2 === 0) return 'yes';

  return 'no';
}

process.stdout.write(`${data.map(find).join('\n')}`);

n=readline();
while(n--) {
    var x= readline().split(' ')
    if (x[0]==x[1]) {
        print('YES');
        continue;
    }
    if ((x[0]==2||x[0]==3) && x[1]>3) print('NO');
    else print('YES');
}

// var num = readline().split(" ").map(x => parseInt(x)); // num will be an array [1,2,3]
// var x = num[0]; // to store values in different variables.
// var y= num[1];
// var z= num[2];

// var num2= readline(); // reads next line.

// print(num2)

// let input = document.querySelector('.input pre').textContent.split('\n')

// const readline = () => input.shift()

// const print = console.log

// begin solution

const solution = (x, y) => 3 < x || y <= x || x === 2 && y === 3

const uglySolution = (x, y) => solution(x, y) ? 'yes' : 'no'

// boilerplate

// const inputCount = readline()

// for (let i = 0; i < inputCount; i++) {
//     print(uglySolution.apply(this, (readline().split(' ').map(Number))))
// }

const num = readline().split(" ").map(x => parseInt(x)); // num will be an array [1,2,3]
var x = num[0]; // to store values in different variables.
var y= num[1];
var z= num[2];

var num2= readline(); // reads next line.

print(num2)

// const solution = (x, y) => 3 < x || y <= x || x === 2 && y === 3

// const uglySolution = (x, y) => solution(x, y) ? 'yes' : 'no'

// // boilerplate

// const inputCount = readline()

// for (let i = 0; i < inputCount; i++) {
//     print(solution(...(readline().split(' ').map(Number))))
// }

// var num = readline().split(" ").map(x => parseInt(x)); // num will be an array [1,2,3]
// var x = num[0]; // to store values in different variables.
// var y= num[1];
// var z= num[2];

// var num2= readline(); // reads next line.

// print(num2)

// let input = document.querySelector('.input pre').textContent.split('\n')

// const readline = () => input.shift()

// const print = console.log

// begin solution

const solution = (x, y) => 3 < x || y <= x || x === 2 && y === 3

const uglySolution = (x, y) => solution(x, y) ? 'yes' : 'no'

// boilerplate

const inputCount = readline()

// for (let i = 0; i < inputCount; i++) {
//     print(uglySolution.apply(this, (readline().split(' ').map(Number))))
// }

var num = readline().split(" ").map(x => parseInt(x)); // num will be an array [1,2,3]
var x = num[0]; // to store values in different variables.
var y= num[1];
var z= num[2];

var num2= readline(); // reads next line.

print(num2)

// const solution = (x, y) => 3 < x || y <= x || x === 2 && y === 3

// const uglySolution = (x, y) => solution(x, y) ? 'yes' : 'no'

// // boilerplate

// const inputCount = readline()

// for (let i = 0; i < inputCount; i++) {
//     print(solution(...(readline().split(' ').map(Number))))
// }


var arr = readline().split(" ", 2).map(Number);
var n = arr[0], m = arr[1];

function getSum(x) {
    return (x + 1) * x / 2;
}
var beg = 1, end = 5e4, mid;
while(true) {
    if (getSum(end) <= m) {
        break;
    }
    mid = Math.ceil((beg + end) / 2);
    if (getSum(mid) <= m) {
        beg = mid;
    } else {
        end = mid - 1;
    }
}
var buy = end, money = m - getSum(buy), over = 0;

var array = readline().split(" ", n).map(Number);
array.sort(function(a, b) {return a - b;});
for (var i = 0; i < n; ++i) {
    if (array[i] <= buy) {
        ++over;
        money += array[i];
        if (money >= buy + 1) {
            ++buy;
            money -= buy;
        }
    } else {
        break;
    }
}

function range(array, num) {
    var result = "", beg, end;
    if (num === 0) {
        beg = 1;
    } else {
        beg = array[num - 1] + 1;
    }
    end = array[num];
    for (var i = beg; i < end; ++i) {
        result += i + " ";
    }
    return result;
}
var answer = "";
print(buy - over);
for (var i = 0; i < over; ++i) {
    answer += range(array, i);
}
for (var i = (over === 0 ? 1 : array[over - 1] + 1); i <= buy; ++i) {
    answer += i  + " ";
}
print(answer);

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

var input = readline().split(' ')
  , n = +input[0]
  , m = +input[1]
  , types = readline().split(' ').map( Number ).sort(sortNumber);
  // 4 14
  // 4 6 12 8
// console.log(types);
// console.log(Math.pow(10, 9));
for (var i = 1, sum = 0, curr = types.shift(), result = []; i < Math.pow(10, 9); i++) {
  if ((sum + i) > m) {
      break;
  };
  if (i === curr) {
    curr = types.shift();
    continue;
  } else {
    //console.log(i);
    result.push(i);
    sum += i;
  }
}
print(result.length);
print(result.join(' '));
//console.log(result);
//console.log(i);
//alert('asdas');

var arr = readline().split(" ", 2).map(Number);
var n = arr[0], m = arr[1];

function getSum(x) {
    return (x + 1) * x / 2;
}
var beg = 1, end = 5e4, mid;
while(true) {
    if (getSum(end) <= m) {
        break;
    }
    mid = Math.ceil((beg + end) / 2);
    if (getSum(mid) <= m) {
        beg = mid;
    } else {
        end = mid - 1;
    }
}
var buy = end, money = m - getSum(buy), over = 0;

var array = readline().split(" ", n).map(Number);
array.sort(function(a, b) {return a - b;});
for (var i = 0; i < n; ++i) {
    if (array[i] <= buy) {
        ++over;
        money += array[i];
        if (money >= buy + 1) {
            ++buy;
            money -= buy;
        }
    } else {
        break;
    }
}

function range(array, num) {
    var result = "", beg, end;
    if (num === 0) {
        beg = 1;
    } else {
        beg = array[num - 1] + 1;
    }
    end = array[num];
    for (var i = beg; i < end; ++i) {
        result += i + " ";
    }
    return result;
}
var answer = "";
print(buy - over);
for (var i = 0; i < over; ++i) {
    answer += range(array, i);
}
for (var i = array[over - 1] + 1; i <= buy; ++i) {
    answer += i  + " ";
}
print(answer);


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 avl = new Set(a);
		let used = new Set();

		let rem = [];
		let seq = [];

		for (let x = 1; x <= n; x++) {
			if (avl.has(x)) {
				used.add(x);
			} else {
				seq.push(x);
			}
		}

		for (let i = 0; i < n; i++) {
			if (used.has(a[i])) {
				used.delete(a[i]);
			} else {
				rem.push(a[i]);
			}
		}

		rem.sort((x, y) => x - y);

		let ok = true;
		for (let i = 0; ok && i < rem.length; i++) {
			ok = rem[i] > 2*seq[i];
		}

		console.log(ok ? rem.length : -1);
	}
}

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

		a.sort((x, y) => x - y);

		let ans = n;
		const done = Array(n+1);
		const used = Array(n+1);
		for (let i = 0; i < n; i++) {
			if (a[i] <= n && !done[a[i]]) {
				done[a[i]] = true;
				used[i] = true;
				ans--;
			}
		}

		let ok = true;
		for (let i = 0, x = 1; ok && i < n; i++) {
			while (x <= n && done[x]) x++;
			if (!used[i]) {
				if (a[i] > 2*x) {
					x++;
				} else {
					ok = false;
				}
			}
		}

		console.log(ok ? ans : -1);
	}
}

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

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    let narr = [],
      obj = {};
    for (let i = 0; i < n; i++) {
      if (arr[i] > n) narr.push(arr[i]);
      else if (obj[arr[i]] === undefined) obj[arr[i]] = 1;
      else narr.push(arr[i]);
    }
    narr.sort((a, b) => a - b);
    const helper = (arr) => {
      let ans = 0,
        k = 0;
      for (let i = 0; i < n; i++) {
        if (obj[i + 1] === 1) continue;
        else {
          if (arr[k++] > 2 * (i + 1)) ans++;
          else return -1;
        }
      }
      return ans;
    };
    console.log(helper(narr));
  }
};
solve();

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

		const rem = [];
		const seq = new Set();
		for (let i = 1; i <= n; i++) seq.add(i);

		for (let i = 0; i < n; i++) {
			if (seq.has(a[i]))
				seq.delete(a[i]);
			else
				rem.push(a[i]);
		}

		rem.sort((x, y) => x - y);

		let ok = true, it = seq.values();
		for (let i = 0; ok && i < rem.length; i++) {
			ok = rem[i] > 2*it.next().value;
		}

		console.log(ok ? rem.length : -1);
	}
}

/* Common Template Starts */
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++];
}
/* Common Template Ends */

minOperationToConvertToPermutation = (nums, n)=>{

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

    let set = new Set();
    let j = 1;
    let count = 0;
    for(let i =0; i < n; ++i){
        if(nums[i] <= n){
            if(!set.has(nums[i])){
                set.add(nums[i])
                continue;
            }
        }

        while(set.has(j)){
            j++;
        }
        if(nums[i] % (nums[i]-j) === j){
            set.add(j);
            count++;

        }
        else{
            console.log(-1);
            // console.log(set, nums[i], j)
            return;
        }

    }
    console.log(count);
}
function main() {
    //take input according to the format;
    const t = +(readline());
    for(let i =0; i<t; ++i){
        const n = +(readline());
        const nums = readline().split(' ').map(el=>parseInt(el));
        minOperationToConvertToPermutation(nums, n);
    }
}

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

		a.sort((x, y) => x - y);

		let ans = n;
		const done = Array(n+1);
		const used = Array(n+1);
		for (let i = 0; i < n; i++) {
			if (a[i] <= n && !done[a[i]]) {
				done[a[i]] = true;
				used[i] = true;
				ans--;
			}
		}

		let ok = true;
		for (let i = 0, x = 1; ok && i < n; i++) {
			while (x <= n && !done[x]) x++;
			if (!used[i]) {
				if (a[i] > 2*x) {
					x++;
				} else {
					ok = false;
				}
			}
		}

		console.log(ok ? ans : -1);
	}
}

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

		a.sort((x, y) => x - y);

		let ans = n;
		const b = new Set(a);
		for (let i = 1; i <= n; i++) {
			if (b.has(i)) ans--;
		}

		let ok = true;
		for (let i = 0; ok && i < n; i++) {
			if (a[i] == i+1 || a[i] > 2*(i+1))
				;
			else
				ok = false;
		}

		console.log(ok ? ans : -1);
	}
}

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

		a.sort((x, y) => x - y);

		let ans = 0, ok = true;
		for (let i = 0; ok && i < n; i++) {
			if (a[i] == i+1 || i+1 <= a[i] - Math.ceil((a[i]+1)/2))
				;
			else
				ok = false;
			ans += a[i] != i + 1;
		}

		console.log(ok ? ans : -1);
	}
}

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

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    arr.sort((a, b) => a - b);
    const helper = () => {
      let ans = 0;
      for (let i = 0; i < n; i++) {
        if (arr[i] === i + 1) continue;
        else if (arr[i] > 2 * (i + 1)) ans++;
        else return -1;
      }
      return ans;
    };
    console.log(helper());
  }
};
solve();


var nxy = readline().split(' ').map(item => +item);
var arr = readline().split(' ').map(item => +item);

if(nxy[0] > 1) {
  for(var i = 0; i < nxy[0]; i++) {
    var first = i - nxy[1];
    var last = i + nxy[2] + 1;
    var ans = Math.min(...arr.slice(first > 0 ? first : 0, last));
    if(ans === arr[i]) {
      print(i + 1);
      break;
    }
  }
} else {
  print(1);
}

const processData = () => {
  const [ n, x, y ] = lines[0].split(/\s/).map(Number)
  const a = lines[1].split(/\s/).map(Number)
  const max = Math.pow(10, 10)
  let result = 0

  a.some((ai, i) => {
    const leftMin = Math.min.apply(null, a.slice(i - x > 0 ? i - x : 0, i))
    const rightMin = Math.min.apply(null, a.slice(i + 1, i + 1 + y))

    if(a[i] < leftMin && a[i] < rightMin) {
      result = i
      return true
    }

    return false
  })

  console.log(result + 1)
}

let lines = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', input => lines += input)
process.stdin.on('end', () => {
  const { EOL } = require('os')
  lines = lines.split(EOL)

  processData()
})

const processData = (lines) => {
  const [conditions, data] = lines
  const [n, x, y] = conditions.split(' ').map(x => +x)
  const realData = data.split(' ').map(x => +x)
  const max = Math.pow(10, 10)
  for (let i=0; i<realData.length; i++) {
    const leftMin = realData.slice(i-x > 0 ? i-x: 0, i).reduce((r,x) => r < x ? r : x, max)
    const rightMin = realData.slice(i+1, i+1+y).reduce((r,x) => r < x ? r : x, max)
    if (realData[i] < leftMin && realData[i] < rightMin)
      return void console.log(i+1)
  }
}

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

var numbers = readline().split(" ").map(function (x){return parseInt(x)});
var days = readline().split(" ").map(function (el){return parseInt(el)});
var x = numbers[1];
var y = numbers[2];
var n = numbers[0];
var min = Number.MAX_VALUE;
var streak=0;
function look(k, val){
  for (var j = k+1; j <= k+y ; j++) {
    if (val>days[j]) {
      return false
    }
  }
  return true
}
for (var i = 0; i < days.length; i++) {
  if (days[i]<min){
    min = days[i];
  }
    if  (look(i, days[i])){
        write(i+1)
        break;
    }

}

let lines = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', input => lines += input)
process.stdin.on('end', () => {
  const { EOL } = require('os')
  lines = lines.split(EOL)

  main()
})

function main() {
  const [ n, x, y ] = lines[0].split(/\s/).map(Number)
  const a = lines[1].split(/\s/).map(Number)
  let result = 0

  a.some((ai, i) => {
    const leftMin = Math.min.apply(null, a.slice(i - x > 0 ? i - x : 0, i))
    const rightMin = Math.min.apply(null, a.slice(i + 1, i + y + 1))

    if(ai < leftMin && ai < rightMin) {
      result = i
      return true
    }

    return false
  })

  console.log(result + 1)
}

(function() {
var INPUT = ``;
var OUTPUT = ``;

var main = function() {"use strict";
    // TODO
    var input = rdArN();
    var n = input[0];
    var x = input[1];
    var y = input[2];
    var A = [null].concat(rdArN());

    for (var d = 1; d <= n; ++d) {
        var minL = +Infinity;
        for (var l = d-x; l <= d - 1; ++l) {
            minL = Math.min(minL, A[l] || +Infinity);
        }
        var minR = +Infinity;
        for (var r = d + 1; r <= d + y; ++r) {
            minR = Math.min(minR, A[r] || +Infinity);
        }
        var cur = A[d];
        if (cur < minL && cur < minR) {
            wr(d);
            break;
        }
    }

    /*var SL = new Set();
    var j = x + 1;
    for (var i = 1; i < j; ++i) {
        SL.add(A[i]);
    }
    var SR = new Set();
    for (var i = j + 1; i <= j + y; ++i) {
        SR.add(A[i]);
    }
    //pr(SL.size, SR.size);
    var d = j;
    for (var l1 = 1, l2 = d - 1, r1 = d + 1, r2 = d + y; r2 <= n;
    ++l1, ++l2, ++d, ++r1, ++r2
    ) {
        var minL = SL.values().next().value;
        var minR = SR.values().next().value;
        var cur = A[d];
        if (cur < minL && cur < minR) {
            wr(d);
            break;
        }
        SL.delete(A[l1]);
        SL.add(A[l2+1]);
        SR.delete(A[r1]);
        SR.add(A[r2+1]);
    }*/
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const
rdS=readline,
rdN=()=>+rdS(),
rdArS=()=>rdS().split(' '),
rdArN=()=>rdArS().map(v=>+v),
wr=write,
pr=print,
prAr=(a)=>pr(...a),
prOb=(o)=>pr(JSON.stringify(o,null,4)),
crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},
getPrimes=function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}var primes=[];for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;},
defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{configurable:true,enumerable:false,value:v});
defineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});
defineProperty(Set.prototype,'union',function(s){return new Set([...this,...s]);});
defineProperty(Set.prototype,'intersection',function(s){return new Set([...this].filter((v)=>s.has(v)));});
defineProperty(Set.prototype,'difference',function(s){return new Set([...this].filter((v)=>!s.has(v)));});

main();
return OUTPUT;
})();

const processData = (lines) => {
  const [conditions, data] = lines
  const [n, x, y] = conditions.split(' ')
  const realData = data.split(' ').map(x => +x)
  const max = Math.pow(10, 10)
  for (let i=0; i<realData.length; i++) {
    const leftMin = realData.slice(i-x > 0 ? i-x: 0, i).reduce((r,x) => r < x ? r : x, max)
    const rightMin = realData.slice(i+1, i+y).reduce((r,x) => r < x ? r : x, max)
    if (realData[i] < leftMin && realData[i] < rightMin)
      return void console.log(i+1)
  }
}

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

const processData = (lines) => {
  const [conditions, data] = lines
  const [n, x, y] = conditions.split(' ').map(x => +x)
  const realData = data.split(' ').map(x => +x)
  const max = Math.pow(10, 10)
  for (let i=0; i<realData.length; i++) {
    const leftMin = realData.slice(i-x > 0 ? i-x: 0, i).reduce((r,x) => r < x ? r : x, max)
    const rightMin = realData.slice(i+1, i+y).reduce((r,x) => r < x ? r : x, max)
    if (realData[i] < leftMin && realData[i] < rightMin)
      return void console.log(i+1)
  }
}

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

let line = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', function (input) {
  line += (input.trim() + '\n')
})

process.stdin.on('end', function () {
  main(line)
})

function checkMin(arr, ai, start, end, i) {
  start < 0 ? start = 0 : void 0
  end > arr.length - 1 ? end = arr.length - 1 : void 0

  const leftMin = Math.min.apply(null, arr.slice(start, i))
  const rightMin = Math.min.apply(null, arr.slice(i + 1, end + 1))

  return ai < leftMin && ai < rightMin
}

function main(line) {
  line = line.split(/\n/).map(l => l.replace(/\r/, ''))

  const [ n, x, y ] = line[0].split(/\s/).map(Number)
  const a = line[1].split(/\s/).map(Number)
  let result = 0

  a.some((ai, i) => {
    if(checkMin(a, ai, i - x, i + y, i)) {
      result = i
      return true
    }

    return false
  })

  console.log(result + 1)
}

// ad < aj should hold for all d−x ≤ j < d and d < j ≤ d+y

let line = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', function (input) {
  line += (input.trim() + '\n')
})

process.stdin.on('end', function () {
  main(line)

  process.exit(0)
})

function findMinIndex(arr, start, end) {
  let min = arr[0]
  let minIdx = null

  arr.forEach((v, i) => {
    if(i >= start && i < end) {
      if(v < min) {
        min = v
        minIdx = i
      }
    }
  })

  return { min, idx: minIdx }
}

function main(line) {
  line = line.split(/\n/).map(l => l.replace(/\r/, ''))

  const [ n, x, y ] = line[0].split(/\s/).map(Number)
  const a = line[1].split(/\s/).map(Number)
  let result = 0

  a.some((ai, i) => {
    const { min, idx } = findMinIndex(a, i - x, i + y + 1)

    if(min === ai && i === idx) {
      result = idx
      return true
    }

    return false
  })

  console.log(result + 1)
}

let line = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', function (input) {
  line += (input.trim() + '\n')
})

process.stdin.on('end', function () {
  main()
})

function main() {
  line = line.split(/\n/).map(l => l.replace(/\r/, ''))

  const [ n, x, y ] = line[0].split(/\s/).map(Number)
  const a = line[1].split(/\s/).map(Number)
  let result = 0

  a.some((ai, i) => {
    const start = i - x > 0 ? i - x : (0, i)
    const end = i + y
    const leftMin = Math.min.apply(null, a.slice(start, i))
    const rightMin = Math.min.apply(null, a.slice(i + 1, end + 1))

    if(ai < leftMin && ai < rightMin) {
      result = i
      return true
    }

    return false
  })

  console.log(result + 1)
}

let lines = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', input => lines += input)
process.stdin.on('end', () => {
  lines = lines.split(/\n/)

  main()
})

function main() {
  const [ n, x, y ] = lines[0].split(/\s/).map(Number)
  const a = lines[1].split(/\s/).map(Number)
  let result = 0

  a.some((ai, i) => {
    const leftMin = Math.min.apply(null, a.slice(i - x > 0 ? i - x : 0, i))
    const rightMin = Math.min.apply(null, a.slice(i + 1, i + y + 1))

    if(ai < leftMin && ai < rightMin) {
      result = i
      return true
    }

    return false
  })

  console.log(result + 1)
}

let line = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', function (input) {
  line += (input.trim() + '\n')
})

process.stdin.on('end', function () {
  main()
})

function main() {
  line = line.split(/\n/).map(l => l.replace(/\r/, ''))

  const [ n, x, y ] = line[0].split(/\s/).map(Number)
  const a = line[1].split(/\s/).map(Number)
  let result = 0

  a.some((ai, i) => {
    const start = i - x < 0 ? 0 : i - x
    const end = i + y > n - 1 ? n - 1 : i + y
    const leftMin = Math.min.apply(null, a.slice(start, i))
    const rightMin = Math.min.apply(null, a.slice(i + 1, end + 1))

    if(ai < leftMin && ai < rightMin) {
      result = i
      return true
    }

    return false
  })

  console.log(result + 1)
}

let line = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', function (input) {
  line += (input.trim() + '\n')
})

process.stdin.on('end', function () {
  main(line)

  process.exit(0)
})

function findMinIndex(arr, start, end) {
  let min = arr[0]
  let minIdx = null

  arr.forEach((v, i) => {
    if(i >= start && i < end) {
      if(v < min) {
        min = v
        minIdx = i
      }
    }
  })

  return { min, idx: minIdx }
}

function main(line) {
  line = line.split(/\n/).map(l => l.replace(/\r/, ''))

  const [ n, x, y ] = line[0].split(/\s/).map(Number)
  const a = line[1].split(/\s/).map(Number)
  let result

  a.some((ai, i) => {
    const { min, idx } = findMinIndex(a, i - x, i + y + 1)

    if(min === ai && i === idx) {
      result = idx
      return true
    }

    return false
  })

  console.log(result + 1)
}

let line = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', function (input) {
  line += (input.trim() + '\n')
})

process.stdin.on('end', function () {
  main(line)
})

function checkMin(arr, ai, start, end, i) {
  start < 0 ? start = 0 : void 0
  end > arr.length - 1 ? end = arr.length - 1 : void 0

  const leftMin = Math.min.apply(null, arr.slice(start, i + 1))
  const rightMin = Math.min.apply(null, arr.slice(i, end + 1))

  return ai <= leftMin && ai <= rightMin
}

function main(line) {
  line = line.split(/\n/).map(l => l.replace(/\r/, ''))

  const [ n, x, y ] = line[0].split(/\s/).map(Number)
  const a = line[1].split(/\s/).map(Number)
  let result = 0

  a.some((ai, i) => {
    if(checkMin(a, ai, i - x, i + y, i)) {
      result = i
      return true
    }

    return false
  })

  console.log(result + 1)
}

let line = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', function (input) {
  line += (input.trim() + '\n')
})

process.stdin.on('end', function () {
  main()
})

function main() {
  line = line.split(/\n/).map(l => l.replace(/\r/, ''))

  const [ n, x, y ] = line[0].split(/\s/).map(Number)
  const a = line[1].split(/\s/).map(Number)
  let result = 0

  a.some((ai, i) => {
    const start = i - x < 0 ? i : i - x
    const end = i + y
    const leftMin = Math.min.apply(null, a.slice(start, i))
    const rightMin = Math.min.apply(null, a.slice(i + 1, end + 1))

    if(ai < leftMin && ai < rightMin) {
      result = i
      return true
    }

    return false
  })

  console.log(result + 1)
}

let line = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', function (input) {
  line += (input.trim() + '\n')
})

process.stdin.on('end', function () {
  main(line)
})

function findMinIndex(arr, start, end, i) {
  start < 0 ? start = 0 : void 0

  let idx = start
  let min = arr[idx]

  arr.slice(start, end).forEach((v, i) => {
    if(v < min) {
      min = v
      idx = start + i
    }
  })

  return { min, idx }
}

function main(line) {
  line = line.split(/\n/).map(l => l.replace(/\r/, ''))

  const [ n, x, y ] = line[0].split(/\s/).map(Number)
  const a = line[1].split(/\s/).map(Number)
  let result = 0

  a.some((ai, i) => {
    const { min, idx } = findMinIndex(a, i - x, i + y + 1, i)

    if(min === ai && i === idx) {
      result = idx
      return true
    }

    return false
  })

  console.log(result + 1)
}

let line = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', function (input) {
  line += (input.trim() + '\n')
})

process.stdin.on('end', function () {
  main(line)
})

function findMin(arr, start, end) {
  start < 0 ? start = 0 : void 0

  let idx = start
  let min = Number(arr[idx])

  for(let i = start; i <= end; i++) {
    const v = Number(arr[i])

    if(v < min) {
      min = v
      idx = i
    }
  }

  return { min, idx }
}

function main(line) {
  line = line.split(/\n/).map(l => l.replace(/\r/, ''))

  const [ n, x, y ] = line[0].split(/\s/).map(Number)
  const a = line[1].split(/\s/)
  let result = 0

  a.some((ai, i) => {
    const { min, idx } = findMin(a, i - x, i + y)

    if(min === Number(ai) && i === idx) {
      result = idx
      return true
    }

    return false
  })

  console.log(result + 1)
}

var nxy = readline().split(' ').map(item => +item);
var arr = readline().split(' ').map(item => +item);

if(nxy[0] > 1) {
  var pr = true;

  if(arr[0] < arr[1]) {
    var ans = Math.min(...arr.slice(0, nxy[2]));
    if(ans === arr[0]) {
      print(1);
      pr = false;
    }
  }

  if (pr) {
    for(var i = 1; i < arr.length - 1; i++) {
      var start = i - nxy[1];
      var end = i + nxy[2] + 1;
      var ans = Math.min(...arr.slice(start < 0 ? start : 0, end));
      if(ans === arr[i]) {
        print(i + 1);
        pr = false;
        break;
      }
    }
  }

  if(pr) {
    print(arr.length);
  }
} else {
  print(1);
}


test = readline();

while (test--) {

    ans = [];
    taken = {};
    tmp = [];

    sizeOfDeck = readline();
    orginalDeck = readline().split(' ').map(x => parseInt(x));

    for (var i = sizeOfDeck - 1; i >= 0; i--) {
        if (orginalDeck[i] == sizeOfDeck) {
            sizeOfDeck--;

            ans.push(orginalDeck[i]);

            for (var j = tmp.length - 1; j >= 0; j--) {
                ans.push(tmp[j]);
                taken[tmp[j]] = true;
            }
            tmp = [];
            for(var j = sizeOfDeck; j > 0;j--) {

                if(!taken.hasOwnProperty(j)) {
                    break;
                }
                sizeOfDeck--;
            }
            continue;
        }
        tmp.push(orginalDeck[i]);

    }
    print(...ans);
}

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

    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, iii) => {
        var n = parseInt(readline())
        // var [n, k] = readline().split(' ').map((x, iii) => {
        //     return parseInt(x)
        // })
        // var a = new Array(n + 1).fill(0)

        var a = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })
        var pos = new Array(n)
        for (let i = 0; i < a.length; i++) {
            pos[a[i]] = i
        }
        var right = n
        var answer = []
        for (let i = n; i >= 0; i--) {
            // console.log(i,pos[i], right)
            if (pos[i] > right) continue
            for (let j = pos[i]; j < right; j++) {
                answer.push(a[j])
            }
            right = pos[i]
        }

        console.log(answer.join(' '))
    })
}

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

    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, iii) => {
        var n = parseInt(readline())
        // var [n, k] = readline().split(' ').map((x, iii) => {
        //     return parseInt(x)
        // })
        // var a = new Array(n + 1).fill(0)

        var a = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })

        var locMax = new Array(n).fill(0)
        locMax[0] = a[0]
        for (var i = 1; i < n; i++) {
            locMax[i] = Math.max(locMax[i - 1], a[i])
            // locMax[i] = Math.min(locMax[i], a[i])
        }
        var index = new Array(n).fill(0)
        var ii = 0

        for (var i = 0; i < n; i++) {
            if (locMax[i] === a[i]) {
                index[a[i]] = i
                ii = i
            } else {
                index[a[i]] = ii
            }
        }
        // console.log(locMax)
        // console.log(index)

        var array = []
        var currect = []
        var last = n - 1
        var i = n - 1
        while (i >= 0) {

            var ii = index[a[i]]
            i = ii - 1

            var max = locMax[ii]
            while (locMax[ii] === max && ii < n) {
                array.push(a[ii])
                ii++
            }
        }

        console.log(array.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));
    if (n === 1) {
      console.log(1);
      continue;
    }
    let narr = [];
    narr.push({ val: arr[0], ind: 0 });
    for (let i = 1; i < n; i++) {
      let k = { val: narr[i - 1].val, ind: narr[i - 1].ind };
      narr.push(k);
      if (narr[i].val < arr[i]) narr[i].val = arr[i];
      narr[i].ind = i;
    }
    narr.sort((a, b) => b.val - a.val);
    let res = "";
    for (let i = 0; i < n; i++) res += arr[narr[i].ind] + " ";
    console.log(res);
  }
};
solve();

var print = this.print || require('lol-io').print
var write = this.write || require('lol-io').write
var readline = this.readline || require('lol-io').readline

var t=parseInt(readline())
var a=new Array(100005).fill(0);
var mx=new Array(100005).fill(0);
	while(t--){
        var n=parseInt(readline());
        var arr=readline().split(" ").map(t=>parseInt(t));
       // console.log(arr);
		for(var i=1;i<=n;i++) a[i]=arr[i-1],mx[i]=Math.max(mx[i-1],a[i]);
        var r=n;
        var re=[];
		for(var i=n;i>=1;i--){
			if(mx[i]==a[i]){
				for(var j=i;j<=r;j++)re.push(a[j]);
				r=i-1;
			}
        }
        print(re.join(" "))
    }

const processData = (lines) => {
    let n = +lines[0]
    let cur = 0
    while(n--) {
        cur++
        const c = +lines[cur]
        cur++
        const arr = lines[cur].split(' ').map(x => +x)
        const valueMap = {}
        for (const t of arr) {
            valueMap[t] = false
        }
        const final = []
        let target = c
        while (final.length < arr.length) {
            let b = arr.length - final.length
            let maxIndex = -1
            let maxValue = -1
            if (target !== -1) {
                while (b--) {
                    if (arr[b] === target) {
                        maxValue = target
                        maxIndex = b
                        target = -1
                        break
                    }
                }
            } else {
                while (b--) {
                    if (arr[b] > maxValue) {
                        maxValue = arr[b]
                        maxIndex = b
                    }
                }
            }
            let start = maxIndex
            const end = arr.length - final.length
            let possibleTarget = maxValue - 1
            while (start < end) {
                final.push(arr[start])
                valueMap[arr[start]] = true
                start++
            }
            while(valueMap[possibleTarget] === true) {
                possibleTarget--
            }
            target = possibleTarget
            // console.log('final', final)
        }
        console.log(final.join(' '))
    }
}

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

const processData = (lines) => {
    let n = +lines[0]
    let cur = 0
    while(n--) {
        cur++
        const c = +lines[cur]
        cur++
        const arr = lines[cur].split(' ').map(x => +x)
        const final = []
        let target = c
        while (final.length < arr.length) {
            let b = arr.length - final.length
            let maxIndex = -1
            let maxValue = -1
            if (target !== -1) {
                while (b--) {
                    if (arr[b] === target) {
                        maxValue = target
                        maxIndex = b
                        target = -1
                        break
                    }
                }
            } else {
                while (b--) {
                    if (arr[b] > maxValue) {
                        maxValue = arr[b]
                        maxIndex = b
                    }
                }
            }
            let start = maxIndex
            const end = arr.length - final.length
            let possibleTarget = maxValue - 1
            let foundPossibleTarget = false
            while (start < end) {
                final.push(arr[start])
                if (!foundPossibleTarget && arr[start] === possibleTarget) {
                    foundPossibleTarget = true
                }
                start++
            }
            if (!foundPossibleTarget) {
                target = possibleTarget
            }
            // console.log('final', final)
        }
        console.log(final.join(' '))
    }
}

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

const processData = (lines) => {
    let n = +lines[0]
    let cur = 0
    while(n--) {
        cur++
        const c = +lines[cur]
        cur++
        const arr = lines[cur].split(' ').map(x => +x)
        let t = 0
        while (t < arr.length) {
            let b = arr.length - t
            let maxIndex = -1
            let maxValue = -1
            const possibleMax = b
            while (b--) {
                if (arr[b] > maxValue) {
                    maxValue = arr[b]
                    maxIndex = b
                    if (maxValue === possibleMax) {
                        break
                    }
                }
            }
            let start = maxIndex
            const end = arr.length - t
            t += end - start
            while (start < end) {
                process.stdout.write(arr[start] + ' ')
                start++
            }
        }
        process.stdout.write('\n')
    }
}

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

const findMax = (arr, n) => {
    return arr.reduce((res, num, index) => {
        // console.log('num', num)
        if (num > res.value) {
            return {index, value: num}
        }
        return res
    }, {index: -1, value: 0n})
}

const processData = (lines) => {
    let n = +lines[0]
    let cur = 0
    while(n--) {
        cur++
        const c = +lines[cur]
        cur++
        const arr = lines[cur].split(' ').map(x => +x)
        const final = []
        while (final.length < arr.length) {
            let b = arr.length - final.length
            const t = b
            let maxIndex = -1
            while (b--) {
                if (arr[b] === t) {
                    maxIndex = b
                }
            }
            let start = maxIndex
            const end = arr.length - final.length
            while (start < end) {
                final.push(arr[start])
                start++
            }
            // console.log('final', final)
        }
        console.log(final.map(x => x.toString(10)).join(' '))
    }
}

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