;(function () {

    print(function () {
        readline();
        var a = readline().split(' ').map(Number),
            b = readline().split(' ').map(Number),
            n = a.length, m = b.length, i = 0, j = 0, q = 0;

        while (i < n && j < m) {
            if (a[i] <= b[j]) {
                q++; i++;
            }
            j++;
        }

        return n - q;
    }());

}.call(this));

var l=readline().split(' ');
var n=+l[0];
var m=+l[1];
var a=readline().split(' ').map(function(v){return +v;});
var b=readline().split(' ').map(function(v){return +v;});

a.sort(function(a,b){return a-b})
b.sort(function(a,b){return a-b})

var i=0,j=0;
var ans=0;
while(i<n&&j<m){
	if(a[i]<=b[j]){
		i++;
		j++;
		ans++;
	}else{
		j++;
	}
}
print(a.length-ans);

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main()
function main() {
  const input = readline().split(' ').map(Number)
  const [goodRoundProblems, preparedProblems] = input
  const goodComplexities = readline().split(' ').map(Number)
  const preparedComplexities = readline().split(' ').map(Number)
  helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities)
}

function helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities) {
    let cnt = 0
    let j = 0
    for (let i = 0; i < goodRoundProblems; i++) {
        while (j < preparedProblems) {
            if (preparedComplexities[j] >= goodComplexities[i]) {
                cnt++
                i++
            }
            j++
        }
    }

    console.log(Math.max(0, goodRoundProblems - cnt))
}

'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 printResult(x) {
    process.stdout.write(x);
}

function main() {
    const nm = readLine().split(' ').map(Number);
    const requirements = readLine().split(' ').map(Number);
    const complexities = readLine().split(' ').map(Number);

    const n = nm[0];
    const m = nm[1];

    // console.log(nm, requirements, complexities)
    const result = georgeAndRound2(n, m, requirements, complexities);
    printResult(result.toString());
}

const georgeAndRound = (n, m, a, b) => {
    let appearance = 0;
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            if (b[j] >= a[i]) {
                appearance++;
                i++;
            }
        }
    }

    return Math.max(0, n - appearance);
};

const georgeAndRound2 = (n, m, a, b) => {
    let appearance = 0;
    let j = 0;
    for (let i = 0; i < n; i++) {
        while(j < m) {
            if (b[j] >= a[i]) {
                appearance++;
                i++;
            }
            j++;
        }
    }

    return Math.max(0, n - appearance);
};

var line = readline().split(" ");
var n = parseInt(line[0]);
var m = parseInt(line[1]);

var complexes = readline().split(" ").map(function(x) { return parseInt(x); });
var problems  = readline().split(" ").map(function(x) { return parseInt(x); });

var result = 0;
for (var i = 0; i < complexes.length; i++) {
  var found = false;
  var foundBigger = false;
  var whichBigger = -1;

  for (var u = 0; u < problems.length; u++) {
    if (problems[u] == -1) continue;

    if (problems[u] > complexes[i]) {
      foundBigger = true;
      whichBigger = u;
      break;
    } else if (complexes[i] == problems[u]) {
      found = true;
      break;
    }
  }

  if (!found && foundBigger) {
    problems[whichBigger] = -1;
  }

  if (!foundBigger && !found) {
    result++;
  }
}

print(result);

function main() {
    var line = readline().split(' ').map(Number);
    var n = line[0];
    var m = line[1];

    var a =  readline().split(' ').map(Number);
    var b =  readline().split(' ').map(Number);
    a.sort((a,b) => b- a);
    b.sort((a,b) => a-b);
    var used = [];
    var res = 0;
    for(var i=0;i<a.length;i++){
        var found = false;
        for(var j=0;j<b.length;j++){
            if(used[j]){
                continue;
            }
            if(b[j] >= a[i]){
                found = true;
                used[j] = true;
                break;
            }
        }
        if(!found){
            res++;
        }
    }
    print(res)
}

main()

// Make a Snippet for the code above this and then write your logic in main()
function main() {
  const input = readline().split(' ').map(Number)
  const [goodRoundProblems, preparedProblems] = input
  const goodComplexities = readline().split(' ').map(Number)
  const preparedComplexities = readline().split(' ').map(Number)
  helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities)
}

function helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities) {
  let cnt = 0
  let j = 0
  for (let i = 0; i < goodRoundProblems; i++) {
    const goodComplexity = goodRoundProblems[i]
    while (goodComplexity > preparedComplexities[j]){
      j++
    }
    if (j === preparedProblems - 1) {
      console.log((goodRoundProblems - i - 1) + '')
      return
    }
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main()
function main() {
  const input = readline().split(' ').map(Number)
  const [goodRoundProblems, preparedProblems] = input
  const goodComplexities = readline().split(' ').map(Number)
  const preparedComplexities = readline().split(' ').map(Number)
  helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities)
}

function helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities) {
  let cnt = new Map()
  for (let i = 0; i < goodRoundProblems; i++) {
    cnt.set(goodComplexities[i], (cnt.get(goodComplexities[i]) || 0) + 1)
  }

  for (let i = 0; i < preparedProblems; i++) {
    const complexity = preparedComplexities[i]
    if (cnt.has(complexity)) {
      cnt.set(complexity, cnt.get(complexity) - 1)
      if (cnt.get(complexity) === 0) {
        cnt.delete(complexity)
      }
    }
  }

  let missed = 0
  for (let value of cnt.values()) {
    missed += value
  }

  console.log(missed)
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main()
function main() {
  const input = readline().split(' ').map(Number)
  const [goodRoundProblems, preparedProblems] = input
  const goodComplexities = readline().split(' ').map(Number)
  const preparedComplexities = readline().split(' ').map(Number)
  helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities)
}

function helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities) {
    let cnt = 0
    let j = 0
    for (let i = 0; i < goodRoundProblems; i++) {
        const goodComplexity = goodComplexities[i]
        if (preparedComplexities[j] >= goodComplexity) {
            j++
            cnt++
        } else {
            while (preparedComplexities[j] && preparedComplexities[j] < goodComplexity) {
                j++
            }
            if (preparedComplexities[j] && preparedComplexities[j] >= goodComplexity)
                cnt++
        }
        if (j === preparedProblems - 1) {
            console.log(goodRoundProblems - cnt - 1)
            return
        }
    }

    console.log(goodRoundProblems - cnt)
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main()
function main() {
  const input = readline().split(' ').map(Number)
  const [goodRoundProblems, preparedProblems] = input
  const goodComplexities = readline().split(' ').map(Number)
  const preparedComplexities = readline().split(' ').map(Number)
  helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities)
}

function helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities) {
    let cnt = 0
    let j = 0
    for (let i = 0; i < goodRoundProblems; i++) {
        const goodComplexity = goodComplexities[i]
        if (preparedComplexities[j] >= goodComplexity) {
            j++
            cnt++
        } else {
            while (preparedComplexities[j] && preparedComplexities[j] < goodComplexity) {
                j++
            }
            if (preparedComplexities[j] && preparedComplexities[j] >= goodComplexity)
                cnt++
        }
        if (cnt === goodRoundProblems - 1) {
           console.log(0)
           return
        }

        if (j >= preparedProblems - 1) {
            console.log(goodRoundProblems - cnt)
            return
        }
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main()
function main() {
  const input = readline().split(' ').map(Number)
  const [goodRoundProblems, preparedProblems] = input
  const goodComplexities = readline().split(' ').map(Number)
  const preparedComplexities = readline().split(' ').map(Number)
  helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities)
}

function helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities) {
    let cnt = 0
    let j = 0
    for (let i = 0; i < goodRoundProblems; i++) {
        const goodComplexity = goodComplexities[i]
        if (preparedComplexities[j] >= goodComplexity) {
            j++
            cnt++
        } else {
            while (preparedComplexities[j] && preparedComplexities[j] < goodComplexity) {
                j++
            }
            if (preparedComplexities[j] && preparedComplexities[j] >= goodComplexity)
                cnt++
        }
        if (j === preparedProblems) {
            break
        }
    }

    console.log(goodRoundProblems - cnt)
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main()
function main() {
  const input = readline().split(' ').map(Number)
  const [goodRoundProblems, preparedProblems] = input
  const goodComplexities = readline().split(' ').map(Number)
  const preparedComplexities = readline().split(' ').map(Number)
  helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities)
}

function helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities) {
    let cnt = 0
    let j = 0
    for (let i = 0; i < goodRoundProblems; i++) {
        const goodComplexity = goodComplexities[i]
        if (preparedComplexities[j] >= goodComplexity) {
            j++
            cnt++
        } else {
            while (preparedComplexities[j] && preparedComplexities[j] < goodComplexity) {
                j++
            }
            if (j < preparedProblems)
                cnt++
        }
        if (j === preparedProblems) {
            break;
        }
    }

    console.log(goodRoundProblems - cnt)
}

