At the store, the salespeople want to make all prices round. In this problem, a number that is a power of $$$10$$$ is called a round number. For example, the numbers $$$10^0 = 1$$$, $$$10^1 = 10$$$, $$$10^2 = 100$$$ are round numbers, but $$$20$$$, $$$110$$$ and $$$256$$$ are not round numbers. So, if an item is worth $$$m$$$ bourles (the value of the item is not greater than $$$10^9$$$), the sellers want to change its value to the nearest round number that is not greater than $$$m$$$. They ask you: by how many bourles should you decrease the value of the item to make it worth exactly $$$10^k$$$ bourles, where the value of $$$k$$$ — is the maximum possible ($$$k$$$ — any non-negative integer).For example, let the item have a value of $$$178$$$-bourles. Then the new price of the item will be $$$100$$$, and the answer will be $$$178-100=78$$$.

The first line of input data contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases . Each test case is a string containing a single integer $$$m$$$ ($$$1 \le m \le 10^9$$$) — the price of the item.

For each test case, output on a separate line a single integer $$$d$$$ ($$$0 \le d < m$$$) such that if you reduce the cost of the item by $$$d$$$ bourles, the cost of the item will be the maximal possible round number. More formally: $$$m - d = 10^k$$$, where $$$k$$$ — the maximum possible non-negative integer.

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*/
    var n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split('').map(Number)
        b = lines[j]

         e = '1'
        for(l = 0; l < k.length - 1; l++){
            e += '0'
        }
        e = Number(e)

        if(b < 10){
            console.log(b-1)
        }else{

            console.log(k.join('')-e)

        }

    }

});

// как меня заебала эта корявая платформа
// https://stackoverflow.com/questions/20086849/how-to-read-from-stdin-line-by-line-in-node
// // cat .\input.txt | node .\script.js
const state = { i: 0 }
const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});
const ten_exp = (exp = 0) => 10 ** exp
rl.on('line', function (line) {
    if (state.i > 0) console.log((line - ten_exp(line.length - 1)).toString() + '\r')
    state.i++
})

const readline = require('readline');

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

function getRound(m) {
    let s = 0
    let base = 10
    let t = 0
    while (t <= m) {
        s++;
        t = Math.pow(base,s)
    }
    return  m - Math.pow(base,s - 1)
}
let lines = [];
rl.on('line', (line) => {
    lines.push(line);
}).on('close', () => {
    const [n,...values] = lines
    for (let i = 0; i< n; i++) {
        const ans = getRound(values[i])
        console.log(ans)
    }
});

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;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}
// console.log(input)
var T = readline();
// var inf = 1000000000000;
for(var tc=1;tc<=T;tc++) {
  var n = readline()//.split(' ').map((x) => parseInt(x));
  // var a = readline().split(' ').map((x) => parseInt(x));
  var len = n.length;
  var val = Math.pow(10, len-1);
  // console.log(len, val)
  val = max(val, 0);
  // n -= 0;
  var ans = n - val;
  console.log(ans)

}

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];
    for(i = 1; i <= t; i++){
        var a = lines[i];
        var k = lines[i].split('').map(Number);
        if(a < 10){
            console.log(a - 1);
        }else{
            var fl = '1';
            var len = k.length;
            for(j = 1; j < len; j++){
                fl += '0';
            }
            console.log(a - fl);
        }
    }
});

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
    var tests = parseInt(readline());
    for (let t = 0;t < tests; ++t) {
        var x = parseInt(readline());
        let prev = 1;
        let next = 1;
        let ans = 1;
        while (next <= x) {
            ans = Math.min(Math.abs(x-prev),Math.abs(x-next));
            prev = 10;
            next *= 10;
        }
        console.log(ans);
    }
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = readline().trim();
    let p = n.length,
      k = 10;
    if (p === 1) {
      console.log(parseInt(n) - 1);
      continue;
    }
    for (let i = 2; i < p; i++) k = k * 10;
    console.log(Math.abs(parseInt(n) - k));
  }
};
solve();

'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 test = 0; test < N; test++) {
        let price = readline();
        let target = 0;
        if (price.length === 1) {
            target = 1
        } else {
            target = Number('1' + ('0').repeat(price.length - 1));
        }
        output(Number(price) - target);

    }
}

'use strict';

function solve(n, m, s) {
  return n - 10 ** (n.toString().length - 1);
}

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

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

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
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++]
        output[i] = solve(n)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n) {
    const k = Math.floor(Math.log10(n))
    return n - 10 ** k
}

//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 M = nextInt();
		var d = 0;
		var now = 1;
		while(true){
			if(now * 10 <= M){
				now *= 10;
			}else{
				break;
			}

		}
		myout(M - now);
	}
}

T = readline()
while (T--) {
   m = readline().split('').map(el => +el)

   if(m[0] !=1){
      m[0] = m[0] - 1
   }
   else{
      m.shift()
   }
   if(m.length){
      print(+m.join(''))
   }
   else{
      print('0')
   }

}

var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var valueString = readline();
    var power = valueString.length;
    var value = parseInt(valueString);
    var roundNum = 1;
    for (var j = 1; j < power; j++)
    {
        roundNum *= 10;
    }
    var result = value - roundNum;
    print(result);
}

var tens = [];
    for (var i=0; i < 10; i++) {
        tens.push(Math.pow(10,i));
    }
    var tests = parseInt(readline());
    for (var t=0; t < tests; t++) {
        var m = parseInt(readline());
        var i = 1;
        while (tens[i] && m >= tens[i]) {
            i++;
        }
        print(m-tens[i-1]);
    }

const main = () => {

	var t = readInt();
	var allans = [];
	for (var zz = 0; zz < t; zz++) {
		var m = readInt();
		var x = 1;
		while (x * 10 <= m) {
			x *= 10;
		}
		var ans = m - x;
		allans.push(ans);
	}
	multiLineArrayPrint(allans);

	return;
}

const readInt = () => parseInt(readline());
const readString = () => readline();
const readIntArr = () => readline().split(" ").map(zzzz => parseInt(zzzz));
const parseLong = (string) => { // javascript's largest long is < (1<<62)
	var n = string.length;
	var res = 0;
	for (var i = 0; i < n; i++) {
		res *= 10;
		res += parseInt(string[i]);
	}
	return res;
}
const readLong = () => parseLong(readLong());
const readLongArr = () => readline().split(" ").map(zzzz => parseLong(zzzz));
const oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));
const multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\n'));
const multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\n'));
const makeArr = (defaultVal, dimensionsArr) => {
	var n = dimensionsArr.length;
	if (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);
	else {
		var temp = [];
		for (var i = 0; i < dimensionsArr[0]; i++)
			temp.push(makeArr(defaultVal, dimensionsArr.slice(1)));
		return temp;
	}
}

for (_ = 0; _ < 1; _++) {
	main();
}

// newline for testing
 //newline for testing
