'use strict';

function solve(n, m, a, b) {
  let ma = Math.max(...a),
      mb = Math.max(...b);
  if (ma > mb) {
    return 'Alice\nAlice';
  } else if (ma < mb) {
    return 'Bob\nBob';
  } else {
    return 'Alice\nBob';
  }
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    while (t--) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      const m = Number(await read());
      const b = (await read()).split(' ').map(Number);
      res.push(solve(n, m, a, b));
    }
    console.log(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', () => {
  inputs = str.split('\n').values();
  main(read);
});

'use-strict'

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

let data = '';
let currentLine = 0;

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

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

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

while(testCases--) {

const m = parseInt(readLine());
const al = get_ints();
const n = parseInt(readLine());
const b = get_ints();

const res = a(m,al,n,b);
console.log(res)
}
});

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

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

function a(m,a,n,b){
    let ans = '';
    const amax = Math.max(...a);
    const bmax = Math.max(...b);
    bmax > amax ? ans+='Bob\n' : ans+='Alice\n';
    amax > bmax ? ans+='Alice' : ans+='Bob';

    return ans
}

module.exports = a;

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

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

/*---------------------------------------------------*/

function div(val, by){
    return (val - val % by) / by;
}

const calc = (t)=>{
    /* read */
    let n = +readline();
    let a = ra();
    let m = +readline();
    let b = ra();

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

    let al = a[n - 1];
    let bb = b[m - 1];

    let result = '';

    if (al >= bb) result += 'Alice\n';
    else result += 'Bob\n';

    if (bb >= al) result += 'Bob';
    else result += 'Alice';

    return result;
};

function main() {
    let T = +readline();
    let out = [];
    for (let t = 1; t <= T; t++){
        out.push(calc(t));
        // process.stdout.write(`${calc(n, a)}\n`);
    }
    process.stdout.write(out.join('\n')+'\n');
}

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

var arr = "";

process.stdin.on("data", function (chunk) {
  arr += chunk;
});

process.stdin.on("end", function () {
  arr = arr.split("\n");
  const n = parseInt(arr.shift()); // no of test cases

  for (let i = 0; i < 4 * n; ) {
    const qtyAlice = arr[i++];
    const cardsAlice = arr[i++].split(" ").map((el) => parseInt(el));
    const maxAlice = Math.max(...cardsAlice);

    const qtyBob = arr[i++];
    const cardsBob = arr[i++].split(" ").map((el) => parseInt(el));
    const maxBob = Math.max(...cardsBob);

    // Alice turn
    if (maxAlice >= maxBob) {
      console.log("Alice");
    } else {
      console.log("Bob");
    }

    // Bob turn
    if (maxBob >= maxAlice) {
      console.log("Bob");
    } else {
      console.log("Alice");
    }
  }
});

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

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

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

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

        let aMax = Math.max(...arr);
        let bMax = Math.max(...brr);

        if (aMax > bMax) {
            output('Alice');
        } else if (aMax < bMax) {
            output('Bob');
        } else {
            output('Alice');
        }

        if (aMax > bMax) {
            output('Alice');
        } else if (aMax < bMax) {
            output('Bob');
        } else {
            output('Bob');
        }
    }
}

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++) {
        l++
        const sa = lines[l++].trim().split(' ').map(Number)
        l++
        const sb = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(sa, sb)
    }
    console.log(output.join('\n'))
// })()
})

function solve(sa, sb) {
    const a = Math.max(...sa)
    const b = Math.max(...sb)
    if (a > b) {
        return 'Alice\nAlice'
    } else if (a < b) {
        return 'Bob\nBob'
    } else {
        return 'Alice\nBob'
    }
}

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

let input = [];
rl.on("line", function (line) {
  input.push(line);
}).on("close", function () {
  solution(input);
  process.exit();
});

function solution(_input) {
  const input = _input[Symbol.iterator]();
  const T = Number(input.next().value);

  for (let t = 0; t < T; t++) {
    input.next();
    const A = input.next().value.split(" ").map(Number);
    input.next();
    const B = input.next().value.split(" ").map(Number);
    const maxA = Math.max(...A);
    const maxB = Math.max(...B);
    const names = ["Alice", "Bob"];
    const results = [];
    for (let i = 0; i < 2; i++) {
      if (maxA === maxB) {
        results.push(names[i]);
      } else {
        results.push(names[Number(maxA < maxB)]);
      }
    }
    console.log(results.join("\n"));
  }
}

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

function Main(){
    // test case in nodeJs
	var t = nextInt();
	while(hasNext()){
		solve();
	}
}

function solve() {
	const aliceCardNum = nextInt();
    const aliceCards = nextIntArray(aliceCardNum);
    const bobCardNum = nextInt();
    const bobCards = nextIntArray(bobCardNum);

    const maxAliceCard = Math.max(...aliceCards);
    const maxBobCard = Math.max(...bobCards);

    // Alice goes first
    if (maxAliceCard >= maxBobCard) {
        myout("Alice")
    } else {
        myout("Bob")
    }

    // Bob goes first
    if (maxBobCard >= maxAliceCard) {
        myout("Bob")
    } else {
        myout("Alice")
    }
}

process.stdin.resume();
process.stdin.setEncoding("utf-8");
//
let standardInputString = "";
let currentLine = 0;
//
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readline() {
  return standardInputString[currentLine++];
}
function print(data) {
  console.log(data);
}

//line to array of integers
//readline().split(' ').map(Number)
//  let iter=parseInt(readline())
function main() {
  let iter = parseInt(readline());
  for (let i = 0; i < iter; i++) {
    let n = readline();
    let a = readline().split(" ").map(Number);
    let m = readline();
    let b = readline().split(" ").map(Number);
    FindWinner(a, b);
  }
}

function FindWinner(a, b) {
  let maxA = Math.max(...a);
  let maxB = Math.max(...b);
  if (maxA == maxB) {
    print("Alice");
    print("Bob");
  } else if (maxA > maxB) {
    print("Alice");
    print("Alice");
  } else {
    print("Bob");
    print("Bob");
  }
}

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

const solve = (aCards, bCards) => {
  // console.log("alice", aCards);

  // console.log("bob", bCards);
  const maxAlice = Math.max(...aCards);
  const maxBob = Math.max(...bCards);
  if (maxAlice >= maxBob) {
    console.log("Alice");
  } else {
    console.log("Bob");
  }
  if (maxBob >= maxAlice) {
    console.log("Bob");
  } else {
    console.log("Alice");
  }
};
let T = -1;
let aliceCards;
let bobCards;

rl.on("line", function (line) {
  if (T !== -1) {
    switch (T % 4) {
      case 1:
        aliceCards = line.split(" ").map(Number);
        break;
      case 3:
        bobCards = line.split(" ").map(Number);
        if (aliceCards !== undefined && bobCards !== undefined)
          solve(aliceCards, bobCards);
        break;
      default:
        break;
    }
  }
  T++;
});

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
var T = readline();
for(var qe=1;qe<=T;qe++) {
  var an = readline();
  var a = readline().split(' ').map((x) => parseInt(x));
  var bn = readline();
  var b = readline().split(' ').map((x) => parseInt(x));
  a.sort(function(x,y) { return x-y })
  b.sort(function(x,y) { return x-y })
  if(b[bn-1] > a[an-1]) {
    console.log('Bob');
    console.log('Bob');
  } else if(a[an-1] > b[bn-1]) {
    console.log('Alice');
    console.log('Alice');
  } else {
    console.log('Alice');
    console.log('Bob');
  }

  //console.log(ans);
  //fs.appendFileSync('output.txt', ans+'\r\n');

}
//

'use strict';
// HEADER:
const print = function(arg){
  let str = arg;
  if (arguments.length>1)
    str = Array.prototype.slice.call(arguments).join(' ');
  process.stdout.write(str+'\n');
};
let IS_MULTITEST, testN, tests;
const pcalc = (testN, toPrint)=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    toPrint.push(res.join(' '));
  } else if (Number.isFinite(res) || typeof res=='string'){
    toPrint.push(res+'');
  }
  if (process.env.DEBUG && toPrint.length){
    let ans = toPrint.pop();
    print(ans);
    let expected = tests[testN-1];
    if (expected){
      if (expected==ans)
        console.log('\x1b[32m%s\x1b[0m', 'correct');
      else {
        console.log('\x1b[31m%s\x1b[0m', 'wrong, expected:', expected);
      }
    }
  }
};

