var t = parseInt(readline());

  function solve() {
    var n = parseInt(readline())
    var ans = 0;

    ans += Math.floor(Math.sqrt(n))
    var qubic = Math.floor(Math.cbrt(n))
    ans += qubic
    ans -= Math.floor(Math.sqrt(qubic))
    return ans
  }

  while (t--) {
    print(solve())
  }


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

  let ans = new Set(d.toLowerCase()).size;

  if (ans === 26) {
    console.log('YES');
  }
  else {
    console.log('NO');
  }

  c++;
});

rl.on('close', () => {

});


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

rl.on('line', (line) => {
    console.log(solution(line));
});

// Count the number of uppercase and lower case letters
// If numUpper > numLower turn everything into upper
// Else turn everything into lower
function solution(input) {
    const word = input.split('');
    let numUpper = 0, numLower = 0;
    for (let i = 0; i < word.length; i++) {
        if (word[i] === word[i].toUpperCase()) {
            numUpper++;
        } else {
            numLower++;
        }
    }

    if (numUpper > numLower) {
        return input.toUpperCase();
    } else {
        return input.toLowerCase();
    }
}


'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 print(s) {
  process.stdout.write(`${s}`);
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // input
  const a = readline().split(' ').map(x => parseInt(x));
  const max = Math.max(...a);
  let nr = 6 - max + 1;
  let dr = 6;

  let r = 6;
  while(r > 0) {
    if (nr % r === 0 && dr % r === 0) {
      nr = nr / r;
      dr = dr / r;
      break;
    }
    r--;
  }

 // output
  print(`${nr}/${dr}`);
}


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

rl.on('line', (d) => {
  const [n, k] = d.split(' ').map(BigInt);
  const ans = n / k;

  if (ans % 2n === 0n) {
    console.log('NO');
  }
  else {
    console.log('YES');
  }

});


const readline = require('readline');

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

rl.on('line', function(line){
	const b = parseInt(line);
	let counter = 0;
	const sqrt = Math.sqrt(b)
	for (let i = 2; i < sqrt; i++) {
		if (b % i === 0) { counter += 2; }
	}
	if (sqrt % 1 === 0) { counter++; }
	console.log(b === 1 ? 1 : counter + 2);
	rl.close();
});


const Fs = require('fs')

const content = Fs.readFileSync(0).toString()

const parse = (a) => {
  a = a.match(/(\d*) (\d*)/)
  return [a[1], a[2]]
}

const decrease = (num, k) => {
  if (k === 0) {
    return num
  }
  if (num % 10 === 0) {
    return decrease(num / 10, k - 1)
  }
  return decrease(num - 1, k - 1)
}

console.log(decrease(...parse(content)))


'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 readAsInt(){
  return parseInt(readline());
}

function readAsIntList(){
  return readline().split(' ').filter(i => i).map(i => parseInt(i));
}

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

function main() {
  for(let i = 0; i < 5; i++) {
    let x = readAsIntList().findIndex(n => n);
    if(x>-1) {
      let result = (x > 2 ? ((x+1) % 3) : 2 - x) + (i > 2 ? ((i+1) % 3) : 2 - i);
      console.log(result);
      return;
    }
  }
}


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

let input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  const count = parseInt(input[0], 10)
  let hash = []
  for (let a = 1; a <= count; a ++) {
    let index = hash.length === 0 ? 1 : hash.length - 1
    if (hash[index] === undefined) {
      hash.push([a])
    } else {
      hash[index].push(a)
    }
  }
  for (let a = 1; a < count - 1; a++) {
    for (let b = 0; b < count; b++) {
      const _prevLeftNum = b > 0 ? hash[a][b - 1] : 0
      const _prevTopNum = hash[a - 1][b]
      const all = _prevLeftNum + _prevTopNum
      if (hash[a] === undefined) {
        hash.push([all])
      } else {
        hash[a].push(all)
      }
    }
  }
  const lastResult = hash[hash.length - 1]
  console.log(hash[hash.length - 1][lastResult.length - 1])
})


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

var finalWord="";
var vowels=["A","O","Y","E","U","I"];
readline.question("",ans=>{
    for (let i = 0; i < ans.length; i++) {
         !vowels.includes(ans[i].toUpperCase())?finalWord+="."+ans[i].toLocaleLowerCase():void 0;
    }
    console.log(finalWord);
    readline.close();
})


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

readline.question('', str => {
  solution(str);
  readline.close();
});

function solution(str) {
  let i, j, count = 0;
  for(i = 0; i < str.length; i++) {
    for(j = i - 1; j >= 0; j--) {
      if (str[i] === str[j]) {
        break;
      }
    }
    if (j === -1) count++;
  }
  if (count % 2) {
    console.log("IGNORE HIM!");
    return;
  }
  console.log("CHAT WITH HER!");
  return;
}


const readline = require('readline');

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

function checkT(x, y, z) {
    if (x + y > z && x + z > y && y + z > x)
        return "T";
    if (x + y == z || x + z == y || y + z == x)
        return "S";
    return "I";
}

rl.on('line', (input) => {
    let temp = input.split(' ').map(item => parseInt(item));
    let a = temp[0], b = temp[1], c = temp[2], d = temp[3];
    if (checkT(a, b, c) == "T" || checkT(b, c, d) == "T" || checkT(a, c, d) == "T" || checkT(a, b, d) == "T")
        console.log("TRIANGLE");
    else if (checkT(a, b, c) == "S" || checkT(b, c, d) == "S" || checkT(a, c, d) == "S" || checkT(a, b, d) == "S")
        console.log("SEGMENT");
    else
        console.log("IMPOSSIBLE");
    rl.close();
});


const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});
const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  const nums = input[0].split(' ').map(x => parseInt(x));
  let [k, n, w] = nums;
  let realSum = 0, i = 1;

  while (w > 0) {
    realSum += k*i;
    i += 1; w -= 1;
  }

  if (n >= realSum) console.log(0)
  else console.log(realSum - n);
});


const readline = require('readline');

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

let input=[];

rl.on('line', line => {input.push(line.trim());
}).on('close', main);

function main() {
    let [n, k] = input[0].split(' ');
    const stdin = input[1].split(' ');

    const scores = stdin.map((stdin) => {
        return Number(stdin);
    });
    let count = 0;
    const thK = Number(k);
    scores.forEach(elm => {
        if (elm > 0 && elm >= scores[thK - 1]) {
            count++;
        }
    });
    console.log(count);
}


const readline = require("readline")

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

//init
let tempi = 0;
let tempj = 0;
let columnCounter = 0;
let rowCounter = 0;

let inputCounterRow = 0;

rl.on('line', input => {
        inputCounterRow++;
        let array = input.split(" ").map(Number);
        for(let j = 0; j < 5; j++){
            if(array[j] === 1){
                tempi = inputCounterRow - 1;
                tempj = j;

                //j loop row counter
                while( tempj != 2){
                    if(tempj > 2)
                        tempj--;
                    else
                        tempj++;

                    rowCounter++;
                }
                //j loop column counter.
                while(tempi != 2){
                    if(tempi > 2)
                        tempi--;
                    else
                        tempi++;

                    columnCounter++;
                }
            }
        }

       if(inputCounterRow === 5){
            console.log(rowCounter + columnCounter);
            rl.close();
       }

  });


//Insomnia cure

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

let inp = '';

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

process.stdin.on('end', () => {
    let lines = inp.split(EOL).map(c => +c);

    let gcd = (a, b) =>  {
    	if(b == 0)  {
    		return a;
    	}
    	return gcd(b, a % b);
    };

    let lcm = (a, b) => (a * b) / gcd(a, b);

    let thr = lines.slice(0, 4);

    let flg = 2;
    for(let i in thr)  {
        if(thr[i] < lines[4])  {
            flg = 0;
            break;
        }
        if(thr[i] == lines[4])  {
            flg = 1;
        }
    }
    if(flg == 2)  {
        process.stdout.write('0');
        return;
    }
    // if(flg == 1)  {
    //     process.stdout.write('1');
    //     return;
    // }

    let thrx = [];

    for(let i = 0; i < thr.length; i++)  {
    	let addflg = true;
    	for(let j = 0; j < thrx.length; j++)  {
    		if(thr[i] % thrx[j] == 0)  {
    			addflg = false;
    			break;
    		}
    		if(thrx[j] % thr[i] == 0)  {
    			thrx[j] = thr[i];
    			addflg = true;
    			break;
    		}
    	}
		if(addflg)  {
			thrx.push(thr[i]);
		}
    }

    let thrf = [thrx, [], [], []];
    for(let i = 0; i < thrx.length; i++)  {
    	for(let j = i + 1; j < thrx.length; j++)  {
    		let l1 = lcm(thrx[i], thrx[j]);
    		for(let k = j + 1; k < thrx.length; k++)  {
    			let l2 = lcm(l1, thrx[k]);
    			for(let l = k + 1; l < thrx.length; l++)  {
    				thrf[3].push(lcm(l2, thrx[l]));
    			}
    			thrf[2].push(l2);
    		}
    		thrf[1].push(l1);
    	}
    }

    let calc = (i) => Math.floor(lines[4] / i);

    let res = 0;

    for(let i = 0; i < thrf.length; i++)  {
    	let sum = 0;
    	for(let j in thrf[i])  {
    		sum += calc(thrf[i][j]);
    	}
    	res += (1 - ((i % 2) * 2)) * sum;
    }

    process.stdout.write(res + '');

    return;
});


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

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

    main();

})