// codeforces js cannot use "let" keyword. use "var" instead
// codeforces js cannot destructure arrays

t = parseInt(readline());

var ans =0, n ;

while(t--)
{
    ans =1;
    //n= prompt();
    n= parseInt(readline());

   while(ans*10<=n) ans*=10;

   print(n-ans);
   //console.log(n-ans);

}

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*/
    var n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split('').map(Number)
        b = lines[j]

         e = 1
        for(l = 0; l < k.length - 1; l++){
            e += '0'
        }
        if(b < 10){
            console.log(b-1)
        }else{

            console.log(k-e)

        }

    }

});

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*/
    var n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split('').map(Number)
        b = lines[j]

        k[0] -= 1
        if(b < 10){
            console.log(b-1)
        }else{

            console.log(k.join(''))

        }

    }

});

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*/
    var n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split('').map(Number)
        b = lines[j]

        k[0] -= 1
        if(b < 10){
            console.log(b)
        }else{

            console.log(k.join(''))

        }

    }

});

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*/
    var n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split('').map(Number)
        b = lines[j]

        k[0] -= 1
        if(k[0] === 0 && k.length > 1){
            k.splice(0,1)
        }
        console.log(k.join(''))

    }

});

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*/
    var n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split('').map(Number)
        b = lines[j]

        k[0] -= 1
        if(k[0] === 0){
            k.splice(0,1)
        }
        console.log(k.join(''))

    }

});

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*/
    var n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split('').map(Number)
        b = lines[j]

        k[0] -= 1
        if(k[0] === 0 && k.length < 1){
            k.splice(0,1)
        }
        console.log(k.join(''))

    }

});

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*/
    var n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split('').map(Number)
        b = lines[j]

        k[0] -= 1
        if(k[0] === 0 && k.length <= 1){
            k.splice(0,1)
        }
        console.log(k.join(''))

    }

});

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*/
    var n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split('').map(Number)
        b = lines[j]

        k[0] -= 1
        console.log(k.join(''))

    }

});

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*/
    var n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split(" ").map(Number)

        a = Math.abs(k[0] - 1);
        b = Math.abs(k[2] - k[1]) + Math.abs(k[2] - 1);
          if (a < b) {
            console.log(1);
          } else if (b < a) {
            console.log(2);
          } else {
            console.log(3);
          }

    }

});

// cat .\input.txt | node .\script.js
const state = { data: [] };
const consume = (chunk) => {
    const chunk_string = chunk.toString()
    const split = chunk_string.split('\r\n').filter(v => v.length > 0)
    for (let i = 0; i < split.length; i++) {
        const element = split[i];
        if (element.indexOf(' ') == -1) {
            state.data.push(Number(element))
            continue
        }
        // if (element.indexOf(' ') > -1) {
        //     state.data.push(element.split(' ').map(Number))
        //     continue
        // }
    }
}
const commit = (answer) => process.stdout.write(answer);
const ten_ext = (exp = 0) => 10 ** exp
const main = (args) => {
    const { data } = state
    const range = data.shift()
    let result = ""
    for (let i = 0; i < range; i++) {
        const element = data[i];
        const etos = element.toString()
        const etosl = etos.length
        result += ((element - ten_ext(etosl - 1)).toString() + '\r\n')
    }
    commit(result)
};
process.stdin
    .on("data", consume)
    .on("end", main);

// cat .\input.txt | node .\script.js
const state = { data: [] };
const consume = (chunk) => {
    const chunk_string = chunk.toString()
    const split = chunk_string.split('\r\n').filter(v => v.length > 0)
    for (let i = 0; i < split.length; i++) {
        const element = split[i];
        if (element.indexOf(' ') == -1) {
            state.data.push(Number(element))
            continue
        }
        if (element.indexOf(' ') > -1) {
            state.data.push(element.split(' ').map(Number))
            continue
        }
    }
}
const commit = (answer) => process.stdout.write(answer);
const ten_ext = (exp = 0) => 10 ** exp
const main = (args) => {
    const { data } = state
    const range = data.shift()
    let result = ""
    for (let i = 0; i < range; i++) {
        const element = data[i];
        const etos = element.toString()
        const etosl = etos.length
        result += ((element - ten_ext(etosl - 1)).toString() + '\r\n')
    }
    commit(result)
};
process.stdin
    .on("data", consume)
    .on("end", main);

// cat .\input.txt | node .\script.js
const state = { data: [] };
const consume = (chunk) => {
    const chunk_string = chunk.toString()
    const split = chunk_string.split('\r\n').filter(v => v.length > 0)
    for (let i = 0; i < split.length; i++) {
        const element = split[i];
        if (element.indexOf(' ') == -1) {
            state.data.push(Number(element))
            continue
        }
        if (element.indexOf(' ') > -1) {
            state.data.push(element.split(' ').map(Number))
            continue
        }
    }
    state.input_counter++
}
const commit = (answer) => process.stdout.write(answer);
const ten_ext = (exp = 0) => 10 ** exp
const main = (args) => {
    const { data } = state
    const range = data.shift()
    for (let i = 0; i < range; i++) {
        const element = data[i];
        const etos = element.toString()
        const etosl = etos.length
        commit((element - ten_ext(etosl - 1)).toString() + '\r\n')
    }
};
process.stdin
    .on("data", consume)
    .on("end", main);

const readline = require('readline');

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

function getRound(m) {
    let s = 0
    let base = 10
    let t = 0
    while (t < m) {
        t = Math.pow(base,++s)
    }
    return m === t ? 0 : m - Math.pow(base,s - 1)
}
let lines = [];
rl.on('line', (line) => {
    lines.push(line);
}).on('close', () => {
    const [n,...values] = lines
    for (let i = 0; i< n; i++) {
        const ans = getRound(values[i])
        console.log(ans)
    }
});

const readline = require('readline');

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

function getRound(m) {
    let s = 0
    let base = 10
    let t = 0
    while (t < m) {
        t = Math.pow(base,++s)
    }
    return m - Math.pow(base,--s)
}
let lines = [];
rl.on('line', (line) => {
    lines.push(line);
}).on('close', () => {
    const [n,...values] = lines
    for (let i = 0; i< n; i++) {
        const ans = getRound(values[i])
        console.log(ans)
    }
});

const readline = require('readline');

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

function getRound(m) {
    let s = 0
    let base = 10
    let t = 0
    while (t < m) {
        t = Math.pow(base,++s)
    }
    return m - (t/10)
}
let lines = [];
rl.on('line', (line) => {
    lines.push(line);
}).on('close', () => {
    const [n,...values] = lines
    for (let i = 0; i< n; i++) {
        const ans = getRound(values[i])
        console.log(ans)
    }
});

T = readline()
while (T--) {
   m = readline().split('').map(el => +el)

   if(m[0] !=1){
      m[0] = m[0] - 1
   }
   else{
      m.shift()
   }
   if(m.length){
      print(m.join(''))
   }
   else{
      print('0')
   }

}