// Make a Snippet for the code above this and then write your logic in main()
function main() {
  const input = readline().split(' ').map(Number)
  const [goodRoundProblems, preparedProblems] = input
  const goodComplexities = readline().split(' ').map(Number)
  const preparedComplexities = readline().split(' ').map(Number)
  helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities)
}

function helper(goodRoundProblems, preparedProblems, goodComplexities, preparedComplexities) {
  let cnt = 0
  let j = 0
  for (let i = 0; i < goodRoundProblems; i++) {
    const goodComplexity = goodRoundProblems[i]
    while (goodComplexity > preparedComplexities[j]){
      j++
    }
    if (j === preparedProblems - 1) {
      console.log(goodRoundProblems - i - 1)
      return
    }
  }
}

'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 printResult(x) {
    process.stdout.write(x);
}

function main() {
    const nm = readLine().split(' ').map(Number);
    const requirements = `0 ${readLine()}`.split(' ').map(Number);
    const complexities = `0 ${readLine()}`.split(' ').map(Number);

    const n = nm[0];
    const m = nm[1];

    // console.log(nm, requirements, complexities)
    const result = georgeAndRound(n, m, requirements, complexities);
    printResult(result.toString());
}

const georgeAndRound = (n, m, a, b) => {
    const counts = new Array(Math.pow(10, 6) + 1);
    for (let i = 1; i <= m; i++) counts[b[i]] = 1;
    let appearance = 0;
    for (let i = 1; i <= n; i++) {
        if (counts[a[i]]) appearance++;
    }

    return n - appearance;
};

'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 printResult(x) {
    process.stdout.write(x);
}

function main() {
    const nm = readLine().split(' ').map(Number);
    const requirements = readLine().split(' ').map(Number);
    const complexities = readLine().split(' ').map(Number);

    const n = nm[0];
    const m = nm[1];

    // console.log(nm, requirements, complexities)
    const result = georgeAndRound(n, m, requirements, complexities);
    printResult(result.toString());
}

const georgeAndRound = (n, m, a, b) => {
    const counts = new Array(Math.pow(10, 6) + 1);
    for (let i = 0; i < m; i++) {
        counts[b[i]] = 1;
    }
    let appearance = 0;
    for (let i = 0; i < n; i++) {
        if (counts[a[i]]) appearance++;
    }

    return n - appearance;
};

'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 printResult(x) {
    process.stdout.write(x);
}

function main() {
    const nm = readLine().split(' ').map(Number);
    const requirements = readLine().split(' ').map(Number);
    const complexities = readLine().split(' ').map(Number);

    const n = nm[0];
    const m = nm[1];

    // console.log(nm, requirements, complexities)
    const result = georgeAndRound(n, m, requirements, complexities);
    printResult(result.toString());
}

const georgeAndRound = (n, m, a, b) => {
    let appearance = 0;
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            if (b[j] >= a[i]) {
                appearance++;
                i++;
            }
        }
    }

    return Math.max(0, n - appearance);
};

var l=readline().split(' ');
var n=+l[0];
var m=+l[1];
var a=readline().split(' ').map(function(v){return +v;});
var b=readline().split(' ').map(function(v){return +v;});

var map={};
b.forEach(function(v){
	map[v]=true;
});

var ans=0;
a.forEach(function(v){
	if(!map[v]){
		ans++;
	}
});
print(ans);

var l=readline().split(' ');
var n=+l[0];
var m=+l[1];
var a=readline().split(' ').map(function(v){return +v;});
var b=readline().split(' ').map(function(v){return +v;});

var map={};
b.forEach(function(v){
	map[v]=true;
});

var ans=0;
a.forEach(function(v){
	if(!ans[v]){
		ans++;
	}
});
print(ans);

;(function () {

    print(function () {
        var n = readline().split(' ').map(Number),
            m = n[1],
            a = readline().split(' ').map(Number),
            b = readline().split(' ').map(Number),
            r = Math.min(n[0], m),
            t = 0;
        n = n[0];

        for (var i = 0; i < r; i++) {
            if (b[m - i - 1] < a[n - i - 1]) t++;
        }

        return t + n - i;
    }());

}.call(this));

;(function () {

    print(function () {
        var n = readline().split(' ').map(Number),
            m = n[1],
            a = readline().split(' ').map(Number),
            b = readline().split(' ').map(Number),
            r = 0,
            t = 0;
        n = n[0];

        for (var i = 0; i < a.length; i++) {
            t = b.indexOf(a[i]);
            if (t !== -1) {
                b.splice(t, 1);
                a.splice(i, 1);
                i--;
            }
        }

        if (a.length === 0) return 0;
        n = a.length;
        m = b.length;
        t = 0;
        r = Math.min(n, m)

        for (var i = 0; i < r; i++) {
            if (b[m - i - 1] < a[n - i - 1]) t++;
        }

        return t + n - i;
    }());

}.call(this));

;(function () {

	print(function (n, m) {
		var a = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }),
			b = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }),
			k = 0;

		for (var i = 0, j = 0; i < n; i++) {
			if (b[j]) {
				if (b[j] >= a[j]) j++;
				else {
					var t = b.indexOf(a[j]);
					if (t === -1) k++;
					else j = t + 1;
				};
			} else k ++;
		}

		return k;
	}.apply(null, readline().split(' ').map(Number)));

}.call(this));

;(function () {

    print(function () {
        var n = readline().split(' ').map(Number),
            m = n[1],
            a = readline().split(' ').map(Number),
            b = readline().split(' ').map(Number);
        n = n[0];

        for (var i = 0; i < a.length; i++) {
            var t = b.indexOf(a[i]);
            if (t !== -1) {
                b.splice(t, 1);
                a.splice(i, 1);
                i--;
            }
        }

        if (a.length === 0) return 0;
        n = a.length;
        m = b.length;

        for (var i = a.length; i > -1; i--) {
            var r = a[i],
                m = Math.max(b);

            if (m > r) {
                a.splice(i, 1);
                var t = b.indexOf(m);
                b.splice(t, 1);
                i++;
            }
        }

        if (a.length === 0) return 0;
        return a.length;
    }());

}.call(this));

;(function () {

    print(function () {
        var n = readline().split(' ').map(Number),
            m = n[1],
            a = readline().split(' ').map(Number),
            b = readline().split(' ').map(Number),
            r = 0,
            t = 0;
        n = n[0];

        for (var i = 0; i < a.length; i++) {
            t = b.indexOf(a[i]);
            if (t !== -1) {
                b.splice(t, 1);
                a.splice(i, 1);
                i--;
            }
        }

        if (a.length === 0) return 0;
        n = a.length;
        m = b.length;
        t = 0;
        r = Math.min(n, m)

        for (var i = 0; i < r; i++) {
            if (b[i] < a[i]) t++;
        }

        return t + n - i;
    }());

}.call(this));

var line = readline().split(" ");
var n = parseInt(line[0]);
var m = parseInt(line[1]);

var complexes = readline().split(" ").map(function(x) { return parseInt(x); });
var problems  = readline().split(" ").map(function(x) { return parseInt(x); });

var result = 0;
for (var i = 0; i < complexes.length; i++) {
  var found = false;
  var foundBigger = false;

  for (var u = 0; u < problems.length; u++) {
    if (problems[u] > complexes[i] && complexes[i] > 0) {
      foundBigger = true;
      break;
    } else if (complexes[i] == problems[u]) {
      found = true;
      break;
    }
  }

  if (!found && !foundBigger) {
    result++;
  }
}

print(result);

var line = readline().split(" ");
var n = parseInt(line[0]);
var m = parseInt(line[1]);

var complexes = readline().split(" ").map(function(x) { return parseInt(x); });
var problems  = readline().split(" ").map(function(x) { return parseInt(x); });

var result = 0;
for (var i = 0; i < complexes.length; i++) {
  var found = false;
  var foundBigger = false;

  for (var u = 0; u < problems.length; u++) {
    if (problems[u] > complexes[i]) {
      foundBigger = true;
    } else if (complexes[i] == problems[u]) {
      found = true;
      break;
    }
  }

  if (!found && !foundBigger) {
    result++;
  }
}

print(result);

function main() {
    var line = readline().split(' ').map(Number);
    var n = line[0];
    var m = line[1];

    var a =  readline().split(' ').map(Number);
    var b =  readline().split(' ').map(Number);
    a.sort((a,b) => b- a);
    b.sort((a,b) => a-b);
    var used = [];
    var res = 0;
    for(var i=0;i<a.length;i++){
        var found = false;
        for(var j=0;j<b.length;j++){
            if(used[j]){
                continue;
            }
            if(b[j] >= a[i]){
                found = true;
                used[j] = true;
            }
        }
        if(!found){
            res++;
        }
    }
    print(res)
}

main()


const readline = require('readline');

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

rl.on('line', (input) => {
    if (q === null) {
        q = +input;
    } else {
        solve(input.split(' ').map(number => +number));
        readedLines++;
    }

    if (q === readedLines) {
        rl.close();
    }
});