function main(){
    n = inp[0].split(" ")[0]
    k = inp[0].split(" ")[1]

    let allscores = inp[1].split(" ").map(item=>{return parseInt(item)})

    let gecen = allscores.filter((item)=>{return item >= allscores[k-1]}).filter(item=>{return item>0})
    console.log(gecen.length)

}


const readline = require('readline');

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

var T, n, k;

rl.on("line", (line) => {
	var n = parseInt(line);
	console.log( (n > 2 && n % 2 == 0) ? "YES" : "NO" );
	rl.close();
});


//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');
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
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 l = one[2];
  var c = one[3];
  var d = one[4];
  var p = one[5];
  var nl = one[6];
  var np = one[7];
  var allB = k * l;
  var allS = c * d;
  myout(Math.min.apply(null, [Math.floor(allB / nl / n), Math.floor(p / np / n), Math.floor(allS / n)]));
}


let inputString = '';
let currentLine = 0;

const runMain = () => {
  inputString = inputString.trim().split('\n').map(string => string.trim());
  main();
  process.exit();
}
const readLine = () => inputString[currentLine++];

process.stdin.on('data', inputStdin => inputString += inputStdin);
process.stdin.on('end', runMain);
process.on('SIGINT', runMain);

function main() {
  const [n, t] = readLine().split(' ').map(num => Number(num));
  const str = readLine().split('');
  for (let i = 0; i < t; i++) {
    let j = 0;
    while (j < n - 1) {
      if (str[j] === 'B' && str[j + 1] === 'G') {
        str[j] = 'G';
        str[j + 1] = 'B';
        j++;
      }
      j++;
    }
  }
  console.log(str.join(''));
}


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

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

function isPrime(x) {
	let s = Math.sqrt(x);
	let i = 2;
	while (i <= s) {
		if (x % i === 0) {
			return false;
		}
		i++;
	}
	return true;
}

function main() {
	let [n, k, l, c, d, p, nl, np] = readLine()
		.split(' ')
		.map(x => x >> 0);

	let bottle = Math.floor((k * l) / nl);
	let limes = c * d;
	let salt = Math.floor(p / np);

	let res = Math.floor(Math.min(bottle, limes, salt) / n);
	console.log(res);
}


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

let l = 0;
rl.on('line', (input) => {
    rl.close();
    let inp = input.split(" ").map(x => parseInt(x))
    let ct = 0
    let s = inp[1]
    for (let i = inp[0]; i >= 0 && s > 0; i--) {
        ct += Math.floor(s / i)
        s = s - i * Math.floor(s / i)
    }
    console.log(ct)
    return 0;
});


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

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
   const arrStr = input[0].split('');
      const b = input[1].split('').join('').split('');

      for (let i = 0; i < arrStr.length; i++){
        for (let n = 0; n < b.length; n++){
          if( arrStr[i] == b[n]){
            console.log('yes');
            return;
          }

        }

        }

     console.log('no');

});


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

rl.on('line', (data) => {
  let [n, k, l, c, d, p, nl, np] = data.split(' ').map(Number);

  let x = Math.floor(k * l / nl);
  let y = c * d;
  let z = Math.floor(p / np);
  let ans = Math.floor(Math.min(x, y, z) / n);

  console.log(ans);
});


const solve = (n) => {
    let res = 1;
    for (let i = 1; i <= n; i++) {
        res *= i;
    }
    res /= n;
    res /= (n >> 1);
    return res;
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    rl.on('line', (line) => {
        console.log(solve(Number(line)));
    });
};

main()


var readline = require('readline')

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

rl.on('line', function(line){
  console.log(theatreSquare(line))
})

// watermelon
// function watermelon(line) {
//   line = parseInt(line)
//   return line % 2 ? 'NO' : (line === 2 ? 'NO' : 'YES')
// }

// theatreSquare
function theatreSquare(line) {
  var arr = line.split(' ')
  return Math.ceil(arr[0] / arr[2]) * Math.ceil(arr[1] / arr[2])
}


function main() {
    // write code here:
    const n = Number(stdin[0]);
    var arr = stdin[1].split(' ').map(Number);
    var obj = {};
    var times = [];
    for (let i = 0; i < n; i++) {
        if (obj[arr[i]]) {
            obj[arr[i]]++;
        } else {
            obj[arr[i]] = 1;
        }
    }
    for (var key in obj) {
        times.push(obj[key]);
    }
    console.log(Math.max(...times));
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {
    stdin.push(line);
});
rl.on('close', main);


function solution(arr){
    for (var i = 1; i < arr.length; i++){
        if (arr[0][0] == arr[i][0] || arr[0][1] == arr[i][1]){
            return "YES"
        }
    }
    return "NO"
}
process.stdin.addListener("data", (data)=>{
    var arr = data.toString().trim().split(/\s+/)

    console.log(solution(arr))
})


const readline = require("readline")

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let word;
let currentChar = "a".charCodeAt(0)
let rotations = 0;

rl.on("line", (input) => {
    if (!word) {
        word = input.split(" ").toString();
    }
    if (word) {
        for (let index = 0; index < word.length; index++) {
            let temp = Math.abs((word.charCodeAt(index) - currentChar))
            if (temp > 13) {
                rotations += (25 - (temp - 1))
                currentChar = word.charCodeAt(index)
            }
            if (temp <= 13) {
                currentChar = word.charCodeAt(index)
                rotations += temp
            }
        }
        console.log(rotations)
        rl.close();

    }
})


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

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

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

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

const getDigits = (x) => {
    let digits = new Array(10).fill(false);
    let len = 0;
    while (x) {
        len++;
        digits[x % 10n] = true;
        x /= 10n;
    }
    return [digits, len];
}

const getLen = (x) => {
    let str = x.toString(10);
    return str.length;
}

const calc = (t)=>{
    /* read */
    let [n, x] = readline().split(' ');
    n = +n;
    x = BigInt(x);

    let arr = new Array(10).fill(x);

    let q = [BigInt(x)];
    let visited = new Set([x]);

    for (let steps = 1; steps <= 1000000; steps++) {
        let maxlen = 0;
        let newq = [];
        for (const num of q) {
            let [digits, len] = getDigits(num);
            if (len === n) return steps - 1;
            if (len > maxlen) maxlen = len;
            if (len < maxlen - 1) continue;
            for (let i = 9; i > 1; i--) {
                if (!digits[i]) continue;
                let newNum = num * BigInt(i);
                if (visited.has(newNum)) continue;
                if (getLen(newNum) > n) continue;
                newq.push(newNum);
                visited.add(newNum);
            }
        }

        if (newq.length === 0) return -1;
        // if (q.length === 1 && newq.length === 1 && q[0] === newq[0]) return -1;
        newq.sort((x, y) => {
            if (y > x) return 1;
            if (x > y) return -1;
            return 0;
        });
        q = newq;
    }

    return -1;
};

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


const {EOL} = require('os')

let input = ''
process.stdin.on('data', s => input += s)
process.stdin.on('end', () => {
    let [number, times] = input.split(" ").map(element => parseInt(element));
    for(let i = 0; i < times; i++) {
        number = number % 10 == 0 ? number / 10 : number - 1;
    }
    console.log(number);
})


function main(input) {
    //Enter your code here
    let [target, counter] = input.split(' ');
    for(let i = 0; i <counter;  i++ ) {
        if(target % 10 === 0) {
            target /= 10;
        } else {
            target -= 1;
        }
    }
    console.log(target);
}

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

process.stdin.on("data", function (input) {
    stdin_input += input;
});