var tens = [];
    for (var i=0; i < 10; i++) {
        tens.push(Math.pow(10,i));
    }
    var tests = parseInt(readline());
    for (var t=0; t < tests; t++) {
        var m = parseInt(readline());
        var i = 1;
        while (tens[i] && m > tens[i]) {
            i++;
        }
        print(m-tens[i-1]);
    }


Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?

The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.

In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.

NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.

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]);
	};
	return tokens;
}

function main() {
	var halfSize = parseInt(readline(), 10),
		fullSize = 2*halfSize,
		cubeOccurrences = {}, sortedCubes = [];

	var cubes = tokenizeIntegers(readline());
	for (var cubeIndex = 0; cubeIndex < fullSize; ++cubeIndex) {
		var cube = cubes[cubeIndex];
		if (cubeOccurrences[cube] == undefined) {
			cubeOccurrences[cube] = [];
			sortedCubes.push(cubeOccurrences[cube]);
		}
		cubeOccurrences[cube].push(cubeIndex);
	}

	sortedCubes.sort(function (a, b) {
		if (a.length%2 != b.length%2) {
			return a.length%2 - b.length%2;
		}
		else {
			return a.length - b.length;
		}
	});

	var uniqueNum = sortedCubes.length,
		counts = { 1: 0, 2: 0 },
		partition = new Array(fullSize);

	for (var uniqueIndex = 0; uniqueIndex < uniqueNum; ++uniqueIndex) {
		var occurrences = sortedCubes[uniqueIndex],
			side = 1 + uniqueIndex%2;
		for (var occurrenceIndex = 0; occurrenceIndex < occurrences.length; ++occurrenceIndex) {
			partition[occurrences[occurrenceIndex]] = side;
			if (occurrenceIndex < 2) {
				counts[side] += 1;
			}
			side = (side == 1 ? 2 : 1);
		}

		//print(occurrences.length+": "+occurrences.join(" "));
	}

	//print(counts[1], counts[2]);
	print(counts[1] * counts[2]);
	print(partition.join(" "));
}

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]);
	};
	return tokens;
}

function main() {
	var halfSize = parseInt(readline(), 10),
		fullSize = 2*halfSize,
		cubeInfo = {}, sortedCubes = [];

	var cubes = tokenizeIntegers(readline());
	for (var cubeIndex = 0; cubeIndex < fullSize; ++cubeIndex) {
		var cube = cubes[cubeIndex];
		if (cubeInfo[cube] == undefined) {
			cubeInfo[cube] = { value: cube, occurrences: [] };
			sortedCubes.push(cubeInfo[cube]);
		}
		cubeInfo[cube].occurrences.push(cubeIndex);
	}

	sortedCubes.sort(function (a, b) {
		return a.occurrences.length%2 - b.occurrences.length%2;
	});

	var uniqueNum = sortedCubes.length,
		counts = { 1: 0, 2: 0 },
		partition = new Array(fullSize);

	for (var uniqueIndex = 0; uniqueIndex < uniqueNum; ++uniqueIndex) {
		var occurrences = sortedCubes[uniqueIndex].occurrences,
			side = 1 + uniqueIndex%2;
		for (var occurrenceIndex = 0; occurrenceIndex < occurrences.length; ++occurrenceIndex) {
			partition[occurrences[occurrenceIndex]] = side;
			if (occurrenceIndex < 2) {
				counts[side] += 1;
			}
			side = (side == 1 ? 2 : 1);
		}
	}

	print(counts[1] * counts[2]);
	print(partition.join(" "));
}

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]);
	};
	return tokens;
}

function main() {
	var halfSize = parseInt(readline(), 10),
		fullSize = 2*halfSize,
		cubeInfo = {}, sortedCubes = [];

	var cubes = tokenizeIntegers(readline());
	for (var cubeIndex = 0; cubeIndex < fullSize; ++cubeIndex) {
		var cube = cubes[cubeIndex];
		if (cubeInfo[cube] == undefined) {
			cubeInfo[cube] = { value: cube, occurrences: [] };
			sortedCubes.push(cubeInfo[cube]);
		}
		cubeInfo[cube].occurrences.push(cubeIndex);
	}

	sortedCubes.sort(function (a, b) {
		return a.occurrences.length - b.occurrences.length;
	});

	var uniqueNum = sortedCubes.length,
		counts = { 1: 0, 2: 0 },
		partition = new Array(fullSize);

	for (var uniqueIndex = 0; uniqueIndex < uniqueNum; ++uniqueIndex) {
		var occurrences = sortedCubes[uniqueIndex].occurrences,
			side = 1 + uniqueIndex%2;
		for (var occurrenceIndex = 0; occurrenceIndex < occurrences.length; ++occurrenceIndex) {
			partition[occurrences[occurrenceIndex]] = side;
			if (occurrenceIndex < 2) {
				counts[side] += 1;
			}
			side = (side == 1 ? 2 : 1);
		}
	}

	print(counts[1] * counts[2]);
	print(partition.join(" "));
}

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]);
	};
	return tokens;
}

function main() {
	var halfSize = parseInt(readline(), 10),
	fullSize = 2*halfSize,
	counts = { 1: 0, 2: 0 },
	duplicate = {},
	firstSide = {}, currentSide = 1, sides = [];

	var cubes = tokenizeIntegers(readline());
	for (var cubeIndex = 0; cubeIndex < fullSize; ++cubeIndex) {
		var cube = cubes[cubeIndex];

		if (firstSide[cube] == undefined) {
			counts[currentSide] += 1;
			firstSide[cube] = currentSide;
			sides.push(currentSide);
			currentSide = (currentSide == 1 ? 2 : 1);
		}
		else {
			firstSide[cube] = (firstSide[cube] == 1 ? 2 : 1);
			sides.push(firstSide[cube]);
			if (duplicate[cube] == undefined) {
				duplicate[cube] = true;
				counts[firstSide[cube]] += 1;
			}
		}
	}

	print(counts[1]*counts[2]);
	print(sides.join(" "));
}

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]);
	};
	return tokens;
}

function main() {
	var halfSize = parseInt(readline(), 10),
		fullSize = 2*halfSize,
		cubeInfo = {}, sortedCubes = [];

	var cubes = tokenizeIntegers(readline());
	for (var cubeIndex = 0; cubeIndex < fullSize; ++cubeIndex) {
		var cube = cubes[cubeIndex];
		if (cubeInfo[cube] == undefined) {
			cubeInfo[cube] = { value: cube, occurrences: [] };
			sortedCubes.push(cubeInfo[cube]);
		}
		cubeInfo[cube].occurrences.push(cubeIndex);
	}

	sortedCubes.sort(function (a, b) {
		return a.occurrences.length - b.occurrences.length;
	});

	var uniqueNum = sortedCubes.length,
		counts = { 1: 0, 2: 0 },
		partition = new Array(fullSize);

	for (var uniqueIndex = 0; uniqueIndex < uniqueNum; ++uniqueIndex) {
		var occurrences = sortedCubes[uniqueIndex].occurrences,
			side = 1 + uniqueIndex%2;
		for (var occurrenceIndex = 0; occurrenceIndex < occurrences.length; ++occurrenceIndex) {
			partition[occurrences[occurrenceIndex]] = side;
			counts[side] += 1;
			side = (side == 1 ? 2 : 1);
		}
	}

	print(counts[1] * counts[2]);
	print(partition.join(" "));
}