let q = null;
let readedLines = 0;

const solve = numbers => {
    numbers.sort((a, b) => a - b);

    if (numbers[0] !== numbers[2]) {
        if (numbers[0] === numbers[1]) {
            numbers[0]++;
            numbers[1]++;

            if (numbers[0] !== numbers[2]) numbers[2]--;
        } else if (numbers[2] === numbers[1]) {
            numbers[2]--;
            numbers[1]--;

            if (numbers[2] !== numbers[0]) numbers[0]++;
        } else {
            numbers[0]++;
            numbers[2]--;
        }
    }

    console.log(
        (numbers[1] - numbers[0]) + (numbers[2] - numbers[1]) + (numbers[2] - numbers[0])
    );
};

'use strict'

const dist = (a, b, c) => Math.abs(a-b) + Math.abs(a-c) + Math.abs(b-c);

const problem = (a, b, c) => {
    let r = Infinity;
    for (let i = -1; i < 2; i++) {
        const A = a + i;
        for (let j = -1; j < 2; j++) {
            const B = b + j;
            for (let k = -1; k < 2; k++) {
                const C = c + k;
                r = Math.min(r, dist(A,B,C));
            }
        }
    }
    return r;
}
let q = +readline();

while(q--) {
    const abc = readline().split(' ').map(i => +i);
    print(problem(abc[0], abc[1], abc[2]));
}

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

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

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

  const t = parseInt(arr.shift())

  for(let i = 0; i < t; i++) {
    const arrN = arr[i].split(' ').map(a => parseInt(a))
    arrN.sort((a, b) => a - b)

    let a = arrN[0]
    let b = arrN[1]
    let c = arrN[2]
    if(a != b && b == c) {
      b--
      c--
      a++
      if(a > b) a--
    }
    else if(c != b && b == a) {
      b++
      c--
      a++
      if(c < a) c++
    }
    else if(a != b && b != c) {
      a++
      c--
    }

    // console.log(a, b, c)

    console.log(Math.abs(a - b) + Math.abs(a - c) + Math.abs(c - b))
  }
})

var toInt = x => parseInt(x);
var n = parseInt(readline());
var check = (a, b, c) => (Math.abs(a-b)+Math.abs(b-c)+Math.abs(a-c));
var ar = new Array(n).fill('').map(readline).map(l=>l.split(' ').map(toInt));
ar.forEach(a => {
    var best = Number.MAX_SAFE_INTEGER;
    for(var i=-1; i<=1;i++) {
        for(var j=-1; j<=1;j++) {
            for(var k=-1; k<=1;k++) {
                best = Math.min(best, check(a[0]+i, a[1]+j, a[2]+k));
            }
        }
    }
    print(best);

})

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL);

    function foo (data) {
        data.sort((a,b) => a - b);
        let [a, b, c] = data;
        if (a < b && b < c) {
            a++;
            c--;
        } else if (a === b) {
            if (b < c) c--;
            if (b < c) c--;
        } else if (b === c) {
            if (a < b) a++;
            if (a < b) a++;
        }
        return b - a + c - a + c - b;
    }

    let testCount = 1;
    let answer = '';
    while(testCount <= +lines[0]) {
        let data = lines[testCount].split(" ").map(Number);

        let result = foo(data);
        answer += result +"\n";
        testCount++;
    }
    console.log(answer);
})

function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){print(t);}//standard output
//function myout(t){console.log(t);}//standard output
function myerr(t){console.err(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main() {
  //input = myconv(input,3);
  var N = myconv(readline(),1);
  var output = [];
  for(var i = 0; i < N; i++){
    var tmp = myconv(readline(),4).sort(function(a,b){return myconv(a,1)-myconv(b,1);});
    var a = tmp[0];
    var b = tmp[1];
    var c = tmp[2];
    var da = a+1;
    var dc = c-1;

    if(c-a > 2){
      if(b == c){
         b = dc;
         }else{
         b = da;
         }
       output.push(Math.abs(da-b)+Math.abs(da-dc)+Math.abs(dc-b));
    }else{
       output.push(0);
    }
  }
  myout(output.join("\n"));
}

Main();

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

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

  const arr = d.split(' ').map(Number);
  const max = Math.max(...arr);

  for (let i = 0; i < arr.length; i++) {
    if (arr[i] < max) {
      arr[i]++;
    }
  }

  const min = Math.min(...arr);
  for (let i = 0; i < arr.length; i++) {
    if (arr[i] > min) {
      arr[i]--;
    }
  }

  const ans = Math.abs(arr[0] - arr[1]) + Math.abs(arr[0] - arr[2]) + Math.abs(arr[1] - arr[2]);

  console.log(ans);

  count++;
});

process.stdin.setEncoding('utf-8').on('data', input => {
    const dist = (a, b, c) => Math.abs(a - b) + Math.abs(a - c) + Math.abs(b - c);
    input.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)
        .forEach(line => {
            const [a, b, c] = line.split(' ').map(Number);
            let minDist = dist(a, b, c);
            for (let i = -1; i <= 1; i++) {
                for (let j = -1; j <= 1; j++) {
                    for (let l = -1; l <= 1; l++) {
                        minDist = Math.min(minDist, dist(a + i, b + j, c + l));
                    }
                }
            }
            console.log(minDist);
        });
});

let fs = require("fs");

let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0;
});

txt.shift();

for (let i = 0; i < txt.length; i++) {
    let info = txt[i].split(" ").filter(data => {
        return data.length > 0;
    }).map(data => {
        return data * 1;
    });
    doit(info);

}

function doit(tab) {
    let mid = Math.round((tab[0] + tab[1] + tab[2]) / 3);
    for (let i = 0; i < tab.length; i++) {
        if (tab[i] < mid) {
            ++tab[i];
        } else if (tab[i] > mid) {
            --tab[i];
        }
    }
    console.log(Math.abs(tab[0] - tab[1]) + Math.abs(tab[0] - tab[2]) + Math.abs(tab[2] - tab[1]));
}

const readline = require('readline');

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

rl.on('line', (input) => {
    if (q === null) {
        q = +input;
    } else {
        solve(input.split(' ').map(number => +number));
        readedLines++;
    }

    if (q === readedLines) {
        rl.close();
    }
});

let q = null;
let readedLines = 0;

const solve = numbers => {
    numbers.sort();

    if (numbers[0] !== numbers[2]) {
        if (numbers[0] === numbers[1]) {
            numbers[0]++;
            numbers[1]++;

            // if (numbers[0] !== numbers[2]) numbers[2]--;
        } else if (numbers[2] === numbers[1]) {
            numbers[2]--;
            numbers[1]--;

            if (numbers[2] !== numbers[0]) numbers[0]++;
        } else {
            numbers[0]++;
            numbers[2]--;
        }
    }

    console.log(
        (numbers[1] - numbers[0]) + (numbers[2] - numbers[1]) + (numbers[2] - numbers[0])
    );
};

const readline = require('readline');

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

rl.on('line', (input) => {
    if (q === null) {
        q = +input;
    } else {
        solve(input.split(' ').map(number => +number));
        readedLines++;
    }

    if (q === readedLines) {
        rl.close();
    }
});

let q = null;
let readedLines = 0;

const solve = numbers => {
    numbers.sort();

    if (numbers[0] !== numbers[2]) {
        if (numbers[0] === numbers[1]) {
            numbers[0]++;
            numbers[1]++;

            // if (numbers[0] !== numbers[2]) numbers[2]--;
        } else if (numbers[2] === numbers[1]) {
            numbers[2]--;
            numbers[1]--;

            // if (numbers[2] !== numbers[0]) numbers[0]++;
        } else {
            numbers[0]++;
            numbers[2]--;
        }
    }

    console.log(
        (numbers[1] - numbers[0]) + (numbers[2] - numbers[1]) + (numbers[2] - numbers[0])
    );
};

const readline = require('readline');

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

rl.on('line', (input) => {
    if (q === null) {
        q = +input;
    } else {
        solve(input.split(' ').map(number => +number));
        readedLines++;
    }

    if (q === readedLines) {
        rl.close();
    }
});

let q = null;
let readedLines = 0;

const solve = numbers => {
    numbers.sort();

    if (numbers[0] !== numbers[2]) {
        if (numbers[0] === numbers[1]) {
            numbers[0]++;
            numbers[1]++;

            if (numbers[0] !== numbers[2]) numbers[2]--;
        } else if (numbers[2] === numbers[1]) {
            numbers[2]--;
            numbers[1]--;

            if (numbers[2] !== numbers[0]) numbers[0]++;
        } else {
            numbers[0]++;
            numbers[2]--;
        }
    }

    console.log(
        (numbers[1] - numbers[0]) + (numbers[2] - numbers[1]) + (numbers[2] - numbers[0])
    );
};

const readline = require('readline');

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