const main = ()=>{
  let toPrint = [];
  L('\nSolving:');
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(testN, toPrint);
  } else {
    pcalc(1, toPrint);
  }
  if (toPrint.length){
    print(toPrint.join('\n'));
  }
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`\nTest #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

tests = [
``, // Test #1
``, // Test #2
``, // Test #3
``, // Test #4
``, // Test #5
];

// SOLUTION:
IS_MULTITEST = true;

const calc = (testN)=>{
  // READING:
  let [n] = ra();
  let A = ra();
  let [m] = ra();
  let B = ra();
  LT({n, A, m, B});
  // PROCESSING:
  let ans = 0;
  let maxA = Math.max.apply(null, A)
  let maxB = Math.max.apply(null, B)
  if (maxA==maxB){
    return 'Alice\nBob'
  }
  return maxA>maxB ? 'Alice\nAlice' : 'Bob\nBob'
};

var num = parseInt(readline(), 10);

for(var i = 0; i < num; i++) {
    var maxA = 0;
    var maxB = 0;

    var cardNumA = parseInt(readline(), 10);
    var cardsA = readline().split(" ");

    var cardNumB = parseInt(readline(), 10);
    var cardsB = readline().split(" ");

    for(var k = 0; k < cardNumA; k++) {
        var elem1 = parseInt(cardsA[k], 10);
        if(elem1 > maxA) {
            maxA = elem1;
        }
    }

    for(var k = 0; k < cardNumB; k++) {
        var elem2 = parseInt(cardsB[k], 10);
        if(elem2 > maxB) {
            maxB = elem2;
        }
    }

    if(maxA === maxB) {
        print("Alice");
        print("Bob");
    }else if(maxA > maxB) {
        print("Alice");
        print("Alice");
    }else {
        print("Bob");
        print("Bob");
    }
}

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

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

/*---------------------------------------------------*/

function div(val, by){
    return (val - val % by) / by;
}

const calc = (t)=>{
    /* read */
    let n = +readline();
    let a = ra();
    let m = +readline();
    let b = ra();

    let al = a[n - 1];
    let bb = b[m - 1];

    let result = '';

    if (al >= bb) result += 'Alice\n';
    else result += 'Bob\n';

    if (bb >= al) result += 'Bob';
    else result += 'Alice';

    return result;
};

function main() {
    let T = +readline();
    let out = [];
    for (let t = 1; t <= T; t++){
        out.push(calc(t));
        // process.stdout.write(`${calc(n, a)}\n`);
    }
    process.stdout.write(out.join('\n')+'\n');
}

var num = parseInt(readline(), 10);

for(var i = 0; i < num; i++) {
    var maxA = 0;
    var maxB = 0;

    var cardNumA = parseInt(readline(), 10);
    var cardsA = readline().split(" ");

    var cardNumB = parseInt(readline(), 10);
    var cardsB = readline().split(" ");

    for(var k = 0; k < cardNumA; k++) {
        var num = parseInt(cardsA[k], 10);
        if(num > maxA) {
            maxA = num;
        }
    }

    for(var k = 0; k < cardNumB; k++) {
        var num = parseInt(cardsB[k], 10);
        if(num > maxB) {
            maxB = num;
        }
    }

    if(maxA > maxB) {
        print("Alice");
        print('Alice');
    }else if(maxA < maxB) {
        print("Bob");
        print("Bob");
    }else {
        print("Alice");
        print("Bob");
    }
}

var num = parseInt(readline(), 10);

for(var i = 0; i < num; i++) {
    var maxA = 0;
    var maxB = 0;

    var cardNumA = parseInt(readline(), 10);
    var cardsA = readline().split(" ");

    var cardNumB = parseInt(readline(), 10);
    var cardsB = readline().split(" ");

    for(var k = 0; k < cardNumA; k++) {
        if(cardsA[k] > maxA) {
            maxA = cardsA[k];
        }
    }

    for(var k = 0; k < cardNumB; k++) {
        if(cardsB[k] > maxB) {
            maxB = cardsB[k];
        }
    }

    if(maxA > maxB) {
        print("Alice");
        print('Alice');
    }else if(maxA < maxB) {
        print("Bob");
        print("Bob");
    }else {
        print("Alice");
        print("Bob");
    }

}


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 sa = lines[l++].trim().split(' ').map(Number)
        const sb = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, sa, sb)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, sa, sb) {
    const m = {}
    const ma = sa.reduce((o, x) => {
        o[x] = (o[x] || 0) + 1
        m[x] = 1
        return o
    }, {})
    const mb = sb.reduce((o, x) => {
        o[x] = (o[x] || 0) + 1
        m[x] = 1
        return o
    }, {})
    //
    const ca = Array(10).fill(0)
    const cb = Array(10).fill(0)
    let r = 0
    for (let x in m) {
        const na = ma[x] || 0
        const nb = mb[x] || 0
        let add = 0
        if (x > 9) {
            add = 1
            x = String(x).length
        }
        if (na > nb) {
            ca[x] += na - nb
            r += add * (na - nb)
        } else {
            cb[x] += nb - na
            r += add * (nb - na)
        }
    }
    //
    // console.log(ca, cb)
    for (let i = 2; i <= 9; i++) {
        r += Math.abs(ca[i] - cb[i])
    }
    return r
}

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

function digiLog(x) {
    return x.toString().length;
}

function heapInsert(heap, value) {
    heap.push(value);

    let index = heap.length - 1;
    let parentIndex = Math.floor((index - 1) / 2);

    // Sift up
    while (index > 0) {
        if (value <= heap[parentIndex]) {
            break;
        }

        heap[index] = heap[parentIndex];
        heap[parentIndex] = value;

        index = parentIndex;
        parentIndex = Math.floor((index - 1) / 2);
    }
}

function heapify(a) {
    const heap = [];
    for (const value of a) {
        heapInsert(heap, value);
    }

    return heap;
}

function heapExtract(heap) {
    if (heap.length === 0) {
        return undefined;
    }

    if (heap.length === 1) {
        return heap.pop();
    }

    const top = heap[0];
    const value = heap.pop();
    let index = 0;
    heap[index] = value;

    while (index < heap.length) {
        const left = (index * 2) + 1;
        const right = left + 1;

        let nextIndex = -1;

        // If both
        if (heap[left] !== undefined && heap[right] !== undefined) {
            // ...pick max
            if (heap[left] > heap[right]) {
                nextIndex = left;
            } else {
                nextIndex = right;
            }
        } else if (heap[left] !== undefined) {
            nextIndex = left;
        } else if (heap[right] !== undefined) {
            nextIndex = right;
        } else {
            break;
        }

        if (heap[nextIndex] <= value) {
            break;
        }

        heap[index] = heap[nextIndex];
        heap[nextIndex] = value;

        index = nextIndex;
    }

    return top;
}

function solve(sourceA, sourceB) {
    let a = heapify(sourceA);
    let b = heapify(sourceB);

    let steps = 0;
    while (a.length > 0) {
        // console.log(a, '|', b);
        const lastA = a[0];
        const lastB = b[0];
        if (lastA === lastB) {
            heapExtract(a);
            heapExtract(b);
        } else if (lastA > lastB) {
            const nextValue = digiLog(heapExtract(a));
            heapInsert(a, nextValue);
            steps++;
        } else {
            const nextValue = digiLog(heapExtract(b));
            heapInsert(b, nextValue);
            steps++;
        }
    }

    console.log(steps);
}

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n');
    for (let i = 1; i < data.length; i += 3) {
        const a = data[i + 1].trim().split(" ").map(Number);
        const b = data[i + 2].trim().split(" ").map(Number);

        solve(a, b);
    }
});

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

//

function main() {
    let t = parseInt(readLine())
    while (t--) {
        const n = parseInt(readLine())
        let a = readLine().split(" ").map((s) => parseInt(s)).sort(
            (x, y) => x - y
        )
        let b = readLine().split(" ").map((s) => parseInt(s)).sort(
            (x, y) => x - y
        )
        // console.log(a, b)
        let na = [], nb = []
        let i = 0, j = 0
        for (; i < n; i ++) {
            while (a[i] > b[j]) {
                nb.push(b[j])
                j ++
            }
            if (a[i] === b[j]) {
                j ++
                continue
            }
            na.push(a[i])
        }
        for (; j < n; j ++) nb.push(b[j])
        // console.log(na, nb)
        let cnt = {}
        for (i = 1; i < 10; i ++) {
            cnt[i] = 0
        }
        let ans = 0
        for (i = 0; i < na.length; i ++) {
            let x = na[i]
            if (x > 9) {
                cnt[dl(x)] ++
                ans ++
            } else {
                cnt[x] ++
            }
        }
        // console.log(cnt)
        for (i = 0; i < na.length; i ++) {
            let x = nb[i]
            if (x > 9) {
                cnt[dl(x)] --
                ans ++
            } else {
                cnt[x] --
            }
        }
        // console.log(cnt)
        for (i = 2; i <= 9; i ++) {
            ans += Math.abs(cnt[i])
        }
        console.log(ans)
    }
}

function dl(x) {
    return Math.floor(Math.log10(x)) + 1
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

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

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

    for (let test = 0; test < N; test++) {
        let n = parseInt(readline(), 10);
        let arr = readline().split(' ').map(Number);
        let brr = readline().split(' ').map(Number);
        let freqA = {}; for (let i = 0; i < arr.length; i++) if (freqA[arr[i]]) freqA[arr[i]]++; else freqA[arr[i]] = 1;
        let freqB = {}; for (let i = 0; i < brr.length; i++) if (freqB[brr[i]]) freqB[brr[i]]++; else freqB[brr[i]] = 1;
        let sum = 0;
        const conv = val => val.toString().length;

        // Remove equals
        Object.keys(freqA).forEach(key => {
            if (freqB[key]) {
                let min = Math.min(freqA[key], freqB[key]);
                freqA[key] -= min;
                freqB[key] -= min;
            }
        });

        Object.keys(freqA).forEach(key => {
            if (parseInt(key) > 9) {
                sum += freqA[key];
                let v = conv(parseInt(key));
                if (freqA[v]) {
                    freqA[v] += freqA[key];
                } else {
                    freqA[v] = freqA[key];
                }
                delete freqA[key];
            }
        });

        Object.keys(freqB).forEach(key => {
            if (parseInt(key) > 9) {
                sum += freqB[key];
                let v = conv(parseInt(key));
                if (freqB[v]) {
                    freqB[v] += freqB[key];
                } else {
                    freqB[v] = freqB[key];
                }
                delete freqB[key];
            }
        });

        // Remove equals
        Object.keys(freqA).forEach(key => {
            if (freqB[key]) {
                let min = Math.min(freqA[key], freqB[key]);
                freqA[key] -= min;
                freqB[key] -= min;
            }
        });

        freqA['1'] = 0;
        freqB['1'] = 0;

        let sumA = Object.values(freqA).reduce((a, b) => a + b, 0);
        let sumB = Object.values(freqB).reduce((a, b) => a + b, 0);
        sum += sumA + sumB;

        output(sum);
    }
}

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

function digiLog(x) {
    return x.toString().length;
}

function solve(a, b) {
    a.sort((x, y) => x - y);
    b.sort((x, y) => x - y);

    let steps = 0;

    while (a.length > 0) {
        const lastA = a[a.length - 1];
        const lastB = b[b.length - 1];
        if (lastA === lastB) {
            a.pop();
            b.pop();
        } else if (lastA > lastB) {
            a[a.length - 1] = digiLog(lastA);
            steps++;
        } else {
            b[b.length - 1] = digiLog(lastB);
            steps++;
        }
    }

    console.log(steps);
}

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n');
    for (let i = 1; i < data.length; i += 3) {
        const a = data[i + 1].trim().split(" ").map(Number);
        const b = data[i + 2].trim().split(" ").map(Number);

        solve(a, b);
    }
});

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

function eliminate(a, b) {
    const filterA = {};
    const filterB = {};
    for (let i = 0; i < a.length; i++) {
        const j = b.indexOf(a[i]);
        if (j > -1 && !filterB[j]) {
            filterA[i] = true;
            filterB[j] = true;
        }
    }

    return {
        a: a.filter((v, i) => !filterA[i]),
        b: b.filter((v, i) => !filterB[i])
    }
}

function step(a, b) {
    if (a.length === 0) {
        return;
    }

    let largestA = a[0];
    let largestAIndex = 0;
    let largestB = b[0];
    let largestBIndex = 0;
    for (let i = 0; i < a.length; i++) {
        const logValueA = digiLog(a[i]);
        if (b.indexOf(logValueA) > -1) {
            a[i] = logValueA;
            return;

        }

        const logValueB = digiLog(b[i]);
        if (a.indexOf(logValueB) > -1) {
            b[i] = logValueB;
            return;
        }

        if (largestA < a[i]) {
            largestA = a[i];
            largestAIndex = i;
        }

        if (largestB < b[i]) {
            largestB = b[i];
            largestBIndex = i;
        }
    }

    if (largestA > largestB) {
        a[largestAIndex] = digiLog(a[largestAIndex]);
    } else {
        b[largestBIndex] = digiLog(b[largestBIndex]);
    }
}

function digiLog(x) {
    return x.toString().length;
}

function solve(a, b) {
    let numberOfSteps = 0;
    const {a: nextA, b: nextB} = eliminate(a, b);
    a = nextA;
    b = nextB;
    while (a.length > 0) {
        numberOfSteps++;
        step(a, b);
        const {a: nextA, b: nextB} = eliminate(a, b);
        a = nextA;
        b = nextB;
    }

    console.log(numberOfSteps);
}

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n');
    for (let i = 1; i < data.length; i += 3) {
        const a = data[i + 1].trim().split(" ").map(Number);
        const b = data[i + 2].trim().split(" ").map(Number);

        solve(a, b);
    }
});

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

function eliminate(a, b) {
    const filterA = {};
    const filterB = {};
    for (let i = 0; i < a.length; i++) {
        const j = b.indexOf(a[i]);
        if (j > -1 && !filterB[j]) {
            filterA[i] = true;
            filterB[j] = true;
        }
    }

    return {
        a: a.filter((v, i) => !filterA[i]),
        b: b.filter((v, i) => !filterB[i])
    }
}

function step(a, b) {
    if (a.length === 0) {
        return;
    }

    let largestA = a[0];
    let largestAIndex = 0;
    let largestB = b[0];
    let largestBIndex = 0;
    for (let i = 0; i < a.length; i++) {
        const logValueA = digiLog(a[i]);
        if (b.indexOf(logValueA) > -1) {
            a[i] = logValueA;
            return;

        }

        const logValueB = digiLog(b[i]);
        if (a.indexOf(logValueB) > -1) {
            b[i] = logValueB;
            return;
        }

        if (largestA < a[i]) {
            largestA = a[i];
            largestAIndex = i;
        }

        if (largestB < b[i]) {
            largestB = b[i];
            largestBIndex = i;
        }
    }

    if (largestA > largestB) {
        a[largestAIndex] = digiLog(a[largestAIndex]);
    } else {
        b[largestBIndex] = digiLog(b[largestBIndex]);
    }
}

function digiLog(x) {
    return x.toString().length;
}

function solve(a, b) {
    let numberOfSteps = -1;
    const {a: nextA, b: nextB} = eliminate(a, b);
    a = nextA;
    b = nextB;
    while (a.length > 0) {
        numberOfSteps++;
        step(a, b);
        const {a: nextA, b: nextB} = eliminate(a, b);
        a = nextA;
        b = nextB;
    }

    console.log(numberOfSteps);
}

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n');
    for (let i = 1; i < data.length; i += 3) {
        const a = data[i + 1].trim().split(" ").map(Number);
        const b = data[i + 2].trim().split(" ").map(Number);

        solve(a, b);
    }
});

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

function eliminate(a, b) {
    const filterA = {};
    const filterB = {};
    for (let i = 0; i < a.length; i++) {
        const j = b.indexOf(a[i]);
        if (j > -1 && !filterB[j]) {
            filterA[i] = true;
            filterB[j] = true;
        }
    }

    return {
        a: a.filter((v, i) => !filterA[i]),
        b: b.filter((v, i) => !filterB[i])
    }
}

function step(a, b) {
    if (a.length === 0) {
        return;
    }

    let largestA = a[0];
    let largestAIndex = 0;
    let largestB = b[0];
    let largestBIndex = 0;
    for (let i = 0; i < a.length; i++) {
        const logValueA = digiLog(a[i]);
        if (b.indexOf(logValueA) > -1) {
            a[i] = logValueA;
            return;

        }

        const logValueB = digiLog(b[i]);
        if (a.indexOf(logValueB) > -1) {
            b[i] = logValueB;
            return;
        }

        if (largestA < a[i]) {
            largestA = a[i];
            largestAIndex = i;
        }

        if (largestB < b[i]) {
            largestB = b[i];
            largestBIndex = i;
        }
    }

    if (largestA > largestB) {
        a[largestAIndex] = digiLog(a[largestAIndex]);
    } else {
        b[largestBIndex] = digiLog(b[largestBIndex]);
    }
}

function digiLog(x) {
    return x.toString().length;
}

function solve(a, b) {
    let numberOfSteps = -1;
    while (a.length > 0) {
        numberOfSteps++;
        const {a: nextA, b: nextB} = eliminate(a, b);
        a = nextA;
        b = nextB;
        step(a, b);
    }

    console.log(numberOfSteps);
}

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n');
    for (let i = 1; i < data.length; i += 3) {
        const a = data[i + 1].trim().split(" ").map(Number);
        const b = data[i + 2].trim().split(" ").map(Number);

        solve(a, b);
    }
});


var info = readline().split(' ').map(Number)
var mountain = readline().split(' ').map(Number)

var nbOfPick = info[0]

var nbToChange = info[1]
var len = nbOfPick * 2 + 1
var prev = mountain[1]
var prevPrev = mountain[0]
var indexToUpdate = []
for (var i = 2; i < len; i++) {
  if (nbToChange <= 0) {
    break;
  }

  if (prev - 1 > prevPrev && prev - 1 > mountain[i]) {
    indexToUpdate.push(i - 1)
    nbToChange -= 1
  }

  prevPrev = prev
  prev = mountain[i]
}

for (var i = 0; i < info[1]; i++) {
  if (indexToUpdate.length > 0) {
    mountain[indexToUpdate.pop()] -= 1
  }
}

print(mountain.join(' '))

var values = readline().split(" ").map(Number);
var n = values[0];
var k = values[1];

var arr = readline().split(" ").map(Number);
var result = [];

for (var i = 0; i < arr.length; i++) {
    var next = arr[i] - 1;
    if (i % 2 !== 0 &&
        k > 0 &&
        next > arr[i - 1] &&
        next > arr[i + 1]) {
        result.push(next);
        k--;
    } else {
        result.push(arr[i]);
    }
}

print(result.join(" "));

var info = readline().split(' ').map(Number)
var mountain = readline().split(' ').map(Number)

var nbOfPick = info[0]

var nbToChange = info[1]
var len = nbOfPick * 2 + 1
var prev = mountain[1]
var prevPrev = mountain[0]
var indexToUpdate = []
for (var i = 2; i < len; i++) {
  if (nbToChange <= 0) {
    break;
  }

  if (prev > prevPrev && prev > mountain[i]) {
    indexToUpdate.push(i - 1)
    nbToChange -= 1
  }

  prevPrev = prev
  prev = mountain[i]
}

for (var i = 0; i < info[1]; i++) {
  if (indexToUpdate.length > 0) {
    mountain[indexToUpdate.pop()] -= 1
  }
}

print(mountain)

var info = readline().split(' ').map(Number)
var mountain = readline().split(' ').map(Number)

var nbOfPick = info[0]

var nbToChange = info[1]
var len = nbOfPick * 2 + 1
var prev = mountain[1]
var prevPrev = mountain[0]
var indexToUpdate = []
for (var i = 2; i < len; i++) {
  if (nbToChange <= 0) {
    break;
  }

  if (prev > prevPrev && prev > mountain[i]) {
    indexToUpdate.push(i - 1)
    nbToChange -= 1
  }

  prevPrev = prev
  prev = mountain[i]
}

for (var i = 0; i < info[1]; i++) {
  if (indexToUpdate.length > 0) {
    mountain[indexToUpdate.pop()] -= 1
  }
}

print(mountain.join(' '))

var values = readline().split(" ").map(Number);
var n = values[0];
var k = values[1];

var arr = readline().split(" ").map(Number);
var result = [];

for (var i = 0; i < arr.length; i++) {
    if (i % 2 === 0 && k !== 0) {
        result.push(arr[i] - 1);
        k--;
    } else {
        result.push(arr[i]);
    }
}

print(result.join(" "));

var values = readline().split(" ").map(Number);
var n = values[0];
var k = values[1];

var arr = readline().split(" ").map(Number);
var result = [];

for (var i = 0; i < arr.length; i++) {
    if (i % 2 !== 0 && k > 0) {
        result.push(arr[i] - 1);
        k--;
    } else {
        result.push(arr[i]);
    }
}

print(result.join(" "));

var values = readline().split(" ").map(Number);
var n = values[0];
var k = values[1];

var arr = readline().split(" ").map(Number);
var result = [];

for (var i = 0; i < arr.length - 1; i++) {
    var next = arr[i] - 1;
    if (i % 2 !== 0 &&
        k > 0 &&
        next > arr[i] &&
        next < arr[i + 1]) {
        result.push(next);
        k--;
    } else {
        result.push(arr[i]);
    }
}

print(result.join(" "));

var values = readline().split(" ").map(Number);
var n = values[0];
var k = values[1];

var arr = readline().split(" ").map(Number);
var result = [];

for (var i = 0; i < arr.length - 1; i++) {
    var next = arr[i] - 1;
    if (i % 2 !== 0 &&
        k > 0 &&
        next > arr[i - 1] &&
        next < arr[i + 1]) {
        result.push(next);
        k--;
    } else {
        result.push(arr[i]);
    }
}

print(result.join(" "));


const solve = (arr,n)=>{
     if(n===1) return "YES";
     let start = arr[0],flag = 0;
     for(let i=0;i<n;i++){
          if(Math.abs(start-arr[i])>1){
               flag=1;
               break;
          }
          start++;
     }
     if(flag===0) return "YES";
     flag = 0;
     start = arr[0]+1;
     for(let i=0;i<n;i++){
          if(Math.abs(start-arr[i])>1){
               flag=1;
               break;
          }
          start++;
     }
     if(flag===0) return "YES";
     return "NO";
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for (let i = 0; i < t; i++) {
       let n = parseInt(readline());
       let mat = readline().trim().split(" ").map(cur=>parseInt(cur));
       console.log(solve(mat,n))
  }
}
main();

const fs = require("fs");

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

const testCases = [];
let T;

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

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

    testCases.push(testCase);
  }
}

function solution(testCase, index) {
  const { n, x } = testCase;

  const test = (start) => {
    let i = 1;
    let last = start;
    while (i < n) {
      if (x[i] - last >= 0 && x[i] - last <= 2) {
        i++;
        last++;
      } else {
        break;
      }
    }
    return i == n;
  };

  const result = test(x[0] - 1) || test(x[0]) || test(x[0] + 1);

  console.log(result ? "YES" : "NO");
}

parseInput();

testCases.forEach(solution);

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

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

function div(val, by){
    return (val - val % by) / by;
}

const cnk = (n, k) => {
    let res = 1;
    for (let i = 1; i <= k; i++)
        res = res * (n - k + i) / i;
    return Math.round(res + 0.01);
}

const calc = (n, a)=>{
    let count3 = 0;
    let count2 = 0;
    for (let i = 1; i < n; i++) {
        if (a[i] - a[i - 1] > 3) {
            return 'NO';
        } else if (a[i] - a[i - 1] === 3) {
            count3++;
        } else if (a[i] - a[i - 1] === 2) {
            count2++;
        }
    }
    if (count3 > 1) return 'NO';
    if (count3 === 1 && count2 > 0) return 'NO';
    if (count2 > 2) return 'NO';

    return 'YES';
};

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

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) ? 'YES' : 'NO'
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    let c2 = 0
    let c3 = 0
    for (let i = 1; i < arr.length; i++) {
        const d = arr[i] - arr[i - 1]
        if (d === 2) {
            c2++
        } else if (d === 3) {
            c3++
        } else if (d > 3) {
            return false
        }
    }
    if (c3 && c2) return false
    if (c2 > 2) return false
    if (c3 > 1) return false
    return true
}

'use strict';

var readline = require('readline');

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

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

function solve(n, a) {
  if (a[a.length - 1] - a[0] <= n + 1) {
    console.log('YES');
  } else {
    console.log('NO');
  }
}

async function main(read) {
  let t = Number(await read());
  while (t--) {
    const n = Number(await read());
    const a = (await read()).split(' ').map(Number);
    solve(n, a);
  }
}

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

'use strict';

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

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

const calc = (n, a)=>{
  let check = (init)=>{
    let i;
    for (i=0; i<n; i++){
      if (a[i]==init || a[i]==init-1 || a[i]==init+1)
        init++;
      else
        break;
    }
    return (i==n)
  };
  for (let i=a[0]-1; i<=a[0]+1; i++)
    if (check(i))
      return true;
  return false;
};

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

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 N = nextInt();
		var list = nextIntArray(N);
		var ok = true;
		var c2 = 0;
		var c3 = 0;
		for(var i = 0; i < N - 1; i++){
			if(list[i + 1] - list[i] > 3){
				ok = false;
				break;
			}else if(list[i + 1] - list[i] == 2){
				c2++;
			}else if(list[i + 1] - list[i] == 3){
				c3++;
			}
		}
		if(c2 > 2 || c3 > 1){
			ok = false;
		}else{
			if(c3 == 1 && c2 > 0){
				ok = false;
			}
		}
		myout((ok) ? "YES" : "NO");
	}
}

const solve = (arr,n)=>{
     if(n===1) return "YES";
     if(arr[1]-arr[0]===1) start = arr[0];
     else start = arr[0]+1;
     for(let i=0;i<n;i++){
          if(Math.abs(start-arr[i])>1) return "NO";
          start++;
     }
     return "YES";
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for (let i = 0; i < t; i++) {
       let n = parseInt(readline());
       let mat = readline().trim().split(" ").map(cur=>parseInt(cur));
       console.log(solve(mat,n))
  }
}
main();

const solve = (arr,n)=>{
     for(let i=0;i<n-1;i++){
          if(arr[i+1]-arr[i]===3){
               arr[i+1]-=1;
               arr[i]+=1;
          }
          else if(arr[i+1]-arr[i]===2) arr[i]+=1;
          else if(arr[i+1]-arr[i]===1) continue;
          else return "NO";
     }
     return "YES";
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for (let i = 0; i < t; i++) {
       let n = parseInt(readline());
       let mat = readline().trim().split(" ").map(cur=>parseInt(cur));
       console.log(solve(mat,n))
  }
}
main();

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var ok = true;
		var c2 = 0;
		var c3 = 0;
		for(var i = 0; i < N - 1; i++){
			if(list[i + 1] - list[i] > 3){
				ok = false;
				break;
			}else if(list[i + 1] - list[i] == 2){
				c2++;
			}else if(list[i + 1] - list[i] == 3){
				c3++;
			}
		}
		if(c2 > 2 || c3 > 1){
			ok = false;
		}
		myout((ok) ? "YES" : "NO");
	}
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var ok = true;
		var c = 0;
		for(var i = 0; i < N - 1; i++){
			if(list[i + 1] - list[i] > 3){
				ok = false;
				break;
			}else if(list[i + 1] - list[i] == 2 || list[i + 1] - list[i] == 3){
				c++;
			}
		}
		if(c > 1){
			ok = false;
		}
		myout((ok) ? "YES" : "NO");
	}
}

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

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

function div(val, by){
    return (val - val % by) / by;
}

const cnk = (n, k) => {
    let res = 1;
    for (let i = 1; i <= k; i++)
        res = res * (n - k + i) / i;
    return Math.round(res + 0.01);
}

const calc = (n, a)=>{
    let count = 0;
    for (let i = 1; i < n; i++) {
        if (a[i] - a[i - 1] > 3) {
            return 'NO';
        } else if (a[i] - a[i - 1] === 3) {
            count++;
        }
    }
    if (count > 1) return 'NO';

    return 'YES';
};

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


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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var K = nextInt();
		var list = nextIntArray(N);
		var output = 0;
		for(var i = 0; i < K; i++){
			if(list[i] > K){
				output++;
			}
		}
		myout(output);
	}
}

'use strict';

const fs = require('fs');

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', function() {
    inputString = inputString.split('\n');

    main();
});

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

function isPossible(n, x, heights) {
    heights.sort();
    heights.sort(function(a, b) {
        return a - b;
      });
    // //console.log(heights)

    let front = []
    let back = []

    for (let i = 0; i < heights.length; i++) {
        if (i < n) {
            front.push(heights[i])
        } else {
            back.push(heights[i])
        }
    }

    // //console.log(front)
    // //console.log(back)
    for (let j = 0; j < front.length; j++) {
        if (back[j] - front[j] < x) {
            // //console.log(back[j] + " " + front[j])
            return "NO";
        }
    }

    return "YES";
}

function calc(a, m) {
    let s = "";
    for (let index = 0; index < m; index++) {
        s += "B"
    }

   for (let index = 0; index < a.length; index++) {
        let ai = a[index];

        if (ai < (m + 1 - ai)) {
            let _s = s.replaceAt(ai - 1, "A");
            if (compare(_s, s) < 0) {
                s = _s;
                continue;
            } else if (compare(_s, s) >= 0) {
                    let __ss = s.replaceAt(m + 1 - ai - 1, "A");
                    if (compare(__ss, s) < 0) {
                        s = __ss;
                        continue;
                    }
            }
         }  else {
            let _s = s.replaceAt(m + 1 - ai - 1, "A");
            if (compare(_s, s) < 0) {
                s = _s;
                continue;
            }  if (compare(_s, s) >= 0) {
                    let __ss = s.replaceAt(ai - 1, "A");
                    if (compare(__ss, s) < 0) {
                        s = __ss;
                        continue;
                    }
            }
    }
}

   return s;
}

function compare(s1, s2) {
    return s1.localeCompare(s2)
}

String.prototype.replaceAt = function(index, replacement) {
    return this.substring(0, index) + replacement + this.substring(index + replacement.length);
}

function main() {
    // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);

    const test_cases = parseInt(readLine().trim(), 10);

    for (let gItr = 0; gItr < test_cases; gItr++) {
        const nk = readLine().replace(/\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));
        const n = nk[0];
        const k = nk[1];

        const p = readLine().replace(/\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));
        const q = p
        if (k == n || k == 0) {
            console.log("0");
        } else {
            const p1 = p.slice(0, k)
            q.sort(function(a, b){return a-b});

            let count = 0
            for (let i = 0; i < k; i++) {
                if (!p1.includes(q[i])) count++
            }

            console.log(count)
        }

        // if ((n >= 1 && n <= 50) && (m >= 1 && m <= 50)) {
        // const val = readLine().replace(/\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));
        // const val = readLine().trim()
        // if (val.toUpperCase() == "YES") console.log("YES")
        // else console.log("NO")
        // let output = calc(val, m);
        // console.log(output)
        // }
        // ws.write(result + '\n');
    }

    // ws.end();
}

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*/
    const splitLines = lines.map(x => x.split(" ").map(x => parseInt(x)))
    for (let i = 0; i < splitLines[0][0]; i ++)
    {
        const currentArray = splitLines.slice(2 * i + 1, 2 * i + 3);
        const k = currentArray[0][1];
        let count = 0;
        for (const p of currentArray[1].slice(0, k))
        {
            if (p > k)
                count ++;
        }
        console.log(count);
    }
})

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

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

    for (let i = 0; i < N; i++) {
        const [n, k] = readline().split(' ').map(Number);
        const arr = readline().split(' ').map(Number);

        let counter = 0;
        for (let i = 0; i < k; i++) {
            if (arr[i] > k) {
                counter++;
            }
        }

        output(counter);
    }
}

'use strict';

function solve(n, m, a) {
  const set = new Set(Array.from({
    length: m
  }, (_, i) => i + 1));
  for (let i = 0; i < m; i++) set.delete(a[i]);
  return set.size;
}

async function main(r) {
  const rns = async () => {
    return (await r()).split(' ').filter(s => s !== '').map(Number);
  };
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const [n, m] = await rns();
      const a = await rns();
      res[i] = solve(n, m, 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);
});

var tests = parseInt(readline());
    var n, k;
    var a;
    for (var t=0; t < tests; t++) {
        var nk = readline().split(' ').map(x=>parseInt(x));
        n = nk[0];
        k = nk[1];
        a = readline().split(' ').map(x=>parseInt(x));
        var b = [...a];
        b.sort((x,y)=>x-y);
        var map = {};
        for (var i = 0; i < k; i++) {
            if (map[b[i]] == undefined) {
                map[b[i]] = 0;
            }
            map[b[i]]++;
        }
        var swaps = 0;
        for (var i = 0; i < k; i++) {
            if (!map[a[i]]) {
                swaps++;
            } else {
                map[a[i]]--;
            }
        }
        print(swaps);
    }

'use strict';

const fs = require('fs');

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', function() {
    inputString = inputString.split('\n');

    main();
});

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

function isPossible(n, x, heights) {
    heights.sort();
    heights.sort(function(a, b) {
        return a - b;
      });
    // //console.log(heights)

    let front = []
    let back = []

    for (let i = 0; i < heights.length; i++) {
        if (i < n) {
            front.push(heights[i])
        } else {
            back.push(heights[i])
        }
    }

    // //console.log(front)
    // //console.log(back)
    for (let j = 0; j < front.length; j++) {
        if (back[j] - front[j] < x) {
            // //console.log(back[j] + " " + front[j])
            return "NO";
        }
    }

    return "YES";
}

function calc(a, m) {
    let s = "";
    for (let index = 0; index < m; index++) {
        s += "B"
    }

   for (let index = 0; index < a.length; index++) {
        let ai = a[index];

        if (ai < (m + 1 - ai)) {
            let _s = s.replaceAt(ai - 1, "A");
            if (compare(_s, s) < 0) {
                s = _s;
                continue;
            } else if (compare(_s, s) >= 0) {
                    let __ss = s.replaceAt(m + 1 - ai - 1, "A");
                    if (compare(__ss, s) < 0) {
                        s = __ss;
                        continue;
                    }
            }
         }  else {
            let _s = s.replaceAt(m + 1 - ai - 1, "A");
            if (compare(_s, s) < 0) {
                s = _s;
                continue;
            }  if (compare(_s, s) >= 0) {
                    let __ss = s.replaceAt(ai - 1, "A");
                    if (compare(__ss, s) < 0) {
                        s = __ss;
                        continue;
                    }
            }
    }
}

   return s;
}

function compare(s1, s2) {
    return s1.localeCompare(s2)
}

String.prototype.replaceAt = function(index, replacement) {
    return this.substring(0, index) + replacement + this.substring(index + replacement.length);
}

function main() {
    // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);

    const test_cases = parseInt(readLine().trim(), 10);

    for (let gItr = 0; gItr < test_cases; gItr++) {
        const nk = readLine().replace(/\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));
        const n = nk[0];
        const k = nk[1];

        const p = readLine().replace(/\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));
        const q = p
        if (k == n || k == 0) {
            console.log("0");
        } else {
            q.sort(function(a, b){return a-b});

            const p1 = p.slice(0, k)

            let count = 0
            for (let i = 0; i < k; i++) {
                if (!p1.includes(q[k])) count++
            }

            console.log(count)

        }

        // if ((n >= 1 && n <= 50) && (m >= 1 && m <= 50)) {
        // const val = readLine().replace(/\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));
        // const val = readLine().trim()
        // if (val.toUpperCase() == "YES") console.log("YES")
        // else console.log("NO")
        // let output = calc(val, m);
        // console.log(output)
        // }
        // ws.write(result + '\n');
    }

    // ws.end();
}

'use strict';

const fs = require('fs');

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', function() {
    inputString = inputString.split('\n');

    main();
});

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

function isPossible(n, x, heights) {
    heights.sort();
    heights.sort(function(a, b) {
        return a - b;
      });
    // //console.log(heights)

    let front = []
    let back = []

    for (let i = 0; i < heights.length; i++) {
        if (i < n) {
            front.push(heights[i])
        } else {
            back.push(heights[i])
        }
    }

    // //console.log(front)
    // //console.log(back)
    for (let j = 0; j < front.length; j++) {
        if (back[j] - front[j] < x) {
            // //console.log(back[j] + " " + front[j])
            return "NO";
        }
    }

    return "YES";
}

function calc(a, m) {
    let s = "";
    for (let index = 0; index < m; index++) {
        s += "B"
    }

   for (let index = 0; index < a.length; index++) {
        let ai = a[index];

        if (ai < (m + 1 - ai)) {
            let _s = s.replaceAt(ai - 1, "A");
            if (compare(_s, s) < 0) {
                s = _s;
                continue;
            } else if (compare(_s, s) >= 0) {
                    let __ss = s.replaceAt(m + 1 - ai - 1, "A");
                    if (compare(__ss, s) < 0) {
                        s = __ss;
                        continue;
                    }
            }
         }  else {
            let _s = s.replaceAt(m + 1 - ai - 1, "A");
            if (compare(_s, s) < 0) {
                s = _s;
                continue;
            }  if (compare(_s, s) >= 0) {
                    let __ss = s.replaceAt(ai - 1, "A");
                    if (compare(__ss, s) < 0) {
                        s = __ss;
                        continue;
                    }
            }
    }
}

   return s;
}

function compare(s1, s2) {
    return s1.localeCompare(s2)
}

String.prototype.replaceAt = function(index, replacement) {
    return this.substring(0, index) + replacement + this.substring(index + replacement.length);
}

function main() {
    // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);

    const test_cases = parseInt(readLine().trim(), 10);

    for (let gItr = 0; gItr < test_cases; gItr++) {
        const nk = readLine().replace(/\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));
        const n = nk[0];
        const k = nk[1];

        const p = readLine().replace(/\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));

        if (k == n || k == 0) {
            console.log("0");
        } else {
            console.log(k)
        }

        // if ((n >= 1 && n <= 50) && (m >= 1 && m <= 50)) {
        // const val = readLine().replace(/\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));
        // const val = readLine().trim()
        // if (val.toUpperCase() == "YES") console.log("YES")
        // else console.log("NO")
        // let output = calc(val, m);
        // console.log(output)
        // }
        // ws.write(result + '\n');
    }

    // ws.end();
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var K = nextInt();
		var list = nextIntArray(N);
		var output = 0;
		for(var i = 0; i < K; i++){
			if(list[i] != i + 1){
				var index = list.indexOf(i + 1);
				var tmp = list[i];
				list[i] = list[index];
				list[index] = tmp;
				output++;
			}
		}
		myout(output);
	}
}


var s = ((+readline()*2))+1;var myarray = ["0"];var last = myarray[myarray.length - 1]

while(last.length!=s){

last = [...new Set(last)];

last.push((+last[last.length-1]) + 1)
last = last.concat(last.slice(0,last.length-1).reverse())

myarray.push(last)
}

for(var i=0;i<myarray.length;i++){tnzm(myarray[i])}
for(var i=myarray.length-2;i>=0;i--){tnzm(myarray[i])}

function tnzm(n){
var space = "";
for(var l=0;l<myarray.length-(i+1);l++){space+="  "}
print(space + n.toString().replace(/,/g," "))
}

var deleteSpace = function(arr)
{
	arr = arr.split('');
	while (arr[arr.length - 1] === ' ')
	{
		if (arr[arr.length - 1] === ' ') arr.splice(arr.length - 1, 1);
	}
	return arr.join('');
}

var main = function(n)
{
	var arr = [],arrAll = [], space, numSpace = 2 * n;
	for (var i = 0; i <= n; i++)
	{
		space = [];
		numSpace -= 2 * i;
		for (var i1 = 1; i1 <= numSpace; i1++)
		{
			space.push(' ');
		}
		arr.push(space.join(''));
		if (i === 0)
			{
				space = space.join('');
				arr[arr.length - 1] += '0';
				print(arr);
				space = space.split('');
			}
		else
			{
				for (var resNum = 0; resNum <= i - 1; resNum++)
				{
				    arr.push(resNum + ' ');
				}
				arr = arr.join('') + i + ' ' + arr.reverse().join('');
				if (arr[arr.length - 1] === ' ') arr = deleteSpace(arr);
				print(arr);
			}
		arrAll.push(arr);
		arr = [];
		numSpace += 2 * i;
	}
	arrAll.reverse();
	for (i = 1; i <= arrAll.length - 1; i++)
	{
	    print( arrAll[i]);
	}
}

main(+readline());

// http://codeforces.com/problemset/problem/118/B
function addSpace(str,time) {
  var space="";
  for(var i = 0; i < time; i++)space+=" ";
  return space+str+"\n";
}
function createPalindromic(n){
  var line="",count=n-1;
  for(var i = 0; i < n; i++){
    line+=(i).toString();
    if(i<=count)line+=" ";
  }
  return line+(n).toString()+line.split("").reverse().join("");
}
function printPresent(n){
  var palindromicArray=[],textToPrint="",counter=n*2;
  for (var i = 0; i < n; i++) {
    var line=addSpace(createPalindromic(i),counter);
    palindromicArray.push(line);
    textToPrint+=line;
    counter-=2;
  }
  textToPrint+=addSpace(createPalindromic(n),0);
  for (var i = n-1; i >= 0; i--)textToPrint+=palindromicArray[i];
  return textToPrint.replace(/\n$/,"");
}
//console.log(printPresent(process.argv[2]));
print(printPresent(readline()));

function getLine(start, n) {
	var res = [];
	var i;
	for (i = 0; i < start; i++ ) {
		res.push(' ');
	}
	for (i = 0; i <= n; i++) {
		res.push(i);
	}
	for (i = n - 1; i >= 0; i--) {
		res.push(i)
	}
	print(res.join(' '));
}

var n = parseInt(readline());
var i;

for(i = 0; i <= n; i++) {
	getLine(n - i, i);
}

for(i = n - 1; i >= 0; i--) {
	getLine(n - i, i);
}

function line(start, n) {
	var res = [];
	var i = 0;

	for (i = 0; i < start; i++) {
		res.push(' ');
	};

	for (i = 0; i <= n; i++) {
		res.push(i);
	};

	for (i = n - 1; i >= 0; i--) {
		res.push(i);
	};

	print(res.join(' '));
};

var n = parseInt(readline());
var i = 0;

for (i = 0; i <= n; i++) {
	line(n - i, i);
};

for (i = n - 1; i >= 0; i--) {
	line(n - i, i);
};

var n=+readline();
function line(n, a){
	var ret = [];
	for(var i=0; i<a-n; i++){
		ret.push(' ');
	}
	for(var i=0; i<=n; i++){
		ret.push(i);
	}
	for(var i=n-1; i>=0; i--){
		ret.push(i);
	}
	return ret.join(' ');
}

for(var i=0; i<=n; i++){
	print(line(i, n));
}
for(var i=n-1; i>=0; i--){
	print(line(i, n));
}

;(function () {

	var n = +readline();
	var s = new Array(2 * n + 1);

	for (var i = 0; i < s.length; i++) {
		s[i] = [];
		for (var j = 0; j < Math.abs(n - i); j++) s[i].push(' ');
		for (var j = 0; j < n - Math.abs(n - i) + 1; j++)s[i].push(j);
		for (var j = n - Math.abs(n - i) - 1; j >= 0 ; j--)s[i].push(j);
		s[i] = s[i].join(' ') + '\n';
	}

	print(s.join(''));

}).call(this);

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++];
}
function main() {
  const len = +readLine();
  const result = [];

  for (let i = 0; i <= len; i++) {
    const line = [];
    for (let j = 0; j <= Math.floor((i * 2) / 2); j++) {
      line.push(j);
    }
    for (let j = Math.floor((i * 2) / 2) - 1; j >= 0; j--) {
      line.push(j);
    }
    result.push(line);
  }

  for (let i = len - 1; i >= 0; i--) {
    result.push(result[i]);
  }

  for (let i = 0; i < result.length; i++) {
    if (i <= len) {
      console.log(`${" ".repeat((len - i) * 2)}${result[i].join(" ")}`);
    } else {
      console.log(`${" ".repeat((i - len) * 2)}${result[i].join(" ")}`);
    }
  }
}

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

function main() {
	let n = readLine() >> 0;
	let arr = [];
	let s = n * 2;

	for (let i = 0; i <= s; i++) {
		arr[i] = Array(s + 1).fill(' ');
	}

	for (let i = 0; i <= n; i++) {
		let c = 2 * i;
		let a = n - i;
		let x = 0;
		for (let j = a; j <= n; j++) {
			arr[i][j] = x;
			arr[i][s - j] = x;
			arr[s - i][j] = x;
			arr[s - i][s - j] = x;
			x++;
		}
	}

	for (let i = 0; i <= s; i++) {
		let str = '';
		let found = false;
		for (let j = 0; j <= s; j++) {
			if (arr[i][j] !== ' ') {
				found = true;
			}

			if (!found) {
				str += arr[i][j] + ' ';
			} else {
				if (arr[i][j] !== ' ') {
					str += arr[i][j] + ' ';
				}
			}
		}
		console.log(str.replace(/\s$/, ''));
	}
}

var n = parseInt(readline());
var str = "", down = false, space = n;
for(var i = 0; i <= 2*n; ++i)
{
    for(var j = 0; j < 2*space; ++j)
    {
        str += " ";
    }
    for(var j = 0; j <= Math.abs(n-space); ++j)
    {
        if(Math.abs(n-space) == 0){str = str + j.toString();}
        else {str = str + j.toString() + " ";}
    }
    for(var j = Math.abs(n-space)-1; j >= 0; --j)
    {
        if(j == 0){str = str + j.toString();}
        else {str = str + j.toString() + " ";}
    }
    if(i < 2*n){str += "\n"};
    if(down){space ++;}
    else {space --;}
    if(space == 0){down = true;}
}
print(str);

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

function main() {
	let n = readLine() >> 0;
	let arr = [];
	let s = n * 2;

	for (let i = 0; i <= s; i++) {
		arr[i] = Array(s + 1).fill(' ');
	}

	for (let i = 0; i <= n; i++) {
		let c = 2 * i; // 2 * 1 = 2
		let a = n - i; // 2 - 1 = 1
		let x = 0;
		for (let j = a; j <= n; j++) {
			arr[i][j] = x;
			arr[i][s - j] = x;
			arr[s - i][j] = x;
			arr[s - i][s - j] = x;
			x++;
		}
	}

	for (let i = 0; i <= s; i++) {
		console.log(arr[i].join(' '));
	}
}

;(function () {

	var n = +readline();
	var s = new Array(2 * n + 1);

	for (var i = 0; i < s.length; i++) {
		s[i] = '';
		for (var j = 0; j < Math.abs(n - i); j++)			s[i] += ' ';
		for (var j = 0; j < n - Math.abs(n - i) + 1; j++)	s[i] += j + ' ';
		for (var j = n - Math.abs(n - i) - 1; j > 0 ; j--)	s[i] += j + ' ';
		s[i] += '0\n';
	}

	print(s.join(''));

}).call(this);

;(function () {

	var n = +readline();
	var s = new Array(2 * n + 1);

	for (var i = 0; i < s.length; i++) {
		s[i] = '';
		for (var j = 0; j < Math.abs(n - i); j++)			s[i] += ' ';
		for (var j = 0; j < n - Math.abs(n - i) + 1; j++)	s[i] += j;
		for (var j = n - Math.abs(n - i) - 1; j >= 0 ; j--)	s[i] += j;
		s[i] += '\n';
	}

	print(s.join(''));

}).call(this);

var n = parseInt(readline());
var str = "", down = false, space = n;
for(var i = 0; i <= 2*n; ++i)
{
    for(var j = 0; j < 2*space; ++j)
    {
        str += " ";
    }
    for(var j = 0; j <= Math.abs(n-space); ++j)
    {
        str = str + j.toString() + " ";
    }
    for(var j = Math.abs(n-space)-1; j >= 0; --j)
    {
        str = str + j.toString() + " ";
    }
    str += "\b";
    if(i < 2*n){str += "\n"};
    if(down){space ++;}
    else {space --;}
    if(space == 0){down = true;}
}
print(str);

var n = parseInt(readline());
var str = "", down = false, space = n;
for(var i = 0; i <= 2*n; ++i)
{
    for(var j = 0; j < 2*space; ++j)
    {
        str += " ";
    }
    for(var j = 0; j <= Math.abs(n-space); ++j)
    {
        if(j == Math.abs(n-space)){str = str + j.toString();}
        else {str = str + j.toString() + " ";}
    }
    for(var j = Math.abs(n-space)-1; j >= 0; --j)
    {
        if(j == 0){str = str + j.toString();}
        else {str = str + j.toString() + " ";}
    }
    if(i < 2*n){str += "\n"};
    if(down){space ++;}
    else {space --;}
    if(space == 0){down = true;}
}
print(str);

var n = parseInt(readline());
var str = "", down = false, space = n;
for(var i = 0; i <= 2*n; ++i)
{
    for(var j = 0; j < 2*space; ++j)
    {
        str += " ";
    }
    for(var j = 0; j <= Math.abs(n-space); ++j)
    {
        str = str + j.toString() + " ";
    }
    for(var j = Math.abs(n-space)-1; j >= 0; --j)
    {
        str = str + j.toString() + " ";
    }
    if(i < 2*n){str += "\n"};
    if(down){space ++;}
    else {space --;}
    if(space == 0){down = true;}
}
print(str);

var n = parseInt(readline());
var str = "", down = false, space = n;
for(var i = 0; i <= 2*n; ++i)
{
    for(var j = 0; j < 2*space; ++j)
    {
        str += " ";
    }
    for(var j = 0; j <= Math.abs(n-space); ++j)
    {
        str = str + j.toString() + " ";
    }
    for(var j = Math.abs(n-space)-1; j >= 0; --j)
    {
        str = str + j.toString() + " ";
    }
    for(var j = 0; j < 2*space; ++j)
    {
        str += " ";
    }
    if(i < 2*n){str += "\n"};
    if(down){space ++;}
    else {space --;}
    if(space == 0){down = true;}
}
print(str);

var n = parseInt(readline());
var str = "", down = false, space = n;
for(var i = 0; i <= 2*n; ++i)
{
    for(var j = 0; j < 2*space; ++j)
    {
        str += " ";
    }
    for(var j = 0; j <= Math.abs(n-space); ++j)
    {
        str = str + j.toString() + " ";
    }
    for(var j = Math.abs(n-space)-1; j >= 0; --j)
    {
        if(j == 0){str = str + j.toString();}
        else {str = str + j.toString() + " ";}
    }
    if(i < 2*n){str += "\n"};
    if(down){space ++;}
    else {space --;}
    if(space == 0){down = true;}
}
print(str);

var n = parseInt(readline());
var str = "", down = false, space = n;
for(var i = 0; i <= 2*n; ++i)
{
    for(var j = 0; j < 2*space; ++j)
    {
        str += " ";
    }
    for(var j = 0; j <= Math.abs(n-space); ++j)
    {
        str = str + j.toString() + " ";
    }
    for(var j = Math.abs(n-space)-1; j >= 0; --j)
    {
        str = str + j.toString() + " ";
    }
    for(var j = 0; j < 2*space; ++j)
    {
        str += " ";
    }
    str += "\n";
    if(down){space ++;}
    else {space --;}
    if(space == 0){down = true;}
}
print(str);

var main = function(n)
{
	var arr = [],arrAll = [], space, numSpace = 2 * n;
	for (var i = 0; i <= n; i++)
	{
		space = [];
		numSpace -= 2 * i;
		for (var i1 = 1; i1 <= numSpace; i1++)
		{
			space.push(' ');
		}
		arr.push(space.join(''));
		if (i === 0)
			{
				space = space.join('');
				arr[arr.length - 1] += '0';
				print(arr);
				space = space.split('');
			}
		else
			{
				for (var resNum = 0; resNum <= i - 1; resNum++)
				{
				    if (resNum !== i - 1)
					    arr.push(resNum + ' ');
					else arr.push(resNum);
				}
				arr = arr.join('') + i + ' ' + arr.reverse().join('');

				print(arr);
			}
		arrAll.push(arr);
		arr = [];
		numSpace += 2 * i;
	}
	arrAll.reverse();
	for (i = 1; i <= arrAll.length - 1; i++)
	{
	    print( arrAll[i]);
	}
}

main(+readline());

var main = function(n)
{
	var arr = [],arrAll = [], space, numSpace = 2 * n;
	for (var i = 0; i <= n; i++)
	{
		space = [];
		numSpace -= 2 * i;
		for (var i1 = 1; i1 <= numSpace; i1++)
		{
			space.push(' ');
		}
		arr.push(space.join(''));
		if (i === 0)
			{
				space = space.join('');
				arr[arr.length - 1] += '0';
				print(arr);
				space = space.split('');
			}
		else
			{
				for (var resNum = 0; resNum <= i - 1; resNum++)
				{
					arr.push(resNum + ' ');
				}
				arr = arr.join('') + i + ' ' + arr.reverse().join('');

				print(arr);
			}
		arrAll.push(arr);
		arr = [];
		numSpace += 2 * i;
	}
	arrAll.reverse();
	for (i = 1; i <= arrAll.length - 1; i++)
	{
	    print( arrAll[i]);
	}
}

main(+readline());

// http://codeforces.com/problemset/problem/118/B
function addSpace(str,time) {
  var space="";
  for(var i = 0; i < time; i++)space+=" ";
  return space+str+space+"\n";
}
function createPalindromic(n){
  var line="";
  var count=n-1;
  for(var i = 0; i < n; i++){
    line+=(i).toString();
    if(i<=count)line+=" ";
  }
  return line+(n).toString()+line.split("").reverse().join("");
}
function printPresent(n){
  var palindromicArray=[];
  var textToPrint="";
  var counter=n*2;
  for (var i = 0; i < n; i++) {
    var line=addSpace(createPalindromic(i),counter);
    palindromicArray.push(line)
    textToPrint+=line;
    counter-=2;
  }
  textToPrint+=addSpace(createPalindromic(n),0);
  for (var i = n-1; i >= 0; i--) {
     textToPrint+=palindromicArray[i];
  }
  return textToPrint.replace(/\n$/,"");
}
printPresent(5);

var s = ((+readline()*2))+1;
var myarray = ["0"];
var last = myarray[myarray.length - 1]

while(last.length!=s){
last = [...new Set(last)];

last.push((+last[last.length-1]) + 1)
last = last.concat(last.slice(0,last.length-1).reverse())
myarray.push(last)
}

for(var i=0;i<myarray.length;i++)
{print(myarray[i].toString().replace(/,/g," "))}

for(var i=myarray.length-2;i>=0;i--){print(myarray[i].toString().replace(/,/g," "))}