process.stdin.on("end", function () {
   main(stdin_input);
});


const readline = require('readline');

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

var ans=0,met=false;

rl.on('line', (input) => {
    let temp=input.match(/B/g);
   // console.log("temp= "+temp);
    if(/*temp.length == 8*/ input=="BBBBBBBB")
       ans++;
    else if(!met){
      if(temp!=null)
          ans+=temp.length;
       met=true;
    }

  }).on('close',function(){
      console.log(ans);
  });


let i = ''

function main(w) {
    // let dem = 0;
    // for(let i = 2; i <= w ; i++){
    //     if(w % i == 0){
    //         dem++;
    //     }
    // };
    //
    // if(dem >= 2){
    //     console.log("YES");
    // }else {
    //     console.log("NO");
    // }
    if(w % 2 == 0 && w > 2){
        console.log("YES");
    }else {
        console.log("NO");
    }
}
// main(6);

process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL)
    const line1Array = lines[0].split(' ').map(x => parseInt(x))
    const w = line1Array[0]

    main(w);
})


//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");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return 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 s = next().split("+").map(Number);
  s.sort(function(a,b){
  	return a - b;
  });
  myout(s.join("+"));
}


const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});
const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  const name = input[0];
  const set = new Set();
  for (let i = 0; i < name.length; i += 1) set.add(name[i]);

  console.log(
    set.size % 2 === 0 ?
    "CHAT WITH HER!" : "IGNORE HIM!"
    )
});


function main() {
    // write code here:
    var m=Number(stdin[0]);
    var n=1;
    for(var i=1;i<=m;i++){
        n+=4*(i-1);
    }
    console.log(n);
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {stdin.push(line);});
rl.on('close', main);


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

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let n = +input;
   const banknotes = [1, 5, 10, 20, 100];

    let min = 0;

    for (let i = banknotes.length - 1; i >= 0; --i) {
      min += Math.floor( n/ banknotes[i]);

      n -= Math.floor(n / banknotes[i]) * banknotes[i];
     }
    console.log( +min);

});


let i = '';

process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var t = lines[0]
    for(j = 1; j <= t; j++){
        var s = 1
        var n = lines[j]
        for(k = 1; k < n; k++){
            s +=  s + 1
        }
        console.log(s   )
    }
});


'use strict'
const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin
});
var MN= [], sum = 0, tt =0;
rl.question('', (nb) => {
    MN = nb.split(' ');
    tt = MN[0]*MN[1];
    console.log(parseInt(tt/2));
    rl.close();
});


function ProblemSolver() {
    this.HAS_TEST_CASES = false ;
    this.INPUT_FILE_NAME = "sample.in" ;
    this.OUTPUT_FILE_NAME = "sample.out" ;
    this.DO_OUTPUT_TO_FILE = false ;
    this.CLEAR_ARRAY_PER_CASE = false ;

    this.solveCase = function() {
        var res , i , j , fl , cn , a , b , c , d ;
        res = 0 ;
        a = 9 ;
        b = 10 ;
        c = 1 ;
        d = 9 ;
        for( i = 1 ; i <= 11 ; i++ ) {
            if( this.n >= a ) {
                res += d * c ;
            }
            else {
                res += c * ( this.n - Math.floor( a / 10 ) ) ;
                break ;
            }
            a = ( a * 10 ) + 9 ;
            b = ( b * 10 ) ;
            c++ ;
            d = ( d * 10 ) ;
        }
        print( res ) ;
    } ;

    this.init = function() {
        this.lim1 = 100010 ;
        this.lim2 = 110 ;
        this.cc = 1 ;
        this.ind = 1 ;
        this.n = 0 ;
        this.cn = 0 ;
        this.declareAndFillArrays() ;
    } ;

    this.getInput = function( irObj ) {
        var hasMoreInput , i ;
        hasMoreInput = true ;
        try {
        	this.n = irObj.nextInt() ;
        }
        catch( ex ) {
            hasMoreInput = false ;
        }
        return hasMoreInput ;
    } ;

    this.clearArraysPerCase = function() {
        var i ;
        this.arr = new Array() ;
        this.adjList = new Array() ;
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.arr.push( 0 ) ;
            this.adjList.push( new Array() ) ;
        }
    } ;

    this.clearPerCase = function() {
        this.cn = 0 ;
        this.cc++ ;
        if( this.CLEAR_ARRAY_PER_CASE == true ) {
            this.clearArraysPerCase() ;
        }
    } ;

    this.declareAndFillArrays = function() {
        var i , j ;
        this.srr = new Array() ;
        this.vis = new Array() ;
        this.arr = new Array() ;
        this.brr = new Array() ;
        this.memo = new Array() ;
        this.done = new Array() ;
        this.adjList = new Array() ;
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.srr.push( '' ) ;
            this.vis.push( 0 ) ;
            this.arr.push( 0 ) ;
            this.brr.push( 0 ) ;
            this.adjList.push( new Array() ) ;
        }
        for( i = 0 ; i < this.lim2 ; i++ ) {
            this.memo.push( new Array() ) ;
            this.done.push( new Array() ) ;
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( -1 ) ;
                this.done[ i ].push( 0 ) ;
            }
        }
    } ;

    this.init() ;
}

function InputReader() {
    var self = this ;
    this.allLines = new Array() ;
    this.currrentLineNumber = 0 ;
    this.currrentCharacterIndex = 0 ;
    this.callBackFunction = null ;
    this.parentContext = null ;

    this.readAllLines = function() {
        var singleLine ;
        while( true ) {
            try {
                singleLine = readline() ;
                if( singleLine == null ) {
                    break ;
                }
            }
            catch( ex ) {
                break ;
            }
            this.allLines.push( singleLine ) ;
        }
    } ;

    this.readAllLinesFromRhino = function() {
        var brObj , line ;
        importPackage( java.io ) ;
        importPackage( java.lang ) ;
        brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;
        this.allLines = [] ;
        while( true ) {
            line = brObj.readLine() ;
            if( line == null ) {
                break;
            }
            this.allLines.push( line ) ;
        }
    } ;

    this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {
        self.chunkData += chunk ;
    } ;

    this.readEndFromNodeJsJudgeServer = function() {
        self.parseRawData( self.chunkData ) ;
        self.parentContext.runCases() ;
    } ;

    this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {
        this.parentContext = parentContext ;
        process.stdin.resume() ;
        process.stdin.setEncoding( 'utf8' ) ;
        this.chunkData = '' ;
        process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;
        process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;
    } ;

    this.parseRawData = function( data ) {
        var len , i , currentString ;
        len = data.length ;
        currentString = '' ;
        this.allLines = [] ;
        for( i = 0 ; i < len ; i++ ) {
            if( data[ i ] == '\r' ) {
            }
            else if( data[ i ] == '\n' ) {
                this.allLines.push( currentString ) ;
                currentString = '' ;
            }
            else {
                currentString += data[ i ] ;
            }
        }
        if( currentString != '' ) {
            this.allLines.push( currentString ) ;
        }
    } ;

    this.readAllLinesFromFile = function( inputFileName ) {
        var currentDirectory , fsObj , inputFilePath , rawData ;
        fsObj = require( 'fs' ) ;
        currentDirectory = __dirname ;
        if( currentDirectory.indexOf( 'D:' ) != -1 ) {
            //on windows
            inputFilePath = currentDirectory + '\\' + inputFileName ;
        }
        else {
            //on linux
            inputFilePath = currentDirectory + '/' + inputFileName ;
        }
        rawData = fsObj.readFileSync( inputFilePath , "utf8" ) ;
        this.parseRawData( rawData ) ;
    } ;

    this.next = function( flag ) {
        var len , i , startIdx , res , endIdx ;
        if( flag == 0 ) {
            if( this.currrentCharacterIndex != 0 ) {
                this.currrentLineNumber++ ;
                this.currrentCharacterIndex = 0 ;
            }
            res = '' ;
            len = this.allLines[ this.currrentLineNumber ].length ;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;
            }
            this.currrentLineNumber++ ;
            this.currrentCharacterIndex = 0 ;
            return res ;
        }
        while( true ) {
            if( this.currrentLineNumber >= this.allLines.length ) {
                throw new Error( 'No more tokens available!' ) ;
            }
            startIdx = -1 ;
            len = this.allLines[ this.currrentLineNumber ].length ;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {
                    startIdx = i ;
                    break ;
                }
            }
            if( startIdx == -1 ) {
                this.currrentLineNumber++ ;
                this.currrentCharacterIndex = 0 ;
                continue ;
            }
            res = '' ;
            endIdx = len - 1 ;
            for( i = startIdx ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {
                    endIdx = i ;
                    break ;
                }
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {
                    res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;
                }
                else {
                    res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;
                }
            }
            this.currrentCharacterIndex = endIdx ;
            if( endIdx == len - 1 ) {
                this.currrentLineNumber++ ;
                this.currrentCharacterIndex = 0 ;
            }
            return res ;
        }
    } ;

    this.nextInt = function() {
        return parseInt( this.next( 1 ) ) ;
    } ;

    this.nextDouble = function() {
        return parseFloat( this.next( 1 ) ) ;
    } ;

    this.nextString = function() {
        return this.next( 1 ) ;
    } ;

    this.nextLine = function() {
        return this.next( 0 ) ;
    } ;
}