rl.on('line', (input) => {
    if (q === null) {
        q = +input;
    } else {
        solve(input.split(' ').map(number => +number));
        readedLines++;
    }

    if (q === readedLines) {
        rl.close();
    }
});

let q = null;
let readedLines = 0;

const solve = numbers => {
    numbers.sort();

    if (numbers[0] !== numbers[2]) {
        if (numbers[0] === numbers[1]) {
            numbers[2]--;
        } else if (numbers[2] === numbers[1]) {
            numbers[0]++;
        } else {
            numbers[0]++;
            numbers[2]--;
        }
    }

    console.log(
        (numbers[1] - numbers[0]) + (numbers[2] - numbers[1]) + (numbers[2] - numbers[0])
    );
};

const readline = require('readline');

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

rl.on('line', (input) => {
    if (q === null) {
        q = +input;
    } else {
        solve(input.split(' ').map(number => +number));
        readedLines++;
    }

    if (q === readedLines) {
        rl.close();
    }
});

let q = null;
let readedLines = 0;

const solve = numbers => {
    numbers.sort();

    if (numbers[0] < numbers[1]) ++numbers[0];

    if (numbers[2] > numbers[1]) --numbers[2];

    console.log(
        (numbers[1] - numbers[0]) + (numbers[2] - numbers[1]) + (numbers[2] - numbers[0])
    );
};

const readline = require('readline');

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

rl.on('line', (input) => {
    if (q === null) {
        q = +input;
    } else {
        solve(input.split(' ').map(number => +number));
        readedLines++;
    }

    if (q === readedLines) {
        rl.close();
    }
});

let q = null;
let readedLines = 0;

const solve = numbers => {
    numbers.sort();

    if (numbers[0] !== numbers[2]) {
        if (numbers[0] === numbers[1]) {
            numbers[0]++;
            numbers[1]++;

            // if (numbers[0] !== numbers[2]) numbers[2]--;
        } else if (numbers[2] === numbers[1]) {
            numbers[2]--;
            numbers[1]--;

            if (numbers[2] !== numbers[0]) numbers[0]++;
        } else {
            numbers[0]++;
            numbers[2]--;
        }
    }

    console.log(numbers);

    console.log(
        (numbers[1] - numbers[0]) + (numbers[2] - numbers[1]) + (numbers[2] - numbers[0])
    );
};

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

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

  const arr = d.split(' ').map(Number);
  arr.sort((a, b) => a - b);

  if (arr[0] < arr[1]) {
    arr[0]++;
  }
  if (arr[2] >= arr[1]) {
    arr[2]--;
  }

  const ans = Math.max(0, (arr[2] - arr[1]) + (arr[2] - arr[0]) + (arr[1] - arr[0]));
  console.log(ans);

  c++;
});

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

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

  const arr = d.split(' ').map(Number);
  arr.sort((a, b) => a - b);

  if (arr[0] < arr[1]) {
    arr[0]++;
  }
  if (arr[2] >= arr[1]) {
    arr[2]--;
  }

  const ans = arr[2] - arr[1] + arr[2] - arr[0] + arr[1] - arr[0];
  console.log(ans);

  c++;
});

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

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

  const arr = d.split(' ').map(Number);
  arr.sort((a, b) => a - b);

  if (arr[0] < arr[1]) {
    arr[0]++;
  }

  if (arr[2] > arr[1]) {
    arr[2]--;
  }
  else if (arr[1] !== arr[0] && arr[1] !== arr[2]) {
    arr[1]--;
  }
  else {
    if (arr[1] === arr[2] && arr[1] !== arr[0]) {
      arr[1]--;
      arr[2]--;
    }
    else if (arr[1] === arr[0] && arr[1] !== arr[2]) {
      arr[1]++;
      arr[0]++;
    }
  }

  const ans = Math.abs(arr[0] - arr[1]) + Math.abs(arr[0] - arr[2]) + Math.abs(arr[1] - arr[2]);

  console.log(ans);

  count++;
});

let fs = require("fs");

let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0;
});

txt.shift();

for (let i = 0; i < txt.length; i++) {
    let info = txt[i].split(" ").filter(data => {
        return data.length > 0;
    }).map(data => {
        return data * 1;
    });
    doit(info);

}

function doit(tab) {
    let mid = Math.floor((tab[0] + tab[1] + tab[2]) / 3);
    for (let i = 0; i < tab.length; i++) {
        if (tab[i] < mid) {
            ++tab[i];
        } else if (tab[i] > mid) {
            --tab[i];
        }
    }
    console.log(Math.abs(tab[0] - tab[1]) + Math.abs(tab[0] - tab[2]) + Math.abs(tab[2] - tab[1]));
}


var n, k, s, cnt, ans;
var token = [];

var i;

token = readline().split(' ');

n = parseInt(token[0]);
k = parseInt(token[1]);

s = readline();

cnt = new Array(k);
for(i=0;i<k;i++) {
  cnt[i] = 0;
}

for(i=0;i<n;i++) {
  ++cnt[s.charCodeAt(i)-"A".charCodeAt()];
}

ans = cnt[0];
for(i=1;i<k;i++) {
  ans = Math.min(ans, cnt[i]);
}

ans*=k;

print(ans);

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

//Don't have to see. end------------------------------------------
function Main(){
	var one = nextIntArray();
	var N = one[0];
	var K = one[1];
	var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var map = {};
	for(var i = 0; i < K; i++){
		map[alpha[i]] = 0;
	}
	var list = next();
	for(var i = 0; i < N; i++){
		map[list[i]]++;
	}
	var min = N;
	var keys = Object.keys(map);
	for(var i = 0; i < keys.length; i++){
		min = Math.min(min, map[keys[i]]);
	}
	myout(min * K);
}

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

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    [n, k] = d.split(' ').map(Number);
    return;
  }

  const str = d;
  const frequence = {};

  for (let i = 0; i < str.length; i++) {
    if (frequence[str[i]]) {
      frequence[str[i]]++;
    }
    else {
      frequence[str[i]] = 1;
    }
  }

  const values = Object.values(frequence);

  if (values.length !== k) {
    console.log(0);
  }
  else {
    const min = Math.min(...values);
    console.log(k*min);
  }

  c++;
});

var ip = readline().split(' ').map(Number);
var n = ip[0], k = ip[1];
var ar = new Array(26);
for (i=0;i<26;i++){
    ar[i] = 0;
}
var min = 1000000;
readline().split('').forEach(x=>ar[x.charCodeAt()-65]++);
for (i = 0;i<k;i++){
    min = Math.min(min,ar[i]);
}
print(min*k)

var numbers = readline().split(" ");
var str = readline().split("");
var s = numbers[0];
var k = numbers[1];

var arr  = [];
for (var i = 0; i < s; i++) {
    // if (str[i].charCodeAt(0)>64+k) {
    //     write("0");
    // }
    var index = arr.findIndex(function(el) {return el.char == str[i]});
    if (index == -1)
        arr.push({char:str[i], number: 1});
    else {
        arr[index].number++;
    }
}
if (arr.length != k)
    print(0);
else
    print(getMinOfArray(arr.map(function(el) {return el.number}))*k);

function getMinOfArray(numArray) {
    return Math.min.apply(null, numArray);
}

var alphapet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
    'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
];

var arr = readline().split(" ").map((elem) => {
    return parseInt(elem);
});
var str = readline();

var n = arr[0],
    k = arr[1];

var arrTmp = alphapet.splice(0, k);
flag = true;

arrTmp.forEach((elem) => {
    if (str.split("").find((x) => {
            return x === elem;
        })) {
        flag = true;
    } else {
        flag = false;
    }
})
if (!flag) {
    print(0);
} else {
    var counterArray = [];
    for(i=0;i<k;i++){
        counterArray[i]=0;
    }

    i=-1,el='';
    strSplitted = str.split("");
    strSplitted.sort();

    strSplitted.forEach((elem)=>{
        if(el !== elem){
            el = elem;
            i++;
        }
        counterArray[i]++;
    })
    mn = Math.min(...counterArray);
    print(k*mn);

}

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

//Don't have to see. end------------------------------------------
function Main(){
	var one = nextIntArray();
	var N = one[0];
	var K = one[1];
	var alpha = "ABCFEFGHIJKLMNOPQESTUVWXYZ";
	var map = {};
	for(var i = 0; i < K; i++){
		map[alpha[i]] = 0;
	}
	var list = next();
	for(var i = 0; i < N; i++){
		map[list[i]]++;
	}
	var min = N;
	var keys = Object.keys(map);
	for(var i = 0; i < keys.length; i++){
		min = Math.min(min, map[keys[i]]);
	}
	myout(min * K);
}


"use strict"

let iter = parseInt(readline());

