Alice and Bob play a game. Alice has $$$n$$$ cards, the $$$i$$$-th of them has the integer $$$a_i$$$ written on it. Bob has $$$m$$$ cards, the $$$j$$$-th of them has the integer $$$b_j$$$ written on it.On the first turn of the game, the first player chooses one of his/her cards and puts it on the table (plays it). On the second turn, the second player chooses one of his/her cards such that the integer on it is greater than the integer on the card played on the first turn, and plays it. On the third turn, the first player chooses one of his/her cards such that the integer on it is greater than the integer on the card played on the second turn, and plays it, and so on — the players take turns, and each player has to choose one of his/her cards with greater integer than the card played by the other player on the last turn.If some player cannot make a turn, he/she loses.For example, if Alice has $$$4$$$ cards with numbers $$$[10, 5, 3, 8]$$$, and Bob has $$$3$$$ cards with numbers $$$[6, 11, 6]$$$, the game may go as follows:  Alice can choose any of her cards. She chooses the card with integer $$$5$$$ and plays it.  Bob can choose any of his cards with number greater than $$$5$$$. He chooses a card with integer $$$6$$$ and plays it.  Alice can choose any of her cards with number greater than $$$6$$$. She chooses the card with integer $$$10$$$ and plays it.  Bob can choose any of his cards with number greater than $$$10$$$. He chooses a card with integer $$$11$$$ and plays it.  Alice can choose any of her cards with number greater than $$$11$$$, but she has no such cards, so she loses. Both Alice and Bob play optimally (if a player is able to win the game no matter how the other player plays, the former player will definitely win the game).You have to answer two questions:  who wins if Alice is the first player?  who wins if Bob is the first player?

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of four lines. The first line of a test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the number of cards Alice has. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 50$$$) — the numbers written on the cards that Alice has. The third line contains one integer $$$m$$$ ($$$1 \le m \le 50$$$) — the number of Bob's cards. The fourth line contains $$$m$$$ integers $$$b_1, b_2, \dots, b_m$$$ ($$$1 \le b_i \le 50$$$) — the numbers on Bob's cards.

For each test case, print two lines. The first line should be Alice if Alice wins when she is the first player; otherwise, the first line should be Bob. The second line should contain the name of the winner if Bob is the first player, in the same format.

NoteLet's consider the first test case of the example.Alice has one card with integer $$$6$$$, Bob has two cards with numbers $$$[6, 8]$$$.If Alice is the first player, she has to play the card with number $$$6$$$. Bob then has to play the card with number $$$8$$$. Alice has no cards left, so she loses.If Bob is the first player, then no matter which of his cards he chooses on the first turn, Alice won't be able to play her card on the second turn, so she will lose.

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

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

}


Let's define $$$f(x)$$$ for a positive integer $$$x$$$ as the length of the base-10 representation of $$$x$$$ without leading zeros. I like to call it a digital logarithm. Similar to a digital root, if you are familiar with that.You are given two arrays $$$a$$$ and $$$b$$$, each containing $$$n$$$ positive integers. In one operation, you do the following:   pick some integer $$$i$$$ from $$$1$$$ to $$$n$$$;  assign either $$$f(a_i)$$$ to $$$a_i$$$ or $$$f(b_i)$$$ to $$$b_i$$$. Two arrays are considered similar to each other if you can rearrange the elements in both of them, so that they are equal (e. g. $$$a_i = b_i$$$ for all $$$i$$$ from $$$1$$$ to $$$n$$$).What's the smallest number of operations required to make $$$a$$$ and $$$b$$$ similar to each other?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The first line of the testcase contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in each of the arrays. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i < 10^9$$$). The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_j < 10^9$$$). The sum of $$$n$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.

For each testcase, print the smallest number of operations required to make $$$a$$$ and $$$b$$$ similar to each other.

NoteIn the first testcase, you can apply the digital logarithm to $$$b_1$$$ twice.In the second testcase, the arrays are already similar to each other.In the third testcase, you can first apply the digital logarithm to $$$a_1$$$, then to $$$b_2$$$.

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

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

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


Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi and yi > yi + 1. We shall call a vertex of a polyline with an even x coordinate a mountain peak.   The figure to the left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k = 2.  Bolek fancied a little mischief. He chose exactly k mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the y coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, r1), (2, r2), ..., (2n + 1, r2n + 1).Given Bolek's final picture, restore the initial one.

The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integers r1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture. It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks.

Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them.

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


You are given $$$n$$$ points with integer coordinates on a coordinate axis $$$OX$$$. The coordinate of the $$$i$$$-th point is $$$x_i$$$. All points' coordinates are distinct and given in strictly increasing order.For each point $$$i$$$, you can do the following operation no more than once: take this point and move it by $$$1$$$ to the left or to the right (i..e., you can change its coordinate $$$x_i$$$ to $$$x_i - 1$$$ or to $$$x_i + 1$$$). In other words, for each point, you choose (separately) its new coordinate. For the $$$i$$$-th point, it can be either $$$x_i - 1$$$, $$$x_i$$$ or $$$x_i + 1$$$.Your task is to determine if you can move some points as described above in such a way that the new set of points forms a consecutive segment of integers, i. e. for some integer $$$l$$$ the coordinates of points should be equal to $$$l, l + 1, \ldots, l + n - 1$$$.Note that the resulting points should have distinct coordinates.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of points in the set $$$x$$$. The second line of the test case contains $$$n$$$ integers $$$x_1 < x_2 < \ldots < x_n$$$ ($$$1 \le x_i \le 10^6$$$), where $$$x_i$$$ is the coordinate of the $$$i$$$-th point. It is guaranteed that the points are given in strictly increasing order (this also means that all coordinates are distinct). It is also guaranteed that the sum of $$$n$$$ does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).

For each test case, print the answer — if the set of points from the test case can be moved to form a consecutive segment of integers, print YES, otherwise print NO.

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

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

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


God's Blessing on This PermutationForces!A Random PebbleYou are given a permutation $$$p_1,p_2,\ldots,p_n$$$ of length $$$n$$$ and a positive integer $$$k \le n$$$. In one operation you can choose two indices $$$i$$$ and $$$j$$$ ($$$1 \le i < j \le n$$$) and swap $$$p_i$$$ with $$$p_j$$$.Find the minimum number of operations needed to make the sum $$$p_1 + p_2 + \ldots + p_k$$$ as small as possible.A permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 100$$$). The second line of each test case contains $$$n$$$ integers $$$p_1,p_2,\ldots,p_n$$$ ($$$1 \le p_i \le n$$$). It is guaranteed that the given numbers form a permutation of length $$$n$$$.

For each test case print one integer — the minimum number of operations needed to make the sum $$$p_1 + p_2 + \ldots + p_k$$$ as small as possible.

NoteIn the first test case, the value of $$$p_1 + p_2 + \ldots + p_k$$$ is initially equal to $$$2$$$, but the smallest possible value is $$$1$$$. You can achieve it by swapping $$$p_1$$$ with $$$p_3$$$, resulting in the permutation $$$[1, 3, 2]$$$.In the second test case, the sum is already as small as possible, so the answer is $$$0$$$.

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

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

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