main();


Stanley defines the beauty of an array $$$a$$$ of length $$$n$$$, which contains non-negative integers, as follows: $$$$$$\sum\limits_{i = 1}^{n} \left \lfloor \frac{a_{i}}{k} \right \rfloor,$$$$$$ which means that we divide each element by $$$k$$$, round it down, and sum up the resulting values.Stanley told Sam the integer $$$k$$$ and asked him to find an array $$$a$$$ of $$$n$$$ non-negative integers, such that the beauty is equal to $$$b$$$ and the sum of elements is equal to $$$s$$$. Help Sam — find any of the arrays satisfying the conditions above.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains integers $$$n$$$, $$$k$$$, $$$b$$$, $$$s$$$ ($$$1 \leq n \leq 10^{5}$$$, $$$1 \leq k \leq 10^{9}$$$, $$$0 \leq b \leq 10^{9}$$$, $$$0 \leq s \leq 10^{18}$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print $$$-1$$$ if such array $$$a$$$ does not exist. Otherwise print $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_{i} \leq 10^{18}$$$) — the answer.

NoteIn the first, the second, the fifth and the sixth test cases of the example it is possible to show that such array does not exist.In the third testcase of the example $$$a = [0, 0, 19]$$$. The sum of elements in it is equal to 19, the beauty of it is equal to $$$\left ( \left \lfloor \frac{0}{6} \right \rfloor + \left \lfloor \frac{0}{6} \right \rfloor + \left \lfloor \frac{19}{6} \right \rfloor \right ) = (0 + 0 + 3) = 3$$$.In the fourth testcase of the example $$$a = [0, 3, 3, 3, 29]$$$. The sum of elements in it is equal to $$$38$$$, the beauty of it is equal to $$$(0 + 0 + 0 + 0 + 7) = 7$$$.

// n = glass container width, k = glass height, b = |filled glass liquid height|, s = |total liquid height|
function solve(n, k, b, s){
    // const FIRST_GLASS = (k+1) * b - 1;
    // const REST_GLASS = b - 1;
    const FIRST_GLASS = k * (b+1) - 1;
    const REST_GLASS = k - 1;
    const MIN_CAPACITY = k * b;
    const MAX_CAPACITY = FIRST_GLASS + ((n-1) * REST_GLASS);
    if(s < MIN_CAPACITY || s > MAX_CAPACITY) return [-1]; // RTE if not arr

    const result = Array(n).fill(0);

    for(let i=0;i<n;i++){
        let cmp = s;
        if(i===0){
            cmp = Math.min(s, FIRST_GLASS);
        }
        else {
            cmp = Math.min(s, REST_GLASS);
        }
        s-=cmp;
        result[i] = cmp;
    }
    return result;
}

function test(){
    console.log(solve(1, 6, 3, 100));
    console.log(solve(3, 6, 3, 12));
    console.log(solve(3, 6, 3, 19));
    console.log('hello CF')
}

// test();

/* --------------------------------------- submit ------------------------------------------ */

const process = require('process');
const {EOL} = require('os');
const { mainModule } = require('process');

let data = ``;

process.stdin.on('data', string=>data+=string);
process.stdin.on('end', () => {
    const dataLines = data.split(EOL);
    B1715(dataLines);
});

/* --------------------------------------- local test ------------------------------------------

let data = `8
1 6 3 100
3 6 3 12
3 6 3 19
5 4 7 38
5 4 7 80
99978 1000000000 100000000 1000000000000000000
1 1 0 0
4 1000000000 1000000000 1000000000000000000`;

const dataLines = data.split('\n');
console.log(B1715(dataLines));

*/

/* --------------------------------------- boilerplate ------------------------------------------ */

function convertNumberArray(str){ // '  12   43 123 4 ' >> [12, 43, 123, 4]
    return str.replace(/ +/g, " ").trim().split(' ').map(string => Number(string));
}
function printArray(arr){ // [12, 43, 123, 4] >> '12 43 123 4'
    return arr.join(' ');
}
function B1715(input){
    let result = '';
    const tests = Number(input[0]);
    for(let i=1; i<=tests; i++){
        const [n, k, b, s] = convertNumberArray(input[i]);
        // process.stdout.write(solve(n, k, b, s) + '\n'); // array printing error
        process.stdout.write(printArray(solve(n, k, b, s)) + '\n');
        result+=solve(n, k, b, s) + '\n'
    }
    return result;
}

/*
answer
-1
-1
0 0 19
0 3 3 3 29
-1
-1
0
0 0 0 1000000000000000000

*/

var tests = parseInt(readline());
    var n, k, b, s;

    for (var t=0; t < tests; t++) {
        var nkbs = readline().split(' ').map(x=>parseInt(x));
        n = nkbs[0];
        k = nkbs[1];
        b = nkbs[2];
        s = nkbs[3];

        if (s < k * b || s > k * b + n * (k-1)) {
            print(-1);
            continue;
        }
        var ans = [];
        var sum = s;
        var first = b * k;
        first += Math.min(sum - b*k, k-1);
        ans.push(first);
        sum -= first;
        while (sum > 0) {
            var next = Math.min(k-1, sum);
            ans.push(next);
            sum -= next;
        }
        while (ans.length < n) {
            ans.push(0);
        }
        print(ans.join(' '));
    }

// n = glass container width, k = glass height, b = |filled glass liquid height|, s = |total liquid height|
function solve(n, k, b, s){
    // const FIRST_GLASS = (k+1) * b - 1;
    // const REST_GLASS = b - 1;
    const FIRST_GLASS = k * (b+1) - 1;
    const REST_GLASS = k - 1;
    const MIN_CAPACITY = k * b;
    const MAX_CAPACITY = FIRST_GLASS + ((n-1) * REST_GLASS);
    if(s < MIN_CAPACITY || s > MAX_CAPACITY) return -1;

    const result = Array(n).fill(0);

    for(let i=0;i<n;i++){
        let cmp = s;
        if(i===0){
            cmp = Math.min(s, FIRST_GLASS);
        }
        else {
            cmp = Math.min(s, REST_GLASS);
        }
        s-=cmp;
        result[i] = cmp;
    }
    return result;
}

function test(){
    console.log(solve(1, 6, 3, 100));
    console.log(solve(3, 6, 3, 12));
    console.log(solve(3, 6, 3, 19));
    console.log('hello CF')
}

// test();

/* --------------------------------------- submit ------------------------------------------ */