while(iter--){
    let length = parseInt(readline());
    let input = readline().split(" ").map(x => parseInt(x));

    let current = input[0];
    let counter = 0;
    let maxCounter = 0;

    for(let i = 0; i < length; i++){
        if(input[i] === current){
            counter++;
        } else {
            current = input[i];
            counter = 1;
        }

        if(counter > maxCounter){
            maxCounter = counter;
        }
    }

    print(maxCounter);
}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var s = 0
    var e = 0
    for(j = 1; j <= n * 2; j++){
        if(j % 2 === 0){
            var a = new Map()
            var k = lines[j].split(' ').map(Number)
            for(l = 0; l < e; l++){
                if(a.has(k[l])){
                    var temp = a.get(k[l])
                    temp++
                    a.set(k[l], temp)
                }else{
                    a.set(k[l], 1)
                }
            }
            var biggestKey = ''
            var biggestValue = 0
            for(var[key, value] of a){
                if(value > biggestValue){
                    biggestValue = value
                    biggestKey=key
                }
            }
            console.log(biggestValue)
        }else{
            e = lines[j]
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0
    for(j = 1; j <= n * 2; j++){
        if(j % 2 === 0){
        var a = new Map()
        var k = lines[j].split(' ')
        for(l = 0 ;l < e; l++){
        if(a.has(k[l])){
            var temp = a.get(k[l])
            temp++
            a.set(k[l], temp)
        }else{
            a.set(k[l], 1)
        }
    }
        var biggestValue = 0
        var biggestKey = ''
            for(var [key,value] of a){
                if(biggestValue < value){
                    biggestKey = key
                    biggestValue = value
                }
            }
    console.log(biggestValue)

        }else {
            e = lines[j]
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var t = lines[0];
    var e = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var a = new Map();
            for(j = 0; j < e; j++){
                if(a.has(k[j])){
                    var te = a.get(k[j]);
                    te++;
                    a.set(k[j], te);
                }else{
                    a.set(k[j], 1);
                }
            }
            var ans = 0;
            for(var [key, value] of a){
                if(value > ans){
                    ans = value;
                }
            }
            console.log(ans);
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var t = lines[0];
    var e = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var a = new Map();
            for(j = 0; j < e; j++){
                if(a.has(k[j])){
                    var temp = a.get(k[j]);
                    temp++;
                    a.set(k[j], temp);
                }else{
                    a.set(k[j], 1);
                }
            }
            var ans = 0;
            for(var [key, value] of a){
                if(ans < value){
                    ans = value;
                }
            }
            console.log(ans);
        }
    }
});

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

let inputString = '';
let currentLine = 0;

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

function main() {
  const t = parseInt(readline(), 10);

  for (let i = 0; i < t; i += 1) {
    readline();
    const a = readline().split(' ').map(num => parseInt(num, 10));
    let number = 1;
    let max = 1;

    a.forEach((item, index) => {
      if (item === a[index + 1]) {
        number += 1;
        return;
      }

      if (number > max) {
        max = number;
      }

      number = 1;
    });

    console.log(max);
  }
}

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

process.stdin.on('end', () => {
  inputString = inputString.split('\n').map(str => str.trim());

  main();
});

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.split('\n').map(str => str.trim());

  main();
});

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

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

  while (t--) {
    readline();
    const a = readline().split(' ').map(num => parseInt(num, 10));
    const r = [];

    a.forEach(item => {
      r.push(a.filter(next => next === item).length);
    });

    console.log(Math.max(...r));
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main()
});

function readline() {
    return inputString[currentLine++]
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    let testCases = readline()
    while(testCases--)
        solve()
}

// function to solve problems
function solve (){
    let arrLength = readline()
    let n = readline().split(' ').map(x => +x)
    // let n = line[0]
    // let k = line[1]
    // let ans = 0
    // ------------------
    // count the most occurrences and it is the answer
    let myMap = new Map()
    for (let i = 0; i < n.length; i++) {
        // if (myMap.has(n[i])){
        if (myMap.has(n[i])) {
            myMap.set(n[i], myMap.get(n[i]) + 1)
            // console.log('IF myMap = ', myMap)
        }
        else {
            myMap.set(n[i], 1)
            // console.log('myMap = ', myMap)
        }
    }
    let max = 0
    // console.log(myMap.keys())
    // console.log('map entries = ', myMap.entries())
    for (const [key, value] of myMap.entries()) {
        max = (value > max) ? +value: max
    }
    console.log(max)
}

function main(lines) {
  const T = parseInt(lines[0], 10);
  for (let i = 0; i < T; i++) {
    const index = 1 + i * 2;
    const n = parseInt(lines[index], 10);
    const str = lines[index + 1];
    const arr = str.split(' ').map((item) => parseInt(item, 10));
    let j = 1;
    let max = 1;
    let currentValue = 1;
    while (j < arr.length) {
      if (arr[j] === arr[j - 1]) {
        currentValue += 1;
      } else {
        max = Math.max(max, currentValue);
        currentValue = 1;
      }
      j += 1;
    }
    max = Math.max(max, currentValue);
    console.log(max);
  }
}

let inputString = '';

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

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

  main(inputString);
});

let inputString = '';
let currentLine = 0;
process.stdin.on('data', (data) => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map((str) => str.trim());
	main();
});
function readLine() {
	return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
	for (var a = arguments, r = a[0], i = a.length; --i; )
		r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
	return r;
}
function inv(b) {
	for (var a = MOD, u = 0, v = 1, t; b; v = t)
		(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
	u %= MOD;
	return u < 0 ? u + MOD : u;
}
function pow(base, n) {
	if (n === 0) return 1;
	let p = pow(base, Math.floor(n / 2));
	let res = mul(mod(p), mod(p));
	if (n % 2 === 1) res = mul(mod(res), base);
	return res;
}
function highestOneBit(i) {
	i |= i >> 1;
	i |= i >> 2;
	i |= i >> 4;
	i |= i >> 8;
	i |= i >> 16;
	return i - (i >>> 1);
}
function permutation(arr, len, store = '', permutations = []) {
	if (store.length === len) {
		permutations.push(store);
		return;
	}
	for (let i = 0; i < arr.length; i++) {
		const newArr = [...arr];
		const newChar = newArr.splice(i, 1);
		permutation(newArr, len, store.concat(newChar), permutations);
	}
	return permutations;
}
function gcd(a, b) {
	if (b === 0) return a;
	return gcd(b, a % b);
}

function main() {
	let t = +readLine();
	while (t--) {
		const len = +readLine();
		const arr = readLine().split(' ').map(Number);
		const map = new Map();
		for (let n of arr) {
			map.set(n, (map.get(n) || 0) + 1);
		}
		const f = [...map.values()].sort((a, b) => a - b);
		console.log(f[f.length - 1]);
	}
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const x = readline();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var n = Number(readline());
        var array = readline().split(' ').map(x=>Number(x));
        var current = 0
        var number = 0
        var max = 0
        array.map((x,i)=>{
            if(i===array.length) return;
            // console.log(current, x)
            if(x === array[i+1]){
                number++
                return
            }
            if(number > max) {
                max = number
            }
            number = 0
        })
         console.log(max +1)
         // console.log(array)

    })

}

process.stdin.resume();
process.stdin.setEncoding("utf8");
let standardInputString = "";
let curLine = 0;

function readLine() {
  return standardInputString[curLine++];
}

process.stdin.on("data", rawData => {
  standardInputString += rawData;
});

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

  main();
});

// Pilot course from ITMO -> Z-function -> Step 1 -> Problem A

// function main() {
//   const testQuantity = +readLine();
//   for (let testNumber = 0; testNumber < testQuantity; testNumber++) {
//     let inputString = readLine();
//     let curLen = 0;
//     let curPrefix = "";
//     let maxPrefixLen = 0;

//     for (let inputChar of inputString) {
//       curPrefix += inputChar;
//       curLen++;

//       let foundNew = true;
//       let medianIndex = Math.floor(curLen / 2);
//       for (; medianIndex >= 0; medianIndex--) {
//         if (curPrefix[curLen - 1 - medianIndex] !== curPrefix[medianIndex]) {
//           foundNew = false;
//           break;
//         }
//       }

//       if (foundNew) {
//         maxPrefixLen = curLen;
//       }
//     }

//     console.log(maxPrefixLen);
//   }
// }

// .. -> Problem B

// function main() {
//   const testQuan = +readLine();
//   for (let testIx = 0; testIx < testQuan; testIx++) {
//     const inputStr = readLine();
//     let counter = 0;

//     for (let curLen = 0; curLen <= inputStr.length; curLen++) {
//       for (let startIx = 0; curLen + startIx <= inputStr.length; startIx++) {
//         let substring = inputStr.substring(startIx, startIx + curLen);
//         let prefix = inputStr.substring(0, curLen);
//         let suffix = inputStr.slice(inputStr.length - curLen, inputStr.length);

//         if (substring === prefix && substring !== suffix || substring === suffix && substring !== prefix) {
//           counter++;
//         }
//       }
//     }

//     console.log(counter);
//   }
// }

// .. -> Problem C