function FileOutputHandler() {
    this.resultantStringArray = new Array() ;

    this.addNewLine = function( newString ) {
        this.resultantStringArray.push( newString ) ;
    } ;

    this.clearPercase = function() {
        this.resultantStringArray = new Array() ;
    } ;

    this.flushOutOutputToFile = function( outputFileName ) {
        var i , sz , res , currentDirectory , fsObj , outputFilePath ;
        res = '' ;
        sz = this.resultantStringArray.length ;
        for( i = 0 ; i < sz ; i++ ) {
            if( i != 0 ) {
                res += '\n' ;
            }
            res += this.resultantStringArray[ i ] ;
        }
        fsObj = require( 'fs' ) ;
        currentDirectory = __dirname ;
        if( currentDirectory.indexOf( 'D:' ) != -1 ) {
            //on windows
            outputFilePath = currentDirectory + '\\' + outputFileName ;
        }
        else {
            //on linux
            outputFilePath = currentDirectory + '/' + outputFileName ;
        }
        fsObj.writeFileSync( outputFilePath , res ) ;
        this.clearPercase() ;
    } ;
}

function CodeExecutioner() {
    this.irObj = new InputReader() ;
    this.psObj = new ProblemSolver() ;
    this.fohObj = new FileOutputHandler() ;

    this.runCases = function() {
		var testCases , hasMoreTestCases , i ;
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt() ;
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase() ;
                this.psObj.getInput( this.irObj ) ;
                this.psObj.solveCase() ;
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase() ;
                hasMoreTestCases = this.psObj.getInput( this.irObj ) ;
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase() ;
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;
        }
    } ;

    this.detectEnvironmentType = function() {
        var environmentType = null ;
        try {
            if( importPackage != null ) {
                environmentType = 'rhino' ;
            }
        }
        catch( ex1 ) {
            try {
                //for nodejs local server check
                if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {
                    environmentType = 'local-node-js' ;
                }
                else {
                    environmentType = 'server-node-js' ;
                }
            }
            catch( ex2 ) {
                try {
                    if( readline == null || typeof( readline ) != 'function' ) {
                        environmentType = 'server-node-js' ;
                    }
                    else {
                        try {
                            if( Map != null ) {
                                environmentType = 'spider-monkey' ;
                            }
                            else {
                                environmentType = 'javascript-v8' ;
                            }
                        }
                        catch( ex3 ) {
                            environmentType = 'javascript-v8' ;
                        }
                    }
                }
                catch( ex3 ) {
                    environmentType = 'server-node-js' ;
                }
            }
        }
        return environmentType ;
    } ;

    this.configureStreamsAndReadInput = function() {
        var localContext , isNodeJsJudgeServer , environmentType ;
        isNodeJsJudgeServer = false ;
        environmentType = this.detectEnvironmentType() ;
        if( environmentType == 'local-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log ;
                }
            }
            catch( ex ) {
                print = console.log ;
            }
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj ;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments ) ;
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;
            this.runCases() ;
        }
        else if( environmentType == 'server-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log ;
                }
            }
            catch( ex ) {
                print = console.log ;
            }
            this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;
        }
        else if( environmentType == 'javascript-v8' ) {
            this.irObj.readAllLines() ;
            this.runCases() ;
        }
        else if( environmentType == 'rhino' ) {
            this.irObj.readAllLinesFromRhino() ;
            this.runCases() ;
        }
        else if( environmentType == 'spider-monkey' ) {
            this.irObj.readAllLines() ;
            this.runCases() ;
        }
    } ;

    this.configureStreamsAndReadInput() ;
}

new CodeExecutioner() ;


const stdin = process.stdin;
stdin.setEncoding("utf8");
let data = "";
stdin.on("data", function(chunk) {
  data += chunk;
});
stdin.on("end", function() {
  const inputs = data.split(/[\n\r]+/);
  const [n, m, a] = splitAndConvert(inputs[0]);
  const result = solve(n, m, a);
  console.log(result);
});

function splitAndConvert(stringOfNumbers, numOfValid) {
  return stringOfNumbers
    .split(" ")
    .slice(0, numOfValid)
    .map(function(num) {
      return parseInt(num);
    });
}

function solve(n, m, a) {
  return Math.ceil(n / a) * Math.ceil(m / a);
}


// node template.js < A-small.in > A-small.out

function main() {
    var tests = 1;
    tests = nextInt();

    for (let t = 1; t <= tests; t++) {
        let N = nextInt();

        let result = -1;
        for(let i = 2; i*i <= N; i++) {
            if (N % i === 0) {
                result = i;
                break;
            }
        }
        if (result !== -1) {
            let b = (result-1)*(N/result);
            let a = N-b;
            print(a + " " + b);
        } else {
            print(1 + " " + (N-1));
        }

    }
}

// ------- Template ------------------
function newTensor(dimensions, value) {
    let res = [];
    let dim = dimensions[0], subdim = dimensions.slice(1);
    if (subdim.length == 0) {
        for(let i = 0; i < dim; i++) {
            res.push(value);
        }
    } else {
        for(let i = 0; i < dim; i++) {
            res.push(newTensor(subdim, value));
        }
    }
    return res;
}

if (!String.prototype.startsWith) {
    Object.defineProperty(String.prototype, 'startsWith', {
        value: function(search, rawPos) {
            var pos = rawPos > 0 ? rawPos|0 : 0;
            return this.substring(pos, pos + search.length) === search;
        }
    });
}
if (!String.prototype.endsWith) {
    String.prototype.endsWith = function(search, this_len) {
        if (this_len === undefined || this_len > this.length) {
            this_len = this.length;
        }
        return this.substring(this_len - search.length, this_len) === search;
    };
}

var curTokens = [], curToken = 0;

function next() {
    while (curToken >= curTokens.length) {
        curTokens = readline().split(/[\s]+/);
        curToken = 0;
    }
    return curTokens[curToken++];
}

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

// code for nodejs
var inputBuffer = '', curLine = 0;

function readline() {
    return inputBuffer[curLine++];
}

function print(data) {
    process.stdout.write(data + '\n');
}

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

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

process.stdin.on('end', function () {
    inputBuffer = inputBuffer.split(/[\s]+/);
    main();
});


'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.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

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

function main() {
    let nt = readLine().split(' ');
    let n = parseInt(nt[0]);
    let t = parseInt(nt[1]);
    let queue = readLine().split('');
    for (var i = 0; i < t; i++) {
        for (var j = 0; j < queue.length; j++) {
            if (queue[j] == 'G' && queue[j - 1] == 'B') {
                queue[j] = 'B';
                queue[j - 1] = 'G';
                j++;
            }
        }
    }
    console.log(queue.join(''));

}


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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

const readLine=()=> inputString[currentLine++];
/* ================================================
           Main Solution Starts Here
===================================================*/

const main=()=>{
	let [k,n,w]=readLine().split(" ").map(n=>+n)
	let price=0
	for(let i=1;i<=w;i++)
		price+=(i*k)

	price<=n ? console.log(0) : console.log(price-n)
}


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

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

function isPrime(x) {
	let s = Math.sqrt(x);
	let i = 2;
	while (i <= s) {
		if (x % i === 0) {
			return false;
		}
		i++;
	}
	return true;
}

function main() {
	let hoes = readLine()
		.split(' ')
		.map(x => x >> 0);

	let counter = {};
	let spend = 0;
	for (let i = 0; i < 4; ++i) counter[hoes[i]] = (counter[hoes[i]] || 0) + 1;

	Object.entries(counter).forEach(([k, v]) => {
		spend += v - 1;
	});
	console.log(spend);
}


'use strict'
const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin
});
var sec, fst, win = 0,
  arr = [],
  arr2 = [],
  i, n, k;