const process = require('process');
const {EOL} = require('os');
const { mainModule } = require('process');

let data = ``;

process.stdin.on('data', string=>data+=string);
process.stdin.on('end', () => {
    const dataLines = data.split(EOL);
    B1715(dataLines);
});

/* --------------------------------------- local test ------------------------------------------ */

// let data = `8
// 1 6 3 100
// 3 6 3 12
// 3 6 3 19
// 5 4 7 38
// 5 4 7 80
// 99978 1000000000 100000000 1000000000000000000
// 1 1 0 0
// 4 1000000000 1000000000 1000000000000000000`;

// const dataLines = data.split('\n');
// console.log(B1715(dataLines));

/* --------------------------------------- boilerplate ------------------------------------------ */

function convertNumberArray(str){ // '  12   43 123 4 ' >> [12, 43, 123, 4]
    return str.replace(/ +/g, " ").trim().split(' ').map(string => Number(string));
}
function B1715(input){
    let result = '';
    const tests = Number(input[0]);
    for(let i=1; i<=tests; i++){
        const [n, k, b, s] = convertNumberArray(input[i]);
        process.stdout.write(solve(n, k, b, s) + '\n');
        result+=solve(n, k, b, s) + '\n'
    }
    return result;
}

/*
answer
-1
-1
0 0 19
0 3 3 3 29
-1
-1
0
0 0 0 1000000000000000000

*/


Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms.Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions:   Take the leftmost item with the left hand and spend wi · l energy units (wi is a weight of the leftmost item, l is some parameter). If the previous action was the same (left-hand), then the robot spends extra Ql energy units;  Take the rightmost item with the right hand and spend wj · r energy units (wj is a weight of the rightmost item, r is some parameter). If the previous action was the same (right-hand), then the robot spends extra Qr energy units; Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.

The first line contains five integers n, l, r, Ql, Qr (1 ≤ n ≤ 105; 1 ≤ l, r ≤ 100; 1 ≤ Ql, Qr ≤ 104). The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 100).

In the single line print a single number — the answer to the problem.

NoteConsider the first sample. As l = r, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units.The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units.

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]);
	};
	return tokens;
}

function main() {
	var data = tokenizeIntegers(readline());
	var numItems = data[0],
		costL = data[1], costR = data[2],
		penaltyL = data[3], penaltyR = data[4];

	var weights = tokenizeIntegers(readline());

	var baseCost = 0;
	for (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {
		baseCost += weights[itemIndex]*costR;
	}

	var best = baseCost + (numItems-1)*penaltyR;

	var countL = 0, countR = numItems;

	for (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {

		baseCost += weights[itemIndex] * (costL - costR);

		++countL;
		--countR;

		var penalty = 0;
		if (countR > countL) {
			penalty = (countR - 1 - countL) * penaltyR;
		}
		else if (countL > countR) {
			penalty = (countL - 1 - countR) * penaltyL;
		}

		best = Math.min(best, baseCost + penalty);
	}

	print(best);
}

main();


Monocarp has got two strings $$$s$$$ and $$$t$$$ having equal length. Both strings consist of lowercase Latin letters "a" and "b". Monocarp wants to make these two strings $$$s$$$ and $$$t$$$ equal to each other. He can do the following operation any number of times: choose an index $$$pos_1$$$ in the string $$$s$$$, choose an index $$$pos_2$$$ in the string $$$t$$$, and swap $$$s_{pos_1}$$$ with $$$t_{pos_2}$$$.You have to determine the minimum number of operations Monocarp has to perform to make $$$s$$$ and $$$t$$$ equal, and print any optimal sequence of operations — or say that it is impossible to make these strings equal.

The first line contains one integer $$$n$$$ $$$(1 \le n \le 2 \cdot 10^{5})$$$ — the length of $$$s$$$ and $$$t$$$. The second line contains one string $$$s$$$ consisting of $$$n$$$ characters "a" and "b".  The third line contains one string $$$t$$$ consisting of $$$n$$$ characters "a" and "b".

If it is impossible to make these strings equal, print $$$-1$$$. Otherwise, in the first line print $$$k$$$ — the minimum number of operations required to make the strings equal. In each of the next $$$k$$$ lines print two integers — the index in the string $$$s$$$ and the index in the string $$$t$$$ that should be used in the corresponding swap operation.

NoteIn the first example two operations are enough. For example, you can swap the third letter in $$$s$$$ with the third letter in $$$t$$$. Then $$$s = $$$ "abbb", $$$t = $$$ "aaab". Then swap the third letter in $$$s$$$ and the second letter in $$$t$$$. Then both $$$s$$$ and $$$t$$$ are equal to "abab".In the second example it's impossible to make two strings equal.

const n = Number(readline());
const s = Array.from(readline().substring(0, n), c => c === "b");
const t = Array.from(readline().substring(0, n), c => c === "b");
const results = (() => {
  if (s.concat(t).reduce((a, b) => a ^ b)) return null;
  var abs = [];
  var bas = [];
  for (var i = 0; i < n; i++)
    if (s[i] ^ t[i]) {
      if (t[i]) abs.push(i);
      else bas.push(i);
    }
  var results = [];
  while (abs.length >= 2)
    results.push([abs.pop(), abs.pop()]);
  while (bas.length >= 2)
    results.push([bas.pop(), bas.pop()]);
  if (abs.length) {
    if (!bas.length) return null;
    var x = abs.pop();
    results.push([x, x], [x, bas.pop()]);
  }
  return results;
})();
if (results) {
  print(results.length);
  for (var result of results)
    print(`${result[0] + 1} ${result[1] + 1}`);
} else print("-1");


You are given four distinct integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$. Timur and three other people are running a marathon. The value $$$a$$$ is the distance that Timur has run and $$$b$$$, $$$c$$$, $$$d$$$ correspond to the distances the other three participants ran. Output the number of participants in front of Timur.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of each test case consists of four distinct integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ ($$$0 \leq a, b, c, d \leq 10^4$$$).

For each test case, output a single integer — the number of participants in front of Timur.

NoteFor the first test case, there are $$$2$$$ people in front of Timur, specifically the participants who ran distances of $$$3$$$ and $$$4$$$. The other participant is not in front of Timur because he ran a shorter distance than Timur.For the second test case, no one is in front of Timur, since he ran a distance of $$$10000$$$ while all others ran a distance of $$$0$$$, $$$1$$$, and $$$2$$$ respectively.For the third test case, only the second person is in front of Timur, who ran a total distance of $$$600$$$ while Timur ran a distance of $$$500$$$.

"use strict";

  let t = +(readline());

  for(let i=0;i<t;i++){
     solve(readline().split(' '));
  }

  function solve(dist){
     let cnt=0;

     for(let i=1;i<4;i++){

       if( +dist[i] > +dist[0])cnt++;
     }

      print(cnt);
  }

"use strict";

        let x = +(readline());

        for(let i = 0; i < x; i++) {
            marathone(readline().split(' '));
        }

        function marathone(distances) {
            let counter = 0;
            for(let i = 1; i < 4; i++) {
                let timurDistance = +distances[0];

                if(timurDistance < +distances[i]) {
                    counter++;
                }
            }

            print(counter);
        }

var t = readline();
for(var  i =0 ; i < t ; i++){
    var inputs = readline().split(' '),
        counter = 0,
        timur = inputs[0],
        participants = inputs.slice(1);
        for(var j = 0 ; j < participants.length ; j++){
            if(parseInt(participants[j]) > parseInt(timur) ){
                counter++;
            }
        }
        print(counter);
}

var n = readline();
var arr = [];
var s = 0;
for(var i = 0; i < n; i++){
    arr[i] = readline().split(' ').map(i=>Number(i));
    for(var j = 0; j < arr[i].length; j++){
        if(arr[i][0]<arr[i][j]){
            s+=1;

        }
    }
    print(s);
    s=0;
}

var limit = parseInt(readline());
    for (var i = 0; i < limit; i++) {
        var caseArray = readline().split(" ");
        var a = parseInt(caseArray[0]);
        var count = 0;
        for (var j = 1; j < caseArray.length; j++) {
            var value = parseInt(caseArray[j]);
            if (value > a)
                count++;
        }
        print(count);
    }

var t = parseInt(readline());

for (var test = 0; test < t; test++) {
    var inp = readline().split(' ');
    var a = parseInt(inp[0]);
    var b = parseInt(inp[1]);
    var c = parseInt(inp[2]);
    var d = parseInt(inp[3]);

    var ans = (b > a) + (c > a) + (d > a);

    print(ans);
}

var testCase=+readline(),counter
for(var i=0;i<testCase;i++){
    var sequence=readline().split(" ")
    var b=sequence[0]
    var a=sequence.sort((a,b)=>a-b)
    print(4-a.indexOf(b)-1)
}

test = readline();

while (test--) {
    input = readline().split(" ").map(x => parseInt(x));
    Timur = input[0];
    participantsInFront = 0;

    for (var i = 1; i <= 3; i++) {
        if (Timur < input[i]) {
            participantsInFront++;
        }
    }
    print(participantsInFront)
}

T = readline()
while (T--) {
   n = readline().split(' ').map(a => +a)
   a = n[0]
   b = n[1]
   c = n[2]
   d = n[3]

   ans = 0
   if(b>a)
      ans++
   if(c>a)
      ans++
   if(d>a)
      ans++

   print(ans)
}

// как меня заебала эта корявая платформа
// https://stackoverflow.com/questions/20086849/how-to-read-from-stdin-line-by-line-in-node
// // cat .\input.txt | node .\script.js
const state = { i: 0 }
const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});
const ten_exp = (exp = 0) => 10 ** exp
rl.on('line', function (line) {
    if (state.i > 0) {
        let data = line.split(' ').map(Number)
        let above = []
        for (let i = 1; i < data.length; i++) {
            const sample = data[0]
            const element = data[i];
            if (element > sample) above.push(element)

        }
        console.log(above.length)
    }
    state.i++
})

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];
    for(i = 1; i <= t; i++){
        var k = lines[i].split(' ').map(Number);
        var ans = 0;
	    for(j = 1; j < 4; j++){
            if(k[j] > k[0]){
	            ans++;
            }
	    }
	    console.log(ans);
    }
});

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];
	for(i = 1; i <= t; i++){
	        var k = lines[i].split(' ').map(Number);
	        var a = k[0];
	        var ans = 0;
	        for(j = 1; j < 4; j++){
	            if(k[j] > a){
	                ans++;
	            }
	        }
	        console.log(ans);
	}
});

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 [a1, b1, c1, d1] = d.split(" ").map(Number);
  const ans = Number(a1 < b1) + Number(a1 < c1) + Number(a1 < d1);
  console.log(ans);

  // const numbers = d.split(" ").map(Number);
  // let me = numbers[0];
  // const ans = numbers.filter((x) => x > me).length;

  // console.log(ans);

  c++;
});