// function match(text, pattern) {
//   if (pattern.length > text.length) {
//     return false;
//   }

//   for (let comparingIx = 0; comparingIx < text.length; comparingIx++) {
//     if (text[comparingIx] !== pattern[comparingIx] && pattern[comparingIx] !== "?") {
//       return false;
//     }
//   }

//   return true;
// }

// function main() {
//   const testQuan = +readLine();
//   for (let testIx = 0; testIx < testQuan; testIx++) {
//     const inputStr = readLine();
//     const inputPattern = readLine();
//     const entryIndexes = [];

//     for (let startIx = 0; startIx + inputPattern.length <= inputStr.length; startIx++) {
//       if ( match(inputStr.slice(startIx, startIx + inputPattern.length), inputPattern) ) {
//         entryIndexes.push(startIx);
//       }
//     }

//     console.log(entryIndexes.length);
//     console.log(entryIndexes.join(" "));
//   }
// }

// .. -> Problem D

// function getSubstrQuan(length) {
//   return (length + 1) * (length) / 2;
// }

// function main() {
//   const testQuan = +readLine();
//   for (let testIx = 0; testIx < testQuan; testIx++) {
//     const inputStr = readLine();
//     const inputPattern = readLine();
//     let entryBorders = [];
//     let counter = 0;

//     for (let startIx = 0; startIx + inputPattern.length <= inputStr.length; startIx++) {
//       if ( inputStr.slice(startIx, startIx + inputPattern.length).includes(inputPattern) ) {
//         entryBorders.push([startIx, startIx + inputPattern.length - 1]);
//       }
//     }

//     entryBorders.push([inputStr.length, inputStr.length]);
//     let lastLeftBorder = 0;
//     for (let pairIx = 0; pairIx < entryBorders.length; pairIx++) {
//       let curPair = entryBorders[pairIx];
//       let curSubstrLen = curPair[1] - lastLeftBorder;
//       counter += getSubstrQuan(curSubstrLen);
//       lastLeftBorder = curPair[0] + 1;

//       if (curPair[1] - curPair[0] - 1 > 0) {
//         counter -= getSubstrQuan(curPair[1] - curPair[0] - 1);
//       }
//     }

//     console.log(counter);
//   }
// }

// Codeforces Round #698 (Div. 2) -> Problem A

function main() {
  let testQuan = +readLine();
  for (let testIx = 0; testIx < testQuan; testIx++) {
    let n = +readLine();
    let a = readLine().split(" ");
    a = a.map(item => +item);
    let counterArr = [];
    for (let i = 0; i <= n; i++) counterArr[i] = 0;

    for (let el of a) {
      counterArr[el]++;
    }

    console.log(Math.max(...counterArr));
  }
}

T = readline()

while(T--){
  n = readline()
  a = readline().split(' ').map(x => +x)
  ans = 1
  repeats = 0
  newrepeats = 0
  for(i = 0; i < n; i++ ){
    if(a[i]==a[i+1]){
      newrepeats++
      if(newrepeats>repeats)
        repeats = newrepeats
    }
    else
      newrepeats = 0
  }
  ans += repeats
  print(ans)
}

function solve(a){
    var l = 1, res = 1;
    for(var i = 1; i < a.length; i++){
        if(a[i] == a[i-1]){
            l++;
            res = Math.max(l, res);
        }else{
            l = 1;
        }
    }
    return res;
}

var a = [];
var t = Number(readline());
for (var i = 0; i<t;i++){
    var n = Number(readline());
    a = readline().split(' ').map((x) => x);
    write(solve(a)+'\n');
}

function solve(a){
    var l = 0;
    var c = 0;
    var min = 0;
    var aux = a[l];
    while(l < a.length){
        if(a[l] == aux){
            c++;
        }else{
            aux= a[l];
            c = 1;
        }
        min = c > min ? c : min;
        l++;
    }
    return min;

}

var a = [];
var t = Number(readline());
for (var i = 0; i<t;i++){
    n = Number(readline());
    a = readline().split(' ').map((x) => x);
    write(solve(a)+'\n');
}

var t = parseInt(readline());
    while (t--) {
        var n=parseInt(readline())
        var line = readline();
        var a = line.split(' ');
        var b = new Array(n+1);
        for(var i=1;i<=n;i++) b[i]=0;
        var ans = 0;
        for (var i = 0; i < n; i++) {
            b[a[i]]++;
            ans = (ans<b[a[i]]?b[a[i]]:ans);
        }
        print(ans);
    }

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var s = 0
    var e = 0
    var a = new Map()
    for(j = 1; j <= n * 2; j++){
        if(j % 2 === 0){
            var k = lines[j].split(' ').map(Number)
            for(l = 0; l < e; l++){
                if(a.has(k[l])){
                    var temp = a.get(k[l])
                    temp++
                    a.set(k[l], temp)
                }else{
                    a.set(k[l], 1)
                }
            }
            var biggestKey = ''
            var biggestValue = 0
            for(var[key, value] of a){
                if(value > biggestValue){
                    biggestValue = value
                    biggestKey=key
                }
            }
            console.log(biggestValue)
        }else{
            e = lines[j]
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]

    for(j = 1; j <= n*2; j ++){
        if(j % 2 === 0){
            var one = 0
    var two = 0
    var three = 0
    var four = 0
            var a = lines[j].split(' ').map(Number)
            for(k = 0; k < e; k++){
                if(a[k] == 1){
                    one++
                }else if(a[k] == 2){
                    two++
                }else if(a[k] == 3){
                    three++
                }else if(a[k] == 4){
                    four++
                }
            }
            console.log(Math.max(one, Math.max(two, Math.max(three, four))))
        }else{
            var e = lines[j]
        }
    }

});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    var a = new Map()
    for(j = 1; j <= n*2; j ++){
        a.clear()
        if(j % 2 === 0){
            var s = lines[j].split(' ').map(Number)
            for(k = 0; k < e; k++){
                if(a.has(s[k])){
                    var temp = a.get(s[k])
                    a.set(s[k], temp + 1)
                }else{
                    a.set(s[k], 1)
                }
            }
                    console.log(a.size)

        }else{
            var e = lines[j]
        }
    }

});

T = readline()

while(T--){
  n = readline()
  a = readline().split(' ').map(x => +x)
  ans = 1
  repeats = 1
  newrepeats = 1
  for(i = 0; i < n; i++ ){
    if(a[i]==a[i+1]){
      newrepeats++
      if(newrepeats>repeats)
        repeats = newrepeats
    }
    else
      newrepeats = 0
  }
  ans = repeats
  print(ans)
}

function solve(a){
    var count = 1, l = 1;
    for(var i = 1; i < a.length; i++){
        if(a[i] == a[i-1]){
            if(l == 1 || count == 1) count++;
            l = 1;
        }else{
            l++;
        }
    }
    return count;
}

var a = [];
var t = Number(readline());
for (var i = 0; i<t;i++){
    var n = Number(readline());
    a = readline().split(' ').map((x) => x);
    write(solve(a)+'\n');
}

function solve(a){
    var l = 0;
    var c = 0;
    var min = 0;
    var aux = a[l];
    while(l < a.length){
        if(a[l] == aux){
            c++;
        }else{
            aux= a[l];
            c = 0;
        }
        min = c > min ? c : min;
        l++;
    }
    return min;

}

var a = [];
var t = Number(readline());
for (var i = 0; i<t;i++){
    n = Number(readline());
    a = readline().split(' ').map((x) => x);
    write(solve(a)+'\n');
}

"use strict"

let iter = parseInt(readline());

while(iter--){
    let length = parseInt(readline());
    let input = readline().split(" ").map(x => parseInt(x));

    let current = input[0];
    let counter = 0;
    let maxCounter = 0;

    for(let i = 0; i < length; i++){
        if(input[i] === current){
            counter++;
        } else {
            current = input[i];
            if(counter > maxCounter){
                maxCounter = counter;
            }
            counter = 0;
        }
    }

    print(maxCounter === 0 ? counter : maxCounter);
}


const readline = require('readline');
const process = require('process');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let lineCount = 0;
let queriesNum;
let resultArr = [];
let temp = {};
rl.on('line', function(line){
  if (lineCount === 0) {
    queriesNum = Number(line.trim());
  } else {
    if (lineCount % 2 === 0) {
      temp.arr = line.trim().split('').map((item) => Number(item));
      console.log(gasPipeline(temp))
    } else {
      let dealLine = line.trim().split(' ');
      temp.n = Number(dealLine[0]);
      temp.a = Number(dealLine[1]);
      temp.b = Number(dealLine[2]);
    }
  }
  if (resultArr.length === queriesNum) {
    rl.close();
  }
  lineCount ++;
});

function total(tempArr, prev, next, a, b) {
  let len = tempArr.length
  let minRes = (len - 1 + (prev === undefined ? 0.5 : 1.5) + (next === undefined ? 0.5 : 1.5))*a + (len - 1)* b
  let maxRes = (len - 1 + (prev === undefined ? 1.5 : 0.5) + (next === undefined ? 1.5 : 0.5))*a + (len - 1)*2* b
  return Math.min(minRes, maxRes)
}