rl.question('', (fst) => {
  rl.on('line', (sec) => {
    arr2 = fst.split(' ');
    n = Number(arr2[0]);
    k = Number(arr2[1]);
    arr = sec.split(' ');
    for (i = 0; i < k; i++) {
      if (arr[i] > 0) {
        win++;
      }
    }
    while ((arr[k - 1] === arr[k]) && (k < n) && (arr[k - 1] != 0)) {
      if (arr[k] > 0) {
        k++;
        win++;
      }
    }
    console.log(win);
    rl.close();
  });
});


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

let stdinInput = '';

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

process.stdin.on('end', () => {
  main(stdinInput);
})

function main(data) {
  data = data.split('\n');
  const first = data[0].toLowerCase();
  const second = data[1].toLowerCase();
  if (first === second) console.log(0);
  else if (first < second) console.log(-1);
  else console.log(1);
}


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

function main() {
    let word = readLine();
    if (word.includes('H') || word.includes('Q') || word.includes('9')) {
        console.log('YES');
    } else {
        console.log('NO');
    }
}


const input = [];

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

RL.on('line', (line) => {
    input.push(line);
});

RL.on('close', () => {
  let [k, r] = input[0].split(' ').map(x => parseInt(x));
  let lastNum = k % 10;

  if (lastNum === r || lastNum === 0) {
    console.log(1);
  } else {
    let i = 1; let f = k;
    while (lastNum !== r && lastNum !== 0) {
      i += 1;
      f += k; lastNum = f % 10;
    }
    console.log(i);
  }
});


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

rl.on('line', (line) => {
  var [n,m,a]=line.split(' ');
  var ans=Math.ceil(n/a)*Math.ceil(m/a);
  console.log(ans);
});


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

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  const [n, a, b, c] = input[0].split(' ').map(x => parseInt(x));

  let max = 0;
  for (let i = 0; i <= 4000; i += 1) {
    for (let j = 0; j <= 4000; j += 1) {
      let ax = i*a, by = j*b;
      let z = (n - ax - by);

      if (z > 0 && z % c === 0) {
        z /= c;
        if (i + j + z > max) max = i + j + z;
      }
      if (ax + by === n) {
        if (i + j > max) max = i + j;
      }
    }
  }

  console.log(max);

});


// Alternative
// https://www.npmjs.com/package/competitive-programming-js
"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++]; }
const println = (x = "") => process.stdout.write(String(x) + "\n");
const print = x => { process.stdout.write(String(x)); }
// >>>>>>>>>>>>> Main starts here <<<<<<<<<<<<<<

function main() {
    let s = readline();
    let cur = s[0];
    let cnt = 1;
    let f = 0;
    for (let i = 1; i < s.length; ++i) {
        if (s[i] === cur) { cnt += 1; }
        else {
            cnt = 1;
            cur = s[i];
        }
        if (cnt >= 7) f = 1;
    }
    println(f ? "YES" : "NO");
}


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

let currentLine = 0;
let inputString = "";

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

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

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

/******** Main function*************/

function main() {
  var s = readLine();

  function isLowerCase(str) {
    return str == str.toLowerCase() && str != str.toUpperCase();
  }

  var lCount = 0,
    uCount = 0;

  for (var i = 0; i < s.length; i++) {
    if (isLowerCase(s[i])) {
      lCount++;
    } else {
      uCount++;
    }
  }

  var str = "";

  if (lCount > uCount || lCount == uCount) str = s.toLowerCase();

  if (lCount < uCount) str = s.toUpperCase();

  console.log(str);
}


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

function main() {
    let k = parseInt(readLine());
    let l = parseInt(readLine());
    let m = parseInt(readLine());
    let n = parseInt(readLine());
    let d = parseInt(readLine());

    let result = d;

    if (k === 1 || l === 1 || m === 1 || n === 1) {
        console.log(result);
        return;
    }

    for (let i = 1; i <= d; i++) {
        if (i % k !== 0 && i % l !== 0 && i % m !== 0 && i % n !== 0) {
            result--;
        }
    }
    console.log(result);
}


var rl=require('readline');
var dd=rl.createInterface(process.stdin,process.stdout);

var s=[];

dd.question('',function(x){

    s=x.split(' ').map(Number);
    dd.close();
})

dd.on('close',function () {
    console.log(Math.ceil(s[0]/s[2])*Math.ceil(s[1]/s[2]));
    process.exit();
})


const readline = require('readline')

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

async function getNumbers() {
	let str = ''
	return new Promise((res,rej)=>{
		rl
		.question(str,ans=>res(ans))
	})
}

function subtraction(n,k){

	if(k == 0)return n

	let resedue = n%10

	if( resedue > 0 ){
		--n
		--k
		return subtraction(n,k)
	}
	else{
		--k
		return subtraction(n/10,k)
	}

}
async function main() {
	let nums = await getNumbers()
	nums = nums.trim().split(' ')
	rl.close()

	console.log(subtraction(...nums))

}

main()


'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 str = readline();
    let upperCase = 0;
    let lowerCase = 0;
    for (let i = 0; i < str.length; i++) {
        if (str[i] === str[i].toUpperCase()) {
            upperCase++;
        }
        else {
            lowerCase++;
        }
    }

    if (upperCase > lowerCase)
        console.log(str.toUpperCase())
    else
        console.log(str.toLowerCase())

    return;
}


#!/usr/bin/env nodejs

// 4A - Watermelon

function main(stdin) {
  const n = parseInt(stdin);
  console.log(n % 2 === 0 && n >= 4 ? "YES" : "NO");
}

main(require("fs").readFileSync(0, "utf-8"));


'use strict';

let inputString = '';

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

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

function solution(len, A) {
    var freqArr = {};
    var alphaBet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toLowerCase();
    var A = A.toLowerCase();
    for (let i = 0; i < A.length; i++) {
        if (!freqArr[A[i]])
            freqArr[A[i]] = 1;
        else {
            freqArr[A[i]]++;
        }
    }
    for (let i = 0; i < alphaBet.length; i++) {
        if (!freqArr[alphaBet[i]]) {
            console.log("NO");
            return;
        }

    }
    console.log("YES");
    return;
}


const input = [];

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

RL.on('line', (line) => {
    input.push(line);
});

RL.on('close', () => {
  const str = input[0].toLowerCase();
  const bad = new Set(); bad.add('a').add('o').add('y').add('e').add('u').add('i');

  const answer = [];
  for(let i = 0; i < str.length; i += 1) {
    if (!bad.has(str[i])) {
      answer.push('.'); answer.push(str[i]);
    }
  }

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


function main(input) {
    const lines = input.split(EOL);
    const line1 = lines[0].split(' ');
    let n = line1[0] * 1;
    let k = line1[1] * 1;

    while (k--) {
        if (n < 2) break;
        n % 10 === 0 ? n /= 10 : --n;
    }

    console.log(n);
}

const { EOL } = require('os')
process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", (input) => _input += input);
process.stdin.on("end", () => main(_input));


// https://codeforces.com/problemset/problem/50/A

function main(stdin) {
  const [m, n] = stdin[0].split(' ').map(Number)
  process.stdout.write(Math.floor(m * n / 2) + '')
}

// Handle standard input
process.stdin.resume()
process.stdin.setEncoding('utf-8')

let inputString = ''

process.stdin.on('data', (inputStdin) => inputString += inputStdin)
process.stdin.on('end', () =>
  main(inputString.trim().split('\n').map(s => s.trim())))


const readline = require("readline");

function substract(number, iterations) {

    let result = number;
    while (iterations > 0) {
        const lastDigit = getLastDigit(result);
        if (lastDigit == 0) {
            result = removeLastDigit(result);
        } else {
            result -= 1;
        }

        iterations--;
    }

    return result;
}

function getLastDigit(number) {
    const { numberAsString, numberLength } = getNumberStringValues(number);
    const lastDigitAsString = numberAsString[numberLength - 1];
    return parseInt(lastDigitAsString);
}

function removeLastDigit(number) {
    const { numberAsString, numberLength } = getNumberStringValues(number);
    return parseInt(numberAsString.slice(0, numberLength - 1));
}

function getNumberStringValues(number) {
    const numberAsString = number.toString()
    const numberLength = numberAsString.length;
    return { numberAsString, numberLength }
}

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

rl.question("", function (line) {
    const input = line.split(" ");
    const number = parseInt(input[0]);
    const iterations = parseInt(input[1]);
    console.log(substract(number, iterations));

    rl.close();
});


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

let l = 0;
let hand = []
rl.on('line', (input) => {
    if (l === 0) {
        hand = input.split("")
    }
    else {
        rl.close();
        let arr = input.split(" ").map(x => x.split(""))
        let can = false
        for (let i = 0; i < arr.length; i++) {
            if (hand[0] === arr[i][0] || hand[1] === arr[i][1]) {
                can = true
                break
            }
        }
        if (can)
            console.log('YES')
        else
            console.log('NO')
        return 0;
    }
    l++
})


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

rl.on('line', (d) => {
  if (counter === 0) {
    S = d;
  }
  else {
    T = d;

    let ans = 'YES';
    let j = 0;
    for (let i = T.length - 1; i >=0; i--) {
      if (T[i] !== S[j]) {
        ans = 'NO';
        break;
      }
      j++;
    }

    console.log(ans);
  }

  counter++;
});


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);
  let ans = 0;
  let prev = -1;

  for (let i = 0; i < arr.length; i++) {
    if (prev !== arr[i] && arr[i] !== 0) {
      ans++;
      prev = arr[i];
    }
  }

  console.log(ans);

  c++;
});


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