rl.on("close", () => {});

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 numbers = d.split(" ").map(Number);
  let me = numbers[0];
  const ans = numbers.filter((x) => x > me).length;

  console.log(ans);

  c++;
});

rl.on("close", () => {});

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

const res = [];
rl.on('line', (line) => {
    const [timur, ...rest] = line.split(' ').map((n) => parseInt(n));
    if (rest.length !== 3) return;
    console.log(rest.filter(n => n > timur).length);
}).on('close', () => {
    process.exit();
});

'use strict';

function solve(a) {
  const [x, ...arr] = a;
  let res = 0;
  for (let num of a) if (num > x) res++;
  return res;
}

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

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

const main = (input) => {
  input = input.split('\n')

  const t = Number(input[0])
  for (let i = 0; i < t; i++) {
    const [a, b, c, d] = input[i + 1].split(' ').map((x) => parseInt(x))

    let ans = 0
    ans += b > a ? 1 : 0
    ans += c > a ? 1 : 0
    ans += d > a ? 1 : 0

    console.log(ans)
  }
}

main(require('fs').readFileSync(0).toString())

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

let input = [];
let ans = [];

readline.on('line', line => {
    input.push(line);
}).on('close', () => {
    let cases = input.slice(1).map(v=>v.split(' ').map(Number));

    for (let c of cases) {
        ans.push(c.filter(v=>v>c[0]).length);
    }
    console.log(ans.join('\n'));

});

const { readFileSync } = require("fs")

let x = readFileSync("./input.fd0138e687.txt","utf-8").match(/(\d+\s){3}\d+/g)

for(let e of x){
   let [b,...a] = e.split(" ")
   console.log( a.filter(e=>+e>+b).length )
}

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
let data = [];
let dataIdx = 0;

rl.on('line', function (line) {
  //input,
  data.push(...line.trim().split(' '));
}).on('close', function () {
  //output
  main();
  process.exit();
});

function input() {
  return data[dataIdx++];
}

function output(value) {
  try {
    process.stdout.write(value);
  } catch (err) {
    process.stdout.write(value.toString());
  }
}
//////////////////////////////////////////////////////////

function main() {
  //ps start!

  let t = Number(input());
  while (t--) {
    let [a, b, c, d] = [
      Number(input()),
      Number(input()),
      Number(input()),
      Number(input()),
    ];

    let result = 0;
    if (b > a) {
      result++;
    }
    if (c > a) {
      result++;
    }
    if (d > a) {
      result++;
    }
    output(result + '\n');
  }
}

"use strict";

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

let inputString = "";
let currentLine = 0;

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

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

  main();
});

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

function main() {
  const T = readline()
  for (let i = 0; i < T; i++) {
    const arr = readline().split(' ').map(Number)
    let result = 0
    for (let i = 1; i < arr.length; i++) {
      if (arr[i] > arr[0]) result++
    }
    console.log(result)
  }
}