function gasPipeline(temp) {
  let {n, a, b, arr} = temp;
  let count = 0;
  let aMoney = 0;
  let bMoney = 2*b;
  let zeroTotal = 0;

  while (count < n) {
    let cur = arr[count];
    let prev = arr[count - 1];
    let temA = [];
    if (cur === 0) {
      while (cur === 0) {
        temA.push(cur);
        count++;
        cur = arr[count];
      }
      zeroTotal += total(temA, prev, arr[count], a, b);
      continue;
    }
    let tempB = [];
    while (cur === 1) {
      tempB.push(cur);
      count++;
      cur = arr[count];
    }
    let tempBLen = tempB.length;
    aMoney += tempBLen*a;
    bMoney += (tempBLen + 1)*2*b;
  }
  return zeroTotal + aMoney + bMoney;
}

const readline = require('readline');
const process = require('process');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let lineCount = 0;
let queriesNum;
let resultArr = [];
let temp = {};
rl.on('line', function(line){
  if (lineCount === 0) {
    queriesNum = Number(line.trim());
  } else {
    if (lineCount % 2 === 0) {
      // 偶数行
      temp.arr = line.trim().split('').map((item) => Number(item));
      resultArr.push(gasPipeline(temp))
    } else {
      // 奇数行
      let dealLine = line.trim().split(' ');
      temp.n = Number(dealLine[0]);
      temp.a = Number(dealLine[1]);
      temp.b = Number(dealLine[2]);
    }
  }
  if (resultArr.length === queriesNum) {
    console.log(resultArr.join('\n'));
    rl.close();
  }
  lineCount ++;
});

function gasPipeline() {
  let {n, a, b, arr} = temp;
  // a:管道 b:柱子
  let count = 0;
  let aMoney = 0;
  let bMoney = 2*b; // 开始结束的低柱子
  let zeroTotal = 0;

  function total(tempArr, prev, next) {
    // 全为低
    let len = tempArr.length
    // 全为低柱子
    let minRes = (len - 1 + (prev === undefined ? 0.5 : 1.5) + (next === undefined ? 0.5 : 1.5))*a + (len - 1)* b
    // 全为高柱子
    let maxRes = (len - 1 + (prev === undefined ? 1.5 : 0.5) + (next === undefined ? 1.5 : 0.5))*a + (len - 1)*2* b
    return Math.min(minRes, maxRes)
  }

  while (count < n) {
    let cur = arr[count];
    let prev = arr[count - 1];
    let temA = [];
    if (cur === 0) {
      // 当前为0时
      while (cur === 0) {
        temA.push(cur);
        count++;
        cur = arr[count];
      }
      zeroTotal += total(temA, prev, arr[count]);
      continue;
    }
    let tempB = [];
    while (cur === 1) {
      tempB.push(cur);
      count++;
      cur = arr[count];
    }
    let tempBLen = tempB.length;
    aMoney += tempBLen*a;
    // 高柱子
    bMoney += (tempBLen + 1)*2*b;
  }
  return zeroTotal + aMoney + bMoney;
}

const readline = require('readline');
const process = require('process');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let lineCount = 0;
let queriesNum;
let resultArr = [];
let temp = {};
rl.on('line', function(line){
  if (lineCount === 0) {
    queriesNum = Number(line.trim());
  } else {
    if (lineCount % 2 === 0) {
      temp.arr = line.trim().split('').map((item) => Number(item));
      console.log(gasPipeline(temp))
    } else {
      let dealLine = line.trim().split(' ');
      temp.n = Number(dealLine[0]);
      temp.a = Number(dealLine[1]);
      temp.b = Number(dealLine[2]);
    }
  }
  if (resultArr.length === queriesNum) {
    rl.close();
  }
  lineCount ++;
});

function total(tempArr, prev, next, a, b) {
  let len = tempArr.length
  let minRes = (len - 1 + (prev === undefined ? 0.5 : 1.5) + (next === undefined ? 0.5 : 1.5))*a + (len - 1)* b
  let maxRes = (len - 1 + (prev === undefined ? 1.5 : 0.5) + (next === undefined ? 1.5 : 0.5))*a + (len - 1)*2* b
  return Math.min(minRes, maxRes)
}

function gasPipeline() {
  let {n, a, b, arr} = temp;
  let count = 0;
  let aMoney = 0;
  let bMoney = 2*b;
  let zeroTotal = 0;

  while (count < n) {
    let cur = arr[count];
    let prev = arr[count - 1];
    let temA = [];
    if (cur === 0) {
      while (cur === 0) {
        temA.push(cur);
        count++;
        cur = arr[count];
      }
      zeroTotal += total(temA, prev, arr[count], a, b);
      continue;
    }
    let tempB = [];
    while (cur === 1) {
      tempB.push(cur);
      count++;
      cur = arr[count];
    }
    let tempBLen = tempB.length;
    aMoney += tempBLen*a;
    bMoney += (tempBLen + 1)*2*b;
  }
  return zeroTotal + aMoney + bMoney;
}


'use strict';

function solve(n, a) {
  let map = new Map();
  for (let i = 0; i < n; i++) {
    const num = a[i];
    if (!map.has(num)) map.set(num, []);
    map.get(num).push(i);
  }
  let res = [];
  for (let [, arr] of map) {
    if (arr.length === 1) return -1;
    const N = arr.length;
    for (let i = 0; i < N; i++) {
      const j = arr[i];
      res[j] = arr[(i + 1) % N];
    }
  }
  return res.map(num => num + 1).join(' ');
}

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);
      res.push(solve(n, a));
    }
    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();
  LT({n, A});
  // PROCESSING:
  if (n==1)
    return -1;
  let r = n-1;
  let perm = [];
  while (r>=0){
    let l = r;
    while (A[l-1]==A[r])
      l--;
    if (l==r)
      return -1;
    perm.push(l+1);
    for (let i=r; i>l; i--){
      perm.push(i+1);
    }
    r = l-1;
  }
  return perm.reverse();
};

function solve() {
   read();
   const a = readArray(Number);
   a.push(-1);
   const ans = [];
   let startIndex = 0;
   for (let i = 1; i < a.length; i++) {
      if (a[i] === a[startIndex]) {
         ans.push(i + 1);
         continue;
      }
      if (i === startIndex + 1) {
         write(-1);
         return;
      }
      ans.push(startIndex + 1);
      startIndex = i;
   }
   write(ans.join(' '));
}

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

function modPow(a, n, mod) {
   let d = a;
   let curN = n;
   let ans = 1n;
   while(curN) {
      if (curN & 1n) {
         ans = modMul(ans, d, mod);
      }
      curN >>= 1n;
      d = modMul(d, d, mod);
   }
   return ans;
}

function modMul(a, b, mod) {
   return (a * b) % mod;
}

function modSum(a, b, mod) {
   return (a + b) % mod;
}

function modDiff(a, b, mod) {
   return (a + mod - b) % mod;
}

function isZero(num) {
   if (typeof num === 'bigint') {
      return num === 0n;
   }
   return num === 0;
}
function div(a, b) {
   if (typeof a !== typeof b) {
      throw new Error('Different types on division');
   }
   if (typeof a === 'bigint') {
      return a / b;
   }
   return Math.floor(a / b);
}

function gcd(x, y) {
   if (isZero(y)) {
      return x;
   }
   return gcd(y, x % y);
}

function lcm(x, y) {
   return div(x * y, gcd(x, y));
}

function allIndexOf(arr, value) {
   var index = arr.indexOf(value)
   var ans = [];
   while (index !== -1) {
      ans.push(index);
      index = arr.indexOf(value, index + 1);
   }
   return ans;
}

function xor(a, b, k) {
   if (k === 2) {
      return a ^ b;
   }
}

function decToBin(num) {
   let n = num;
   const ans = [];
   while(n > 0) {
      ans.push(n & 1);
      n = (n >> 1);
   }
   return ans;
}

function binToDec(binN) {
   let ans = 0;
   for (let i = binN.length - 1; i >= 0; i--) {
      ans = ((ans << 1) | binN[i]);
   }
   return ans;
}

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

function readArray(f) {
   return read().split(' ').map(f);
}

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

   var path = require('path');

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

'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();
  LT({n, A});
  // PROCESSING:
  if (n==1)
    return -1;
  let r = n-1;
  let perm = [];
  while (r>0){
    let l = r;
    while (A[l-1]==A[r])
      l--;
    if (l==r)
      return -1;
    perm.push(l+1);
    for (let i=r; i>l; i--){
      perm.push(i+1);
    }
    r = l-1;
  }
  return perm.reverse();
};