rl.on("line", (d) => {
  console.log(25);
});


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

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

function main() {
	let [n, k] = readLine()
		.split(' ')
		.map(x => x >> 0);
	let arr = readLine()
		.split(' ')
		.map(x => x >> 0);

	if (arr[0] === 0) {
		console.log(0);
		return;
	}

	let score = 0;

	for (let i = 0; i < n; i++) {
		if (arr[i] <= 0) {
			break;
		}

		if (i <= k - 1) {
			score++;
		} else {
			if (arr[i] === arr[k - 1]) {
				score++;
			} else {
				break;
			}
		}
	}

	console.log(score);
}


let fs = require('fs');

let txt = fs.readFileSync(0, "utf-8").split(/[\n\r]/).filter(data => data.length > 0);

for (let i = 0; i < txt.length; i++) {
    console.log(4 - [...new Set(txt[i].split(/[ ]/))].length);

}


require('readline').createInterface({
  input: process.stdin,
}).on('line', (line) => {
  const split = line.split(' ')
  let num = parseInt(split[0])
  const count = parseInt(split[1])
  for (let i = 0; i < count; i++) {
    if (num % 10 === 0) {
      num /= 10
    } else {
      num -= 1
    }
  }
  process.stdout.write(num + '\n')
})


let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let str1 = readLine();
  let str2 = readLine();
  let [count1, count2] = [0, 0];
  const len = Math.max(str1.length, str2.length);
  str1 = str1.toLowerCase();
  str2 = str2.toLowerCase();

  if (str1 === str2) {
    console.log(0);
    return;
  }

  for (let i = 0; i < len; i++) {
    if (str1[i] !== str2[i]) {
      count1 = str1[i].charCodeAt(0);
      count2 = str2[i].charCodeAt(0);
      break;
    }
  }

  if (count1 < count2) console.log(-1);
  else console.log(1);
}


const black = 'B';
const white = 'W';

function is_row_all_black(row) {
  for (const sqr of row) {
    if (sqr === black) {
      // do nothing ...
    } else {
      return false;
    }
  }
  return true;
}

function is_column_all_black(rows, i) {
  for (const row of rows) {
    const sqr = row[i];
    if (sqr === black) {
      // do nothing ...
    } else {
      return false;
    }
  }
  return true;
}

function solve(rows) {
  let result = 0;
  for (const row of rows) {
    result = result + (is_row_all_black(row) ? 1 : 0);
  }
  if (result === rows.length) {
    // do nothing ...
  } else {
    for (let i = 0; i < rows.length; i = i + 1) {
      result = result + (is_column_all_black(rows, i) ? 1 : 0);
    }
  }
  return result;
};

function main(lines) {
  const rows = [];
  for (const line of lines) {
    const t = line.trim();
    if (t.length > 0) {
      rows.push(t);
    }
  }
  const result = solve(rows);
  console.log(result);
};

async function processLinesFromStream(rs, pf) {
  const content = [];
  rs.setEncoding("utf-8");
  for await (let chunk of rs) {
    content.push(chunk);
  }
  const lines = content.join('').split(/\n/);
  const result = pf(lines);
  return result;
};

processLinesFromStream(process.stdin, main);


let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let a = readLine();
  if (a.toUpperCase() === a) {
    console.log(a.toLowerCase());
  } else if (a[0].toLowerCase() + a.substring(1).toUpperCase() === a) {
    console.log(a[0].toUpperCase() + a.substring(1).toLowerCase());
  } else {
    console.log(a);
  }
}


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

rl.on('line', (d) => {
  let [y, w] = d.split(' ').map(Number);
  let start = Math.max(y, w);
  let count = 0;

  for (let i = start; i <= 6; i++) {
    count++;
  }

  if (count === 1) {
    console.log('1/6');
  }
  else if (count === 6) {
    console.log('1/1');
  }
  else {
    if (count % 2 === 0) {
      console.log(`${count / 2}/3`);
    }
    else if (count % 3 === 0) {
      console.log(`${count / 3}/2`);
    }
    else {
      console.log(`${count}/6`);
    }
  }
});


function businessTrip(k, months) {
  // sort the array
  months = months.split(" ");
  months = months.sort(function(a, b) {
    return b - a;
  });
  // itarate
  let count = 0;
  let sum = 0;
  for (let i = 0; i < months.length; i++) {
    if (k == 0) {
      return console.log(count);
    }
    if (k <= parseInt(months[i]) + parseInt(sum)) {
      count++;
      return console.log(count);
    } else {
      sum = parseInt(sum) + parseInt(months[i]);
      count++;
    }
  }

  return console.log("-1");
}

// businessTrip("14", "0 0 0 0 0 0 0 1 1 2 3 0");

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

let arr = [];
rl.on("line", line => {
  arr.push(line);
});

rl.on("close", () => {
  businessTrip(arr[0], arr[1]);
});


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

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

function main() {
	let box = [];
	let r = 3;

	while (r--)
		box.push(
			readLine()
				.split(' ')
				.map(x => x >> 0)
		);

	let board = [Array(3).fill(1), Array(3).fill(1), Array(3).fill(1)];

	for (let i = 0; i < 3; ++i) {
		for (let j = 0; j < 3; ++j) {
			// If odd
			if ((box[i][j] & 1) === 1) {
				board[i][j] = board[i][j] === 0 ? 1 : 0;
				if (i + 1 < 3) board[i + 1][j] = board[i + 1][j] === 0 ? 1 : 0;
				if (i - 1 >= 0) board[i - 1][j] = board[i - 1][j] === 0 ? 1 : 0;
				if (j + 1 < 3) board[i][j + 1] = board[i][j + 1] === 0 ? 1 : 0;
				if (j - 1 >= 0) board[i][j - 1] = board[i][j - 1] === 0 ? 1 : 0;
			}
		}
	}

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


const fs = require('fs');
const text = fs.readFileSync(0, 'utf8');
const n = parseInt(text, 10);
if (n & 1) {
    console.log(0);
} else {
    console.log(Math.pow(2, n/2));
}


'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.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

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

function main() {
    let n = parseInt(readLine());
    let s = readLine().toLowerCase();
    let arr = s.split('').reduce((a, item) => {
        if (a.indexOf(item) == -1) {
            a.push(item);
        }
        return a;
    }, []);
    if (arr.length == 26) console.log("YES");
    else console.log("NO");
}


'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

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

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

    for (let test = 0; test < N; test++) {
        let n = parseInt(readline(), 10);
        output( 2 ** n - 1 );
    }
}


const readline = require('readline');

let inputs = [];

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})

// Read Inputs
rl.on('line', lineInput => {
    inputs.push(lineInput);
})

// Excute algorithm
rl.on('close', () => {
    let firstWord = inputs[0].toLowerCase();
    let secondWord = inputs[1].toLowerCase();

    if (firstWord < secondWord)
        console.log(-1)
    else if (firstWord > secondWord)
        console.log(1)
    else
        console.log(0)

})


const stdin = process.stdin;
stdin.setEncoding( 'utf8' );
stdin.on( 'data', function( rawInput ){
    const inputLines = rawInput.split('\n');
    const [n, m, a] = splitAndConvert(inputLines[0], 3);
    const result = solve(n, m, a);
    console.log(result);
});

function splitAndConvert(stringOfNumbers, numOfValid) {
	return stringOfNumbers.split(' ').slice(0, numOfValid).map(function(num) {
		return parseInt(num);
	});
}