'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 test = 0; test < N; test++) {
        const [a,b,c,d] = readline().split(' ').map(Number);
        let r = 0;
        if (b > a) r++;
        if (c > a) r++;
        if (d > a) r++;
        output(r);
    }
}

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; j ++){
        var s = lines[j].split(' ').map(Number)
        var a = s[0]
        var b = s[1]
        var c = s[2]
        var d = s[3]
        var e = 0
        for(l = 1; l <= 4; l++){
        if(a < s[l]){
            e+=1
        }
        }
        console.log(e)
    }

});

function Solution() {
  let t = 0;
  const n = Number(lines[t++]);

  const res = [];
  for (let i = 0; i < n; i++) {
    const arr = lines[t++].split(' ').map((item) => Number(item));
    let count = 0;
    for (let z = 0; z < arr.length; z++) {
      if (arr[z] > arr[0]) count += 1;
    }
    res[i] = count;
  }

  return res.join('\n');
}

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', () => {
  console.log(Solution());
});

const rdline = require('readline');

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

let lines = [];
rl.on('line', (line) => {
    lines.push(line);
}).on('close', () => {
    // input in lines
    solve();
});

let line = 0;
const readline = () => lines[line++];

solve = () => {
    const t = parseInt(readline());
    for (let i = 0; i < t; i++) {
        n = 0;
        const s = readline().split(" ").map(Number);
        for (let j = 1; j < s.length; j++) {
            if (s[j] > s[0]) {
                n++;
            }
        }
        console.log(n);
    }
}

//Setup
let i = ''
let a;
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*/
  //console.log(lines);
  a=lines
//Actual Code
function stringToNumber(array){
    for (var i = 0; i < array.length; i++){
        array[i]=parseInt(array[i])
    }

    return array
}
var numTestes = a[0]
numTestes = parseInt(numTestes)
var testData = []
for(c=1;c<=numTestes;c++){
    testData.push(stringToNumber(a[c].split(" ")))
}

for(b=0;b<numTestes;b++){
    var ans = 0
    for(a=1;a<4;a++){
      if(testData[b][0]<testData[b][a]){
        ans++
      }

    }

    console.log(ans)

}

//End of Code

})

// Parsing input: https://codeforces.com/blog/entry/78878
process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

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

function main() {
    // Actual body code
    var T = parseInt(readLine());

    for (var t = 0; t < T; ++t) {
        let l = readLine();
        var xs = l.trim().split(" ").map(x => parseInt(x, 10));
        var a = xs[0];
        console.log(xs.slice(1).map(x => a < x).reduce((x, y) => x + y));
    }
}

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

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

    main();
});

const solve = (arr)=>{
     let a = arr[0],cnt = 0;
     for(let i=1;i<4;i++){
          if(arr[i]>a) cnt++;
     }
     return cnt;
}

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 arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       console.log(solve(arr));
  }
}
main();

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

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		let a = nl.nums();
		let x = a.shift();
		let c = a.reduce((ac, e) => ac + ((e>x)?1:0), 0);
		ans.push(c);
	}
	console.log(ans.join('\n'));
};

process.stdin.on('end', sol);

/* Common Template Starts */
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
/* Common Template Ends */

function main() {
    let n = readline()

    for (let i = 0; i < n; i++) {
        let participants = 0

        let row = readline().split(' ')

        if (parseInt(row[0]) < parseInt(row[1])) {
            participants++
        }

        if (parseInt(row[0]) < parseInt(row[2])) {
            participants++
        }

        if (parseInt(row[0]) < parseInt(row[3])) {
            participants++
        }

        console.log(participants)
    }
}

/**
 * Author : Fazlul Hoque
 * Node.js version : 12.16.3
 * command : node fileName.js <input.txt >output.txt
 */
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = ""; //An array of  raw inputs (includes 'n,\r , not usable. need to process before use)
let currentLine = 0; //input sequence controller variable.

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main(); // after input
});

/********** Utility Functions Start **********/
/**
 *  read row Input
 * @returns string
 */
function _readRawLine() {
    return inputString[currentLine++];
}
function readLine(){
    // return _readRawLine().replace(/\s+$/g, '');
    return _readRawLine().replace('\r', '');
}

function print(x) {
    console.log(x);
}

function readSingleInt() {
    const p = readLine();
    return parseInt(p);
}

function readIntArray() {
    return readLine().split(" ").map((v) => parseInt(v));
}

function readArray() {
    return readLine().split(" ");
}

function int(n) {
    return parseInt(n);
}
/********** Utility Functions End **********/
/**
 * Don't Touch this fucntion at all , unless you know what are you doing!
 */
function main() {
    solve();
}

// ********** actual Code Starts from here **********

function solve() {
    let t = readSingleInt();
    while(t--)
    {
        let n  = readIntArray();
        let cnt = 0;
        for(let i=1;i<n.length;i++)
        {
            if(n[0]<n[i]){
                cnt++;
            }
        }
        console.log(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 findKthLargest(nums, k) {
    k = nums.length - k;
    const quickSelect = (l, r) => {
        let pivot = nums[r];
        let p = l;
        for (let i = l; i < r; i++) {
            if (nums[i] <= pivot) {
                swapper(nums, p, i);
                p++;
            }
        }
        swapper(nums, p, r);

        if (p > k) return quickSelect(l, p - 1);
        else if (p < k) return quickSelect(p + 1, r);
        else return nums[p];
    };

    return quickSelect(0, nums.length - 1);
};

function swapper(array, a, b) {
    const temp = array[b];
    array[b] = array[a];
    array[a] = temp;
};

function main() {
    const n = parseInt(readline());
    for(var i=0; i<n; i++){
        const nums = readline().split(" ").map(r => parseInt(r));
        var count = 0;
        var num = nums[0];
        for(var j=1; j<4; j++){
            if(nums[j]>num){
                count++;
            }
        }
        foo(String(count));
    }
}
function foo(x) {
    process.stdout.write(x);   // without auto '\n' (newline)
    console.log();  // with auto '\n' (newline)
}

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())
//multiple integer construction->const [a,b,c]=integer array

function main() {
  let q = parseInt(readline());
  for (let i = 0; i < q; i++) {
    let input = readline().split(" ").map(Number);
    print(R(input));
  }
}

function R(arr) {
  let count = 0;
  for (let i = 1; i < arr.length; i++) {
    if (arr[i] > arr[0]) count++;
  }
  return count;
}

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;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}
var T = readline();
for(var qe=1;qe<=T;qe++) {
  //var n = readline()//.split(' ').map((x) => parseInt(x));
  var [a,b,c,d] = readline().split(' ').map((x) => parseInt(x));
  var ans = 0;
  if(b > a) ans++
  if(c > a) ans++
  if(d > a) ans++
  console.log(ans)
  //fs.appendFileSync('output.txt', ans+'\r\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;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var list = [];
		for(var i = 0; i < 4; i++){
			list.push({
				no : i,
				v : nextInt()
			});
		}
		list.sort(function(a,b){
			return b.v - a.v;
		});
		for(var i = 0; i < 4; i++){
			if(list[i].no == 0){
				myout(i);
				break;
			}
		}
	}
}

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