'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();
  LT({n, A});
  // PROCESSING:
  if (n==1)
    return -1;
  let r = n-1;
  let perm = [];
  while (r>0){
    let l = r;
    while (A[l-1]==A[r])
      l--;
    if (l==r)
      return -1;
    perm.push(l+1);
    for (let i=l; i<r; i++){
      perm.push(i+2);
    }
    r = l-1;
  }
  return perm.reverse();
};


n=+readline()
x=0
y=0
s=readline()
res=0
for (i=0;i<n;i++)
{
    if (s[i]=='R')
        ++x
    else
        ++y
    if (x==y&&i&&i<n-1&&s[i]==s[i+1])
        ++res
}
print(res)

readline();
var silverSpent = 0;
var currentKingdom;
var currPos = {x: 0, y: 0};
var moves = readline().split('');

function calcCurrentKingdom() {
  if (currPos.x > currPos.y) {
    return 'upperKingdom';
  } else if (currPos.y > currPos.x) {
    return 'lowerKingdom';
  }
}

function checkForChanges() {
  var kingdomAfterMove = calcCurrentKingdom();
  if (kingdomAfterMove && kingdomAfterMove !== currentKingdom) {
    if (currentKingdom) {
      silverSpent++;
    }
    currentKingdom = kingdomAfterMove;
  }
}

function goUp() {
  currPos.y++;
  checkForChanges();
}

function goRight() {
  currPos.x++;
  checkForChanges();
}

function makeTheMove(direction) {
  direction === 'U' ? goUp() : goRight();
}

moves.forEach(e => makeTheMove(e));

print(silverSpent);

var a = Number(readline());
var b = readline().split('');

var loc = {x:0, y:0};
var coins = 0;

for(var i = 0; i < a; i++){
	if(b[i] === 'R'){
		loc.x+=1;
	} else if (b[i] ==='U'){
		loc.y+=1;
	}
	if(loc.x === loc.y){
		if(b[i] === b[i+1]){
			coins++;
		}
	}
}

print(coins);

inputs = readline();
moves = parseInt(inputs);
movelist = readline();
// print(moves+" "+movelist)

var pos = {
    x:0,
    y:0,
    onGate: false,
    sides:"",
    goUp:()=>{
        pos.isOnGate();
        pos.y = pos.y+1;
        if(pos.onGate && pos.sides === "right"){
            pos.sides = "left"
            return 1;
        } else {
            return 0;
        }
    },
    goRight: ()=>{
        pos.isOnGate();
        pos.x = pos.x+1;
         if(pos.onGate && pos.sides === "left"){
             pos.sides = "right"
            return 1;
        } else {
            return 0;
        }
    },
    isOnGate:()=>{
        if(pos.x === pos.y && pos.x != 0){
            pos.onGate = true;
        }else{
            pos.onGate = false;
        }
    }
}

var cost = 0;
if(movelist[0] === "R"){
    pos.sides = "right";
    pos.goRight();
} else {
    pos.sides = "left";
    pos.goUp()
}
for(move = 1; move < moves; move++){
    if(movelist[move] === "R"){
        cost += pos.goRight();
    }else if(movelist[move] === "U"){
        cost += pos.goUp();
    }
    // print(pos.x+":"+pos.y +" ("+cost+")" )
}
print(cost);

n = readline();
str = readline().split('');

var x = 0, y = 0, side = 'UP', count = 0;

if (str[0] == 'R') {
	side = 'DOWN';
};

for (var i = 0; i < n; i++) {
	if (str[i] == 'U') {
		y++;
	} else if (str[i] == 'R') {
		x++;
	};

	if (side == 'DOWN' && y == x + 1) {
		count++;
		side = 'UP';
	} else if (side == 'UP' && x == y + 1) {
		count++;
		side = 'DOWN';
	};
};

print(count);

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;
	let n = inputReader.readNumber();

	let str = inputReader.readLine();
	let i =0;
	let count = 0,x=0,y=0;
	while(i<str.length){
		if(str[i]=='U')
			y++;
		else
			x++;
		if(x===y){
			if(str[i]==str[i+1])
				count++;
		}
		i++;
	}
	console.log(count);

}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	function readLine(){
		return _inputLines[_lineNumber++];
	}

	return {
		readNumber,
		readLine,
	}
}

var a = Number(readline());
var b = readline().split('');

var loc = {x:0, y:0};
var coins = 0;

b.forEach(e=>{
	if(e === 'R'){
		loc.x+=1;
	} else if (e==='U'){
		loc.y+=1;
	}
	if(loc.x === loc.y){
		coins++;
	}
});
print(coins);


var tok = null;
var index = 0;
function next() {
    while (tok == null || index == tok.length) {
        tok = readline().split(' ');
        index = 0;
    }
    var res = tok[index++];
    return res;
}

function nextInt() {
    return parseInt(next());
}

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

function main() {
    var cX = [];
    var arrY = [];
    var n = nextInt();
    for (var i = 0; i < n; i++) {
        var x = nextInt();
        var y = nextInt();
        arrY[i] = y;
        if (typeof (cX[x]) == 'undefined') {
            cX[x] = 1;
        } else {
            cX[x]++;
        }
    }
    for (var i = 0; i < n; i++) {
        var same = cX[arrY[i]]||0;
        print((n - 1 + same) + " " + (n - 1 - same));
    }
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var teamNum = parseInt(readline());
	function makeHash() {
		var hash = {};
		hash.increment = function(key) {
			if (this[key] === undefined) {
				this[key] = 1;
			} else {
				this[key] += 1;
			}
		};
		hash.get = function(key) {
			return this[key] || 0;
		}
		return hash;
	}
	var homeCount = makeHash(), awayCount = makeHash(),
		teams = [];
	for (var i = 0; i < teamNum; ++i) {
		var data = tokenizeIntegers(readline()),
			home = data[0], away = data[1];
		homeCount.increment(home);
		awayCount.increment(away);
		teams.push({ home: home, away: away });
	}
	for (var i = 0; i < teamNum; ++i) {
		var team = teams[i],
			conflict = homeCount.get(team.away);
		print(teamNum-1+conflict, teamNum-1-conflict);
	}
}

main();

function main() {

    var teamNum = readline().split(' ');

    function makeObj () {
         var hash = {};

         hash.add = function (key) {
             if(this[key] === undefined) {
                 this[key] = 1;
             }else {
                 this[key] +=1;
             }
         }

        hash.get = function (key) {
            return this[key] || 0;
        }

        return hash;

    }

    var homeCount = makeObj(), teams = [];

     for(var i =0; i < teamNum; i++){
         var colors = readline().split(' ');
         var home = colors[0];
         var away = colors[1];
         homeCount.add(home);

         teams.push({home : home, away : away})
     }

    for(var i=0; i < teamNum; i++) {
       var team=teams[i],
           confilct = homeCount.get(team.away);

        print(teamNum - 1 + confilct, teamNum - 1- confilct) ;
    }

}

main();

function main() {

    var teamNum = readline().split(' ');

    var teams = [];
    function makeObj () {
         var hash = {};

         hash.add = function (key) {
             if(this[key] === undefined) {
                 this[key] = 1;
             }else {
                 this[key] +=1;
             }
         }

        hash.get = function (key) {
            return this[key] || 0;
        }

        return hash;

    }

    var homeCount = makeObj(), awayCount = makeObj(),teams = [];

     for(var i =0; i < teamNum; i++){
         var colors = readline().split(' ');
         var home = colors[0];
         var away = colors[1];
         homeCount.add(home);
         awayCount.add(away);
         teams.push({home : home, away : away})
     }

    for(var i=0; i < teamNum; i++) {
       var team=teams[i],
           confilct = homeCount.get(team.away);

        print(teamNum - 1 + confilct, teamNum - 1- confilct) ;
    }

}

main();

var n = parseInt(readline());
function trav(n, cb) {
  var i;
  for (i = 1; i <= n; i ++) {
    cb(i);
  }
}
function createZeroFilledArray() {
  return Array.apply( void 0, Array( 1e5 + 1 ) ).map(Number.prototype.valueOf, 0);
}

var recX = createZeroFilledArray(),
    recY = createZeroFilledArray(),
    totX = createZeroFilledArray();

trav(n, function(cur) {
  recX[cur] = readline().split(" ");
  recY[cur] = parseInt(recX[cur][1], 10);
  recX[cur] = parseInt(recX[cur][0], 10);
  totX[ recX[cur] ] ++;
});

trav(n, function(cur) {
  var resX = (n - 1) + totX[ recY[cur] ],
    resY = 2 * (n - 1) - resX;
  print(resX, resY);
});

;(function () {
	print(function (n) {
		var a = [], m = {}, l = 2 * n - 2;

		for (var i = 0; i < n; i++) {
			s = readline().split(' ').map(Number);
			a.push(s); s = s[0];
			m[s] = m[s] ? m[s] + 1 : 1;
		}

		return a.map(function (e) {
			e = n - 1 + (m[e[1]] || 0 );
			return [e, l - e].join(' ');
		}).join('\n');
	}(+readline()));
}.call(this));