function solve(n, m, a) {
    return Math.ceil(n/a) * Math.ceil(m/a);
}


var read = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function (input) { inLine.push(input); });
read.on('close', function () {
    obj = init(inLine);
    myerr("-----start-----");
    var start = new Date();
    Main();
    var end = new Date() - start;
    myerr("----- end -----");
    myerr("Time: " + (end) + "ms");
    myerr("Memory: " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt() { return myconv(next(), 1); }
function nextStrArray() { return myconv(next(), 2); }
function nextIntArray() { return myconv(next(), 4); }
function nextCharArray() { return myconv(next(), 6); }
function next() { return obj.next(); }
function hasNext() { return obj.hasNext(); }
function init(input) {
    var returnObj = {
        list: input, index: 0, max: input.length,
        hasNext: function () { return (this.index < this.max); },
        next: function () { if (!this.hasNext()) { throw "ArrayIndexOutOfBoundsException"; } else { var returnInput = this.list[this.index]; this.index++; return returnInput; } }
    };
    return returnObj;
}
function myout(s) { console.log(s); }
function myerr(s) { console.error("debug:" + require("util").inspect(s, false, null)); }
function myconv(i, no) { try { switch (no) { case 1: return parseInt(i); case 2: return i.split(" "); case 4: return i.split(" ").map(Number); case 6: return i.split(""); case 7: return i.split("").map(Number); case 8: return i.join(" "); case 9: return i.join("\n"); case 0: return i.join(""); default: return i; } } catch (e) { return i; } }

function Main() {
    var mat = [];

    for (var i = 0; i < 5; i++) {
        mat[i] = nextIntArray();
        for (var j = 0; mat[i][j] < 5; j++) {
            if (mat[i][j] === 1) {
                myout(Math.abs(i - 2) + Math.abs(j - 2));
            }
        }
    }

} // Use Terminal to debug, not Debug Console!


'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.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

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

function main() {
    let s = readLine();
    let t = readLine();
    if (s == t.split('').reverse().join('')) {
        console.log('YES')
    } else console.log('NO')
}


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

let currentLine = 0;
let i = '';
process.stdin.on('data', c => {
  i += c;
});
process.stdin.on('end', () => {
  const { EOL } = require('os');
  i = i.trim()
    .split(' ' || EOL)
    .map(string => {
      return string.trim();
    });
  main();
});

function readLine() {
  return i[currentLine++];
}
function main() {
  var x = readLine();
  var res = Math.floor(x / 5);
  if (x % 5 == 0) {
    console.log(res);
  }
  else console.log(res + 1);
}


const input = [];

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

RL.on('line', line => input.push(line));

RL.on('close', () => {
  const [n, k, l, c, d, p, nl, np] = input[0].split(' ').map(x => parseInt(x));
  let botl = parseInt((k * l) / nl);
  let lim  = c*d; let s = parseInt(p / np);

  console.log( parseInt(Math.min(botl, lim, s) / n) );
});


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

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

function main() {
	const n = readLine() >> 0;
	const s = readLine().split('');

	let current = s[0];
	let deleteCount = 0;

	for (let i = 1; i < n; i++) {
		if (s[i] === current) {
			deleteCount++;
		} else {
			current = s[i];
		}
	}

	console.log(deleteCount);
}


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

function findGreeting(str) {
  const word = 'hello';
  let i = 0;
  for(const l of str) {
    if(l == word[i]) {
      i++;
    }
  }
  return i == word.length ? 'YES' : 'NO';
}

let data = '';
process.stdin.on('data', c => data += c);
process.stdin.on('end', () => {
  const res = findGreeting(data.split(EOL)[0]);
  console.log(res);
});


function main() {
    var str = stdin[0].split(' ').map(x=>parseInt(x));
    var L = str[0];
    var P = str[1];
    var N = str[2];
    var F = N>0?true:false;
    for(var i = 1;i<=Math.abs(N);i++){
        if(F){
            P += 1;
            P = P<=L?P:1;
        }else{
            P -= 1;
            P = P>0?P:L;
        }
    }
   console.log(P);
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {stdin.push(line);});
rl.on('close', main);


const readline = require("readline");

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.question("", loop =>{
  getUserInput(loop);
})

function totalPressedDigit(number){
    let digit = number[0];
    let length = number.length;
    console.log( (digit-1) * 10 + length*(length+1)/2);
}

function getUserInput(n) {
    rl.question('', (number) => {
        totalPressedDigit(number)
        if (n > 1) {
            getUserInput(n-1);
        } else {
            rl.close();
        }
    });
}

rl.on("close", function() {
    process.exit(0);
});


function ProblemSolver() {
    this.HAS_TEST_CASES = false ;
    this.INPUT_FILE_NAME = "sample.in" ;
    this.OUTPUT_FILE_NAME = "sample.out" ;
    this.DO_OUTPUT_TO_FILE = false ;
    this.CLEAR_ARRAY_PER_CASE = false ;

    this.solveCase = function() {
        var res , i , j , fl , cn , a , b , c ;
        res = 0 ;
        this.brr = [] ;
        for( i = 1 ; i < this.n ; i++ ) {
          this.brr.push( this.arr[ i ] ) ;
        }
        this.brr = this.brr.sort( function( left , right ) {
          return right - left ;
        } ) ;
        a = this.arr[ 0 ] ;
        while( true ) {
          if( this.brr[ 0 ] < res + a ) {
              break ;
          }
          this.brr[ 0 ]-- ;
          res++ ;
          this.brr = this.brr.sort( function( left , right ) {
            return right - left ;
          } ) ;
        }
        print( res ) ;
    } ;

    this.init = function() {
        this.lim1 = 100010 ;
        this.lim2 = 110 ;
        this.cc = 1 ;
        this.ind = 1 ;
        this.n = 0 ;
        this.cn = 0 ;
        this.declareAndFillArrays() ;
    } ;

    this.getInput = function( irObj ) {
        var hasMoreInput , i ;
        hasMoreInput = true ;
        try {
        	this.n = irObj.nextInt() ;
            this.arr = [] ;
            for( i = 0 ; i < this.n ; i++ ) {
                this.arr.push( irObj.nextInt() ) ;
            }
        }
        catch( ex ) {
            hasMoreInput = false ;
        }
        return hasMoreInput ;
    } ;

    this.clearArraysPerCase = function() {
        var i ;
        this.arr = new Array() ;
        this.adjList = new Array() ;
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.arr.push( 0 ) ;
            this.adjList.push( new Array() ) ;
        }
    } ;

    this.clearPerCase = function() {
        this.cn = 0 ;
        this.cc++ ;
        if( this.CLEAR_ARRAY_PER_CASE == true ) {
            this.clearArraysPerCase() ;
        }
    } ;

    this.declareAndFillArrays = function() {
        var i , j ;
        this.srr = new Array() ;
        this.vis = new Array() ;
        this.arr = new Array() ;
        this.brr = new Array() ;
        this.memo = new Array() ;
        this.done = new Array() ;
        this.adjList = new Array() ;
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.srr.push( '' ) ;
            this.vis.push( 0 ) ;
            this.arr.push( 0 ) ;
            this.brr.push( 0 ) ;
            this.adjList.push( new Array() ) ;
        }
        for( i = 0 ; i < this.lim2 ; i++ ) {
            this.memo.push( new Array() ) ;
            this.done.push( new Array() ) ;
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( -1 ) ;
                this.done[ i ].push( 0 ) ;
            }
        }
    } ;

    this.init() ;
}