function solve(arr) {
    let ans = 0
    for (let i = 1; i < arr.length; i++) {
        if (arr[i] > arr[0]) ans++
    }
    return ans
}

"use strict";

  let t = +(readline());

  for(let i=0;i<t;i++){
     solve(readline().split(' '));
  }

  function solve(dist){
     let cnt=0;

     for(let i=1;i<4;i++){

       if( (dist[i]) > (dist[0]))cnt++;
     }

      print(cnt);
  }

"use strict";

  let t = +(readline());

  for(let i=0;i<t;i++){
     solve(readline().split(' '));
  }

  function solve(dist){
     let cnt=0;

     for(let i=1;i<4;i++){

       if( +dist[i] > +dist[0])cnt++;
     }
      print(dist[0]);
      print(cnt);
  }

"use strict";

  let t = +(readline());

  for(let i=0;i<t;i++){
     solve(readline().split(' '));
  }

  function solve(dist){
     let cnt=0;

     for(let i=1;i<4;i++){
       if( dist[i] > dist[0])cnt++;
     }

      print(cnt);
  }

"use strict";

  let t = +(readline());

  for(let i=0;i<t;i++){
     solve(readline().split(' '));
  }

  function solve(dist){
     let cnt=0;

     for(let i=1;i<4;i++){
       if( dist[i] < dist[0])cnt++;
     }

      print(cnt);
  }

const state = { data: [] };
const consume = (chunk) => {
  const chunk_string = chunk.toString()
  const split = chunk_string.split('\r\n')
  split.forEach(e => {
    if (e.length == 1) e = Number(e)
    if (e.length > 1) e = e.split(' ').map(Number)
    state.data.push(e)
  })
  state.input_counter++
}
const commit = (answer) => process.stdout.write(answer);
const main = (args) => {
  let { data } = state
  const size = data.shift()
  data = data.slice(0, size)
  const target = data.reduce((a, e, i) => [...a, e[0]], [])
  const sorted = data.map(e => Array.from(e).sort((a, b) => b - a))
  const results = sorted.map((e, i) => e.indexOf(target[i]))
  // console.log(results)
  results.forEach(e => commit(e + '\r\n'))
  return
};
process.stdin
  .on("data", consume)
  .on("end", main);

const state = { data: [] };
const consume = (chunk) => {
  const chunk_string = chunk.toString()
  const split = chunk_string.split('\r\n')
  split.forEach(e => {
    if (e.length == 1) e = Number(e)
    if (e.length > 1) e = e.split(' ').map(Number)
    state.data.push(e)
  })
  state.input_counter++
}
const commit = (answer) => process.stdout.write(answer);
const main = (args) => {
  const { data } = state
  const size = data.shift()
  const target = data.reduce((a, e, i) => [...a, e[0]], [])
  const sorted = data.map(e => Array.from(e).sort((a, b) => b - a))
  const results = sorted.map((e, i) => e.indexOf(target[i]))
  // console.log(results)
  results.slice(0, size).forEach(e => commit(e + '\r\n'))
  return
};
process.stdin
  .on("data", consume)
  .on("end", main);

const state = { data: [] };
const consume = (chunk) => {
  const chunk_string = chunk.toString()
  const split = chunk_string.split('\r\n')
  split.forEach(e => {
    if (e.length == 1) e = Number(e)
    if (e.length > 1) e = e.split(' ').map(Number)
    state.data.push(e)
  })
  state.input_counter++
}
const commit = (answer) => process.stdout.write(answer);
const main = (args) => {
  const { data } = state
  data.shift()
  const target = data.reduce((a, e, i) => [...a, e[0]], [])
  const sorted = data.map(e => Array.from(e).sort((a, b) => b - a))
  const results = sorted.map((e, i) => e.indexOf(target[i]))
  // console.log(results)
  results.forEach(e => commit(e + '\r\n'))
  return
};
process.stdin
  .on("data", consume)
  .on("end", main);

const state = { data: [] };
const consume = (chunk) => {
  const chunk_string = chunk.toString()
  const split = chunk_string.split('\r\n')
  split.forEach(e => {
    if (e.length == 1) e = Number(e)
    if (e.length > 1) e = e.split(' ').map(Number)
    state.data.push(e)
  })
  state.input_counter++
}
const commit = (answer) => process.stdout.write(answer);
const main = (args) => {
  const { data } = state
  data.shift()
  const target = data.reduce((a, e, i) => [...a, e[0]], [])
  const sorted = data.map(e => Array.from(e).sort((a, b) => b - a))
  const results = sorted.map((e, i) => e.indexOf(target[i]))
  commit(results.join('\r\n'))
};
process.stdin
  .on("data", consume)
  .on("end", main);

var state = { data: [] };
var element, i, j = null;
function consume(chunk) {
  try {
    var chunk_string = chunk.toString("utf-8");
    var split = chunk_string.split('\r\n');
    for (i = 0; i < split.length; i++) {
      element = split[i];
      if (element.length == 1) {
        element = parseInt(element);
      }
      if (element.length > 1) {
        element = element.split(' ');
        for (j = 0; j < element.length; j++) {
          element[j] = parseInt(element[j]);
        }
      }
      state.data.push(element);
    }
    return;
  } catch (error) {
    process.stdout.write(error.message);
  }
}
function commit(answer) {
  try {
    process.stdout.write(answer);
    return;
  } catch (error) {
    process.stdout.write(error.message);
  }
}
function main() {
  try {

    var data = state.data;
    var target = [];
    var results = [];
    var sorted = [];
    // data.reduce((a, e, i) => [...a, e[0]], []);
    // sorted.map((e, i) => e.indexOf(target[i]));
    //data.map(e => e.sort((a, b) => b - a));
    // results.forEach(e => commit(e + '\r\n'));
    data.shift();
    for (i = 0; i < data.length; i++) {
      element = data[i];
      target.push(element[0]);
    }
    for (i = 0; i < data.length; i++) {
      element = data[i];
      sorted.push(element.sort((a, b) => b - a));
    }
    for (i = 0; i < sorted.length; i++) {
      element = sorted[i];
      results.push(element.indexOf(target[i]));
    }
    for (i = 0; i < results.length; i++) {
      const element = results[i];
      commit(element + '\n');
    }
    return;
  } catch (error) {
    process.stdout.write(error.message);
  }
}
process.stdin
  .on("data", consume)
  .on("end", main);

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

const read = () => new Promise(res => {
    rl.on('line', (line) => res(line));
});

async function main()
{
    const n = await read();
    for (let i = 0; i < n; i++) {
        const line = await read();
        const [timur, ...rest] = line.split(' ').map((n) => parseInt(n));
        process.stdout.write(`${rest.filter(n => n > timur).length}`);
    }
}

main();