function InputReader() {
    var self = this ;
    this.allLines = new Array() ;
    this.currrentLineNumber = 0 ;
    this.currrentCharacterIndex = 0 ;
    this.callBackFunction = null ;
    this.parentContext = null ;

    this.readAllLines = function() {
        var singleLine ;
        while( true ) {
            try {
                singleLine = readline() ;
                if( singleLine == null ) {
                    break ;
                }
            }
            catch( ex ) {
                break ;
            }
            this.allLines.push( singleLine ) ;
        }
    } ;

    this.readAllLinesFromRhino = function() {
        var brObj , line ;
        importPackage( java.io ) ;
        importPackage( java.lang ) ;
        brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;
        this.allLines = [] ;
        while( true ) {
            line = brObj.readLine() ;
            if( line == null ) {
                break;
            }
            this.allLines.push( line ) ;
        }
    } ;

    this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {
        self.chunkData += chunk ;
    } ;

    this.readEndFromNodeJsJudgeServer = function() {
        self.parseRawData( self.chunkData ) ;
        self.parentContext.runCases() ;
    } ;

    this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {
        this.parentContext = parentContext ;
        process.stdin.resume() ;
        process.stdin.setEncoding( 'utf8' ) ;
        this.chunkData = '' ;
        process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;
        process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;
    } ;

    this.parseRawData = function( data ) {
        var len , i , currentString ;
        len = data.length ;
        currentString = '' ;
        this.allLines = [] ;
        for( i = 0 ; i < len ; i++ ) {
            if( data[ i ] == '\r' ) {
            }
            else if( data[ i ] == '\n' ) {
                this.allLines.push( currentString ) ;
                currentString = '' ;
            }
            else {
                currentString += data[ i ] ;
            }
        }
        if( currentString != '' ) {
            this.allLines.push( currentString ) ;
        }
    } ;

    this.readAllLinesFromFile = function( inputFileName ) {
        var currentDirectory , fsObj , inputFilePath , rawData ;
        fsObj = require( 'fs' ) ;
        currentDirectory = __dirname ;
        if( currentDirectory.indexOf( 'D:' ) != -1 ) {
            //on windows
            inputFilePath = currentDirectory + '\\' + inputFileName ;
        }
        else {
            //on linux
            inputFilePath = currentDirectory + '/' + inputFileName ;
        }
        rawData = fsObj.readFileSync( inputFilePath , "utf8" ) ;
        this.parseRawData( rawData ) ;
    } ;

    this.next = function( flag ) {
        var len , i , startIdx , res , endIdx ;
        if( flag == 0 ) {
            if( this.currrentCharacterIndex != 0 ) {
                this.currrentLineNumber++ ;
                this.currrentCharacterIndex = 0 ;
            }
            res = '' ;
            len = this.allLines[ this.currrentLineNumber ].length ;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;
            }
            this.currrentLineNumber++ ;
            this.currrentCharacterIndex = 0 ;
            return res ;
        }
        while( true ) {
            if( this.currrentLineNumber >= this.allLines.length ) {
                throw new Error( 'No more tokens available!' ) ;
            }
            startIdx = -1 ;
            len = this.allLines[ this.currrentLineNumber ].length ;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {
                    startIdx = i ;
                    break ;
                }
            }
            if( startIdx == -1 ) {
                this.currrentLineNumber++ ;
                this.currrentCharacterIndex = 0 ;
                continue ;
            }
            res = '' ;
            endIdx = len - 1 ;
            for( i = startIdx ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {
                    endIdx = i ;
                    break ;
                }
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {
                    res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;
                }
                else {
                    res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;
                }
            }
            this.currrentCharacterIndex = endIdx ;
            if( endIdx == len - 1 ) {
                this.currrentLineNumber++ ;
                this.currrentCharacterIndex = 0 ;
            }
            return res ;
        }
    } ;

    this.nextInt = function() {
        return parseInt( this.next( 1 ) ) ;
    } ;

    this.nextDouble = function() {
        return parseFloat( this.next( 1 ) ) ;
    } ;

    this.nextString = function() {
        return this.next( 1 ) ;
    } ;

    this.nextLine = function() {
        return this.next( 0 ) ;
    } ;
}

function FileOutputHandler() {
    this.resultantStringArray = new Array() ;

    this.addNewLine = function( newString ) {
        this.resultantStringArray.push( newString ) ;
    } ;

    this.clearPercase = function() {
        this.resultantStringArray = new Array() ;
    } ;

    this.flushOutOutputToFile = function( outputFileName ) {
        var i , sz , res , currentDirectory , fsObj , outputFilePath ;
        res = '' ;
        sz = this.resultantStringArray.length ;
        for( i = 0 ; i < sz ; i++ ) {
            if( i != 0 ) {
                res += '\n' ;
            }
            res += this.resultantStringArray[ i ] ;
        }
        fsObj = require( 'fs' ) ;
        currentDirectory = __dirname ;
        if( currentDirectory.indexOf( 'D:' ) != -1 ) {
            //on windows
            outputFilePath = currentDirectory + '\\' + outputFileName ;
        }
        else {
            //on linux
            outputFilePath = currentDirectory + '/' + outputFileName ;
        }
        fsObj.writeFileSync( outputFilePath , res ) ;
        this.clearPercase() ;
    } ;
}

function CodeExecutioner() {
    this.irObj = new InputReader() ;
    this.psObj = new ProblemSolver() ;
    this.fohObj = new FileOutputHandler() ;

    this.runCases = function() {
		var testCases , hasMoreTestCases , i ;
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt() ;
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase() ;
                this.psObj.getInput( this.irObj ) ;
                this.psObj.solveCase() ;
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase() ;
                hasMoreTestCases = this.psObj.getInput( this.irObj ) ;
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase() ;
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;
        }
    } ;

    this.detectEnvironmentType = function() {
        var environmentType = null ;
        try {
            if( importPackage != null ) {
                environmentType = 'rhino' ;
            }
        }
        catch( ex1 ) {
            try {
                //for nodejs local server check
                if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {
                    environmentType = 'local-node-js' ;
                }
                else {
                    environmentType = 'server-node-js' ;
                }
            }
            catch( ex2 ) {
                try {
                    if( readline == null || typeof( readline ) != 'function' ) {
                        environmentType = 'server-node-js' ;
                    }
                    else {
                        try {
                            if( Map != null ) {
                                environmentType = 'spider-monkey' ;
                            }
                            else {
                                environmentType = 'javascript-v8' ;
                            }
                        }
                        catch( ex3 ) {
                            environmentType = 'javascript-v8' ;
                        }
                    }
                }
                catch( ex3 ) {
                    environmentType = 'server-node-js' ;
                }
            }
        }
        return environmentType ;
    } ;

    this.configureStreamsAndReadInput = function() {
        var localContext , isNodeJsJudgeServer , environmentType ;
        isNodeJsJudgeServer = false ;
        environmentType = this.detectEnvironmentType() ;
        if( environmentType == 'local-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log ;
                }
            }
            catch( ex ) {
                print = console.log ;
            }
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj ;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments ) ;
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;
            this.runCases() ;
        }
        else if( environmentType == 'server-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log ;
                }
            }
            catch( ex ) {
                print = console.log ;
            }
            this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;
        }
        else if( environmentType == 'javascript-v8' ) {
            this.irObj.readAllLines() ;
            this.runCases() ;
        }
        else if( environmentType == 'rhino' ) {
            this.irObj.readAllLinesFromRhino() ;
            this.runCases() ;
        }
        else if( environmentType == 'spider-monkey' ) {
            this.irObj.readAllLines() ;
            this.runCases() ;
        }
    } ;

    this.configureStreamsAndReadInput() ;
}

new CodeExecutioner() ;


let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const [data, results] = i.split(EOL).map((x) => {return x.split(" ").map((y) => { return parseInt(y)})})

    if (!(Math.max(...results) < results[data[1] - 1])){
        console.log(results.filter(i => (i > 0) && !(i < results[data[1] - 1])).length);
    } else {console.log(0)}

});


const readline = require("readline");

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

rl.question('', (tableCard) => {
  rl.question('', (handCards) => {
    isAllowed(tableCard, handCards) ? console.log('YES') : console.log('NO');
    rl.close()
  });
});

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

function isAllowed(tableCard, handCards) {

  const handCardsArray = handCards.split(' ');

  for (let index = 0; index < handCardsArray.length; index++) {

    if (handCardsArray[index].charAt(0) == tableCard.charAt(0)) {
      return true;
    }
    else if (handCardsArray[index].charAt(1) == tableCard.charAt(1)) {
      return true;
    }
  };
  return false;
};


function businessTrip(k, months) {
  // sort the array
  months = months.split(" ");
  months = months.sort(function(a, b) {
    return b - a;
  });
  // itarate
  for (let i = 0; i < months.length; i++) {
    let sumOfFirsNLement = months
      .slice(0, i + 1)
      .reduce((startPoint, current) => {
        return parseInt(startPoint) + parseInt(current);
      });
    if (k == 0) return console.log(0);
    if (parseInt(sumOfFirsNLement) >= parseInt(k)) return console.log(i + 1);
  }
  return console.log("-1");
}

// let sum = [1, 2, 3];

// console.log(sum);

// businessTrip("5", "0 0 0 0 0 0 0 1 1 2 3 0");

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

let arr = [];
rl.on("line", line => {
  arr.push(line);
});

rl.on("close", () => {
  businessTrip(arr[0], arr[1]);
});