Polycarp has found a table having an infinite number of rows and columns. The rows are numbered from $$$1$$$, starting from the topmost one. The columns are numbered from $$$1$$$, starting from the leftmost one.Initially, the table hasn't been filled and Polycarp wants to fix it. He writes integers from $$$1$$$ and so on to the table as follows.  The figure shows the placement of the numbers from $$$1$$$ to $$$10$$$. The following actions are denoted by the arrows. The leftmost topmost cell of the table is filled with the number $$$1$$$. Then he writes in the table all positive integers beginning from $$$2$$$ sequentially using the following algorithm.First, Polycarp selects the leftmost non-filled cell in the first row and fills it. Then, while the left neighbor of the last filled cell is filled, he goes down and fills the next cell. So he goes down until the last filled cell has a non-filled neighbor to the left (look at the vertical arrow going down in the figure above).After that, he fills the cells from the right to the left until he stops at the first column (look at the horizontal row in the figure above). Then Polycarp selects the leftmost non-filled cell in the first row, goes down, and so on.A friend of Polycarp has a favorite number $$$k$$$. He wants to know which cell will contain the number. Help him to find the indices of the row and the column, such that the intersection of the row and the column is the cell containing the number $$$k$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line containing one integer $$$k$$$ ($$$1 \le k \le 10^9$$$) which location must be found.

For each test case, output in a separate line two integers $$$r$$$ and $$$c$$$ ($$$r, c \ge 1$$$) separated by spaces — the indices of the row and the column containing the cell filled by the number $$$k$$$, respectively.

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

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

function main(input) {
    input = input.split("\n");
    let z = 0;
    let testCases = +input[z++];

    while(testCases--){
        let number = +input[z++];
        if(number == parseInt(Math.sqrt(number))**2){
            console.log(Math.sqrt(number), 1);
        }
        else{
            let low = parseInt(Math.sqrt(number))**2;
            let high = (parseInt(Math.sqrt(number)) + 1)**2;
            let middle = (low + high + 1) / 2;
            if(number === middle){
                console.log(Math.abs(low - middle), Math.abs(low - middle));
            }
            else if(number < middle){
                console.log(Math.abs(low - number), Math.abs(low - middle));
            }
            else{
                console.log(Math.abs(low - middle), Math.abs(high - number + 1));
            }
        }
    }
}

/****************************************************************\
                  NAME:  MD. TAHURUZZOHA TUHIN
\****************************************************************/

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let matrix = [];
let nbr = 0;
let cnt = 0;
rl.on('line', (line) => {
    matrix.push(line.split(' '));
    let a = matrix.map(x => parseInt(x));
    nbr++;

    if (nbr > a[0]) {
        for (let i = 1; i <= a[0]; i++) {
            let n = a[i];
            let x = 1;
            let k = 1;
            let r, cc = 0, int;
            if (n == 1) {
                console.log(1, 1);
                continue;
            }
            while (1) {
                cc++;

                if (n >= x && n < x + k) {
                    int = parseInt(k / 2 + x);
                    cnt = int;
                    if (n >= x && n <= cnt) {
                        r = Math.abs(n - x) + 1;
                    }
                    else {
                        int = parseInt(k / 2 + 1);
                        r = int;
                        cc = Math.abs(x + k - n);
                    }

                    console.log(r, cc);
                    break;
                }
                x += k;
                k += 2;
            }
        }

        rl.close();
    }

});

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const assert = (condition) => { if (!condition) throw new Error("Assertion failed"); }
const mi = Math.min;
const mx = Math.max;
const mxll = (...args) => args.reduce((m, e) => e > m ? e : m);
const mill = (...args) => args.reduce((m, e) => e < m ? e : m);
const sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0
const abs = Math.abs;
const fl = Math.floor;
const int = parseInt;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg2 = Math.log2;
const lg10 = Math.log10;
const ll = BigInt;
const combination = (m, n) => { return factorial(m, n) / factorial(n, n); };
const factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };
const powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth
const initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };
const initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };
const stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));
const stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));
const stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));
const stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };
const counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };
const reverse2 = (s) => { let res = ""; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
const ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);
const isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 08/18/21 morning
 * https://codeforces.com/contest/1560/problem/A
 */
const solve = (x) => {
    // pr(x)
    let i = 1;
    for (; i * i < x; i++);
    // pr(i, i * i)
    if (i * i == x) {
        return pr(i, 1);
    }
    let pre = (i - 1) * (i - 1);
    let rest = x - pre;
    // pr('pre', pre, 'rest', rest);
    // if (rest == 0) return pr(i + 1, i);
    if (rest <= i) {
        return pr(rest, i);
    }
    rest -= i;
    pr(i, i - rest);
};

// const cal = (n) => {
//    let cnt = (n - 1) / 2 + 1;
//    return (1 + n) * cnt / 2;
// };

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(Number(line));
    });
    rl.on('close', () => {
        let t = input[0];
        let i = 1;
        while (t--) {
            solve(input[i]);
            i++;
        }
    });
};

main()

// pr(cal(1), cal(3), cal(5), cal(7));

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var n = lines[i], num = Math.ceil(Math.sqrt(n)), sq = num * num, d = sq - n;
        var row = 0, cl = 0;
        if(d < num){
            row = num;
            cl = d + 1;
        }else{
            cl = num;
            d -= num;
            d = num - d - 1;
            row = d;
        }
        console.log(row, cl);
    }
});

let input = ''
process.stdin.on('data', c => input += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = input.split(EOL)
    const count = parseInt(lines[0]);
    for (let i = 1; i <= count; i++) {
        const n = parseInt(lines[i]);
        compute(n);
    }
})

function compute(num) {
    if (num === 1) {
        console.log('1 1');
        return;
    }
    let lower = -1;
    let upper = -1;
    for (let s = 1; s < 31623; s++) {
        lower = Math.pow(s, 2);
        upper = Math.pow(s+1, 2);
        if (lower <= num && num <= upper) break;
    }
    let r = -1;
    let c = -1;
    if (lower === num) {
        r = Math.sqrt(lower);
        c = 1;
    } else if (upper === num) {
        r = Math.sqrt(upper);
        c = 1;
    } else {
        const middle = lower + Math.floor((upper - lower) / 2) + 1;
        if (num < middle) {
            r = num - lower;
            c = Math.sqrt(upper);
        } else {
            r = Math.sqrt(upper);
            c = upper - num + 1;
        }
    }

    console.log(r, c);
}

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++]
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        console.log(solve(n).join(' '))
    }
// })()
})

function solve(n) {
    const k = Math.floor(Math.sqrt(n))
    const r = n - k * k
    // console.log(n, k, r)
    if (!r) {
        return [k, 1]
    }
    if (r > k) {
        return [k + 1, k + 1 - (r - k - 1)]
    } else {
        return [r, k + 1]
    }
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		const k = rn();

		let x = Math.floor(Math.sqrt(k-1));
		const d = k - x*x;

		let r, c;
		++x;
		if (d <= x) {
			r = d, c = x;
		} else {
			r = x, c = 2 * x - d;
		}

		console.log(r, c);
	}
}

function main(input) {
    function readline() {
        return input.shift();
    }

    let lines = Number(readline());
    for(let _ = 0; _ < lines; _++) {

        const k = Number(readline())

        let value = 1;
        let scopeLevel = 1;

        while(k >= value) {
            value += (scopeLevel * 2) - 1
            scopeLevel++
        }
        scopeLevel--;

        const scopeStart = value - scopeLevel*2 + 1
        const scopeMiddle = value - scopeLevel;
        const scopeEnd = value - 1

        let row, column;

        if(k < scopeMiddle) {
            row = (k - scopeStart + 1 ) ;
            column = scopeLevel;
        }
        if(k === scopeMiddle) {
            row = scopeLevel;
            column = scopeLevel;
        }

        if(k > scopeMiddle) {
            row = scopeLevel;
            column = scopeLevel - (k - scopeMiddle);
        }
        console.log(`${row} ${column}`)
       }
    }

////////////////////////
let inputString = '';
process.stdin.on('data', (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on('end', (_) => {
    inputString = inputString.trim().split('\n').map((string) => string.trim());

    main(inputString);
});

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

let currentline = 0;
function readline(){
    return input[currentline++];
    // return prompt()
}

function solve() {
    // let lis = readline().split(" ");
    // let a, b;
    // a = parseInt(lis[0]);
    // b = parseInt(lis[1]);
    // c = parseInt(lis[2]);
    let p = parseInt(readline());
    if(p == parseInt(Math.sqrt(p))**2){
        return [Math.sqrt(p) , 1]
    }
    let l = parseInt(Math.sqrt(p))**2;
    let h = (parseInt(Math.sqrt(p))+1)**2;
    let m = (l+h+1)/2;
    if(p == m){
        return [l-m , l-m]
    }
    else if(p < m){
        return [l-p , l-m]
    }else{
        return [l-m , h-p+1]
    }

}
for (let i = parseInt(readline()); i > 0; i--) {
    let [a , b] = solve();
    console.log(Math.abs(a),Math.abs(b))
}

let inputs = []

function read() {
    return inputs.pop();
}

function readInt() {
    return parseInt(read());
}

function solve() {
    let test = readInt();
    while (test--) {
        let k = readInt();
        let c = parseInt(Math.sqrt(k - 1)) + 1;
        while (k - 1 < c * c) c--;
        let r = k - c * c;
        if (r <= c) {
            console.log(r + ' ' + (c + 1));
        }
        else {
            console.log((c + 1) + ' ' + (2 * c - r + 2));
        }
    }
}

function main() {
    inputs = inputString.trim().split(/\n| /).map((string) => string.trim());
    inputs.reverse();
    solve();
}

let inputString = '';

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

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

function solve (k) {
  const n = Math.floor(Math.sqrt(k));
  if (n * n === k) {
    return {
      x: n,
      y: 1,
    };
  }
  if (n * n + 1 === k) {
    return {
      x: 1,
      y: n + 1,
    };
  }
  const maxLeft = (n * n + 1 + (n + 1) * (n + 1)) / 2;
  if (k === maxLeft) {
    return {
      x: n + 1,
      y: n + 1,
    };
  }
  if (k > maxLeft) {
    return {
      x: n + 1,
      y: n - (k - maxLeft) + 1,
    };
  }
  if (k < maxLeft) {
    return {
      y: n + 1,
      x: (n + 1) - ((maxLeft - k)),
    };
  }
}

function main(array) {
  const T = array[0];
  for (let i = 0; i < T; i++) {
    const k = parseInt(array[i + 1], 10);
    const { x, y} = solve(k);
    console.log(`${x} ${y}`);
  }
}

let inputString = '';

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

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

  main(inputString);
});

const arr = [];
let add = 1;
let current = 1;
const max = Math.pow(10, 9);
while(current <= max) {
   arr.push(current);
   current += add;
   add += 2;
}
arr.push(current);

function solve() {
   const k = Number(read());
   let index;
   for(let i = arr.length - 1; i >= 0; i--) {
      if (arr[i] > k) {
         continue;
      }
      index = i;
      break;
   }
   const x1 = arr[index];
   const x3 = arr[index + 1] - 1;
   const x2 = ((x1 + x3) >> 1);
   if (k === x2) {
      write((index + 1) + ' ' + (index + 1));
      return;
   }
   if (k < x2) {
      write((k - x1 + 1) + ' ' + (index + 1))
      return;
   }
   write((index + 1) + ' ' + (x3 - k + 1))
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

   var inTextName;
   var outTextName;

   var needWriteFile = false;

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

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

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

//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] = BigInt(next());
		}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 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 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 K = nextInt();
		if(K == 1){
			myout("1 1");
			continue;
		}
		var r = 1;
		var L = -1;
		var R = -1;
		while(true){
			L = r * r;
			R = (r + 1) * (r + 1);
			if(L < K && K <= R){
				break;
			}
			r++;
		}
		L++;
		var center = (L + R) / 2;
		var c;
		if(K >= center){
			c = 1 + ((r + 1) * (r + 1) - K);
			r++;
		}else{
			c = r + 1;
			r = r - (center - K) + 1;
		}
		myout(r + " " + c);
	}
}

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

var maxN = 2 * 1e5 + 10
var mod = BigInt(1e9 + 7)

function main() {
  const xx = readline();
  var array = []
  // console.log(array)
  Array(Number(xx)).fill(1).map((t, i) => {
    var n = parseInt(readline());
    //
    // var [a, b, c] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // })
    var ii = 1
    while (ii * ii < n) {
      ii++
    }
    var count = ii * ii
    var x = ii
    var y = 1
    var direction = true
    while (count !== n) {
      if (direction) y++
      if (!direction) x--
      count--
      if (y === ii) direction = false
    }
    console.log(x, y)
  })
}

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readLineAsNumber() {
    return Number(this.readLine())
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(String(e))
  }
  println(e) {
    stdout.write(String(e)), stdout.write('\n')
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(t => {
      stdin.on('data', t => e.push(t)),
        stdin.on('end', function () {
          const n = e.join('').split(os.EOL)
          t(n)
        })
    })
  }
}
async function __main__(e) {
  const t = new InputAndOutput()
  await t.init(), e(t)
}
function solve(e) {
  let t = Math.max(1, Math.floor(Math.sqrt(e)) - 2)
  for (; (t + 1) * (t + 1) <= e; ) t += 1
  if (t * t === e) return [t, 1]
  let n = e - t * t
  return n <= t + 1 ? [n, t + 1] : ((n -= t + 1), [t + 1, t + 1 - n])
}
__main__(function (e) {
  const t = e.readLineAsNumber()
  for (let n = 1; n <= t; ++n) {
    const t = e.readLineAsNumber(),
      [n, i] = solve(t)
    e.print(n + ' ' + i + '\n')
  }
})

var t = parseInt(readline());
for(i=0;i<t;++i){
    var num = parseInt(readline());
    var x = 1;
    var l = 1;
    while(num > l) {
        num -= l;
        l = l + 2;
        ++x;
    }
    if (x === num) print(x + ' ' + x);
    else if (x < num) print(x + ' ' + (2 * x - num));
    else print(num + ' ' + x);
}

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

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

function main(input) {
    input = input.split("\n");
    let z = 0;
    let testCases = +input[z++];

    while(testCases--){
        let number = +input[z++];
        if(number == parseInt(Math.sqrt(number))**2){
            console.log(Math.sqrt(number), 1);
        }
        else{
            let low = parseInt(Math.sqrt(number))**2;
            let high = (parseInt(Math.sqrt(number)) + 1)**2;
            let middle = (low + high + 1) / 2;
            if(number === middle){
                console.log(Math.abs(low - middle), Math.abs(low - middle));
            }
            else if(number < middle){
                console.log(Math.abs(low - number), Math.abs(low - middle));
            }
            else{
                console.log(Math.abs(low - middle), Math.abs(high - middle + 1));
            }
        }
    }
}

/****************************************************************\
                    NAME:  MD. TAHURUZZOHA TUHIN
\****************************************************************/

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

let p = 0, m = 0, cnt = 0;
let array1 = [];
let array2 = [];

input.on('line', (line) => {
    array1.push(line.split(" "));
    let a = array1[p].map(x => parseInt(x));
    p++;
    if (p > 0) {

        input.on('line', (line) => {
            array2.push(line.split(' '));
            let b = array2[m].map(x => parseInt(x));
            m++;
            if (m > 0) input.close();

            for (const n of b) {
                let x = 1;
                let k = 1;
                let r, cc = 0, int;
                if (n == 1) {
                    console.log(1, 1);
                    continue;
                }
                while (1) {
                    cc++;

                    if (n >= x && n < x + k) {
                        int = parseInt(k / 2 + x);
                        cnt = int;
                        if (n >= x && n <= cnt) {
                            r = Math.abs(n - x) + 1;
                        }
                        else {
                            int = parseInt(k / 2 + 1);
                            r = int;
                            cc = Math.abs(x + k - n);
                        }

                        console.log(r, cc);
                        break;
                    }
                    x += k;
                    k += 2;
                }
            }

        })

    }

})

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const assert = (condition) => { if (!condition) throw new Error("Assertion failed"); }
const mi = Math.min;
const mx = Math.max;
const mxll = (...args) => args.reduce((m, e) => e > m ? e : m);
const mill = (...args) => args.reduce((m, e) => e < m ? e : m);
const sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0
const abs = Math.abs;
const fl = Math.floor;
const int = parseInt;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg2 = Math.log2;
const lg10 = Math.log10;
const ll = BigInt;
const combination = (m, n) => { return factorial(m, n) / factorial(n, n); };
const factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };
const powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth
const initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };
const initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };
const stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));
const stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));
const stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));
const stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };
const counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };
const reverse2 = (s) => { let res = ""; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
const ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);
const isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 08/18/21 morning
 * https://codeforces.com/contest/1560/problem/A
 */
const solve = (x) => {
    // pr(x)
    let i = 1;
    for (; i * i < x; i++);
    // pr(i, i * i)
    if (i * i == x) {
        return pr(i, 1);
    }
    let pre = (i - 1) * (i - 1);
    let rest = x % pre;
    if (rest == 0) return pr(rest + 1, i);
    // pr('rest', rest);
    if (rest <= i) {
        return pr(rest, i);
    }
    rest -= i;
    pr(i, i - rest);
};

// const cal = (n) => {
//    let cnt = (n - 1) / 2 + 1;
//    return (1 + n) * cnt / 2;
// };

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(Number(line));
    });
    rl.on('close', () => {
        let t = input[0];
        let i = 1;
        while (t--) {
            solve(input[i]);
            i++;
        }
    });
};

main()

// pr(cal(1), cal(3), cal(5), cal(7));

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const assert = (condition) => { if (!condition) throw new Error("Assertion failed"); }
const mi = Math.min;
const mx = Math.max;
const mxll = (...args) => args.reduce((m, e) => e > m ? e : m);
const mill = (...args) => args.reduce((m, e) => e < m ? e : m);
const sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0
const abs = Math.abs;
const fl = Math.floor;
const int = parseInt;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg2 = Math.log2;
const lg10 = Math.log10;
const ll = BigInt;
const combination = (m, n) => { return factorial(m, n) / factorial(n, n); };
const factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };
const powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth
const initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };
const initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };
const stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));
const stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));
const stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));
const stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };
const counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };
const reverse2 = (s) => { let res = ""; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
const ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);
const isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 08/18/21 morning
 * https://codeforces.com/contest/1560/problem/A
 */
const solve = (x) => {
    // pr(x)
    let i = 1;
    for (; i * i < x; i++);
    // pr(i, i * i)
    if (i * i == x) {
        return pr(i, 1);
    }
    let pre = (i - 1) * (i - 1);
    let rest = x % pre;
    if (rest <= i) {
        return pr(rest, i);
    }
    rest -= i;
    pr(i, i - rest);
};

// const cal = (n) => {
//    let cnt = (n - 1) / 2 + 1;
//    return (1 + n) * cnt / 2;
// };

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(Number(line));
    });
    rl.on('close', () => {
        let t = input[0];
        let i = 1;
        while (t--) {
            solve(input[i]);
            i++;
        }
    });
};

main()

// pr(cal(1), cal(3), cal(5), cal(7));

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var n = lines[i];
        var x = 0;
        while(n > 0){
            var z = n % 10;
            x = Math.max(x, z);
            n /= 10;
        }
        console.log(Math.floor(x));
    }
});

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++]
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        console.log(solve(n))
    }
// })()
})

function solve(n) {
    const k = Math.floor(Math.sqrt(n))
    const r = n - k * k
    // console.log(n, k, r)
    if (r > k) {
        return [k + 1, k + 1 - (r - k - 1)].join(' ')
    } else {
        return [r, k + 1].join(' ')
    }
}


AquaMoon has two binary sequences $$$a$$$ and $$$b$$$, which contain only $$$0$$$ and $$$1$$$. AquaMoon can perform the following two operations any number of times ($$$a_1$$$ is the first element of $$$a$$$, $$$a_2$$$ is the second element of $$$a$$$, and so on): Operation 1: if $$$a$$$ contains at least two elements, change $$$a_2$$$ to $$$\operatorname{min}(a_1,a_2)$$$, and remove the first element of $$$a$$$. Operation 2: if $$$a$$$ contains at least two elements, change $$$a_2$$$ to $$$\operatorname{max}(a_1,a_2)$$$, and remove the first element of $$$a$$$.Note that after a removal of the first element of $$$a$$$, the former $$$a_2$$$ becomes the first element of $$$a$$$, the former $$$a_3$$$ becomes the second element of $$$a$$$ and so on, and the length of $$$a$$$ reduces by one.Determine if AquaMoon can make $$$a$$$ equal to $$$b$$$ by using these operations.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 2\,000$$$) — the number of test cases. Description of test cases follows. The first line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n,m \leq 50$$$, $$$m \leq n$$$) — the lengths of $$$a$$$ and $$$b$$$ respectively. The second line of each test case contains a string $$$a$$$ of length $$$n$$$, consisting only $$$0$$$ and $$$1$$$. The third line of each test case contains a string $$$b$$$ of length $$$m$$$, consisting only $$$0$$$ and $$$1$$$.

For each test case, output "YES" if AquaMoon can change $$$a$$$ to $$$b$$$ by using these options; otherwise, output "NO". You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as a positive answer).

NoteIn the first test case, you can use Operation 2 four times to make $$$a$$$ equals to $$$b$$$.In the second test case, you can use Operation 1 four times to make $$$a$$$ equals to $$$b$$$.In the third test case, it can be proved that no matter how we use the operations, it is impossible to make $$$a$$$ equal to $$$b$$$.In the fourth test case, it can be proved that no matter how we use the operations, it is impossible to make $$$a$$$ equal to $$$b$$$.In the fifth test case, you can use Operation 2 three times to make $$$a$$$ become $$$10101$$$, so the first element of $$$a$$$ equals to the first element of $$$b$$$, but it can be proved that no matter how to operate, the second to the fifth elements of $$$a$$$ can't be the same as $$$b$$$.

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    let cnt=0;
    for(let _=1;_<=t;_++)
    {
        let [n,m]=line[++cnt].split(' ').map(x=>{return parseInt(x)});
        let s1=line[++cnt];
        let s2=line[++cnt];
        let a=[],b=[];
        for(let i=0;i<s1.length;i++)
        {
            if(s1[i]==='0') a.push(0);
            else a.push(1);
        }
        for(let i=0;i<s2.length;i++)
        {
            if(s2[i]==='0') b.push(0);
            else b.push(1);
        }
        let c0=0,c1=0;
        while(a.length>b.length)
        {
            if(a[0]===0) c0=1;
            else c1=1;
            a.shift();
        }
        flag=true;
        if(b[0]===0)
        {
            if(c0)
            {
                a[0]=0;
            }
        }
        else
        {
            if(c1)
            {
                a[0]=1;
            }
        }
        for(let i=0;i<a.length;i++)
        {
            if(a[i]!=b[i])
            {
                flag=false;
            }
        }
        if(flag) console.log("YES");
        else console.log("NO");
    }
})

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    let cnt=0;
    for(let _=1;_<=t;_++)
    {
        let [n,m]=line[++cnt].split(' ').map(x=>{return parseInt(x)});
        let s1=line[++cnt];
        let s2=line[++cnt];
        let a=[],b=[];
        for(let i=0;i<s1.length;i++)
        {
            if(s1[i]==='0') a.push(0);
            else a.push(1);
        }
        for(let i=0;i<s2.length;i++)
        {
            if(s2[i]==='0') b.push(0);
            else b.push(1);
        }
        // a.shift();
        // console.log(a,b);
        let c0=0,c1=0;
        while(a.length>b.length)
        {
            if(a[0]===0) c0=1;
            else c1=1;
            a.shift();
        }
        flag=true;
        if(b[0]===0)
        {
            if(c0)
            {
                a[0]=0;
            }
        }
        else
        {
            if(c1)
            {
                a[0]=1;
            }
        }
        for(let i=0;i<a.length;i++)
        {
            if(a[i]!=b[i])
            {
                flag=false;
            }
        }
        if(flag) 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', 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 [n, m] = readline().split(' ').map(Number);
        let a = readline();
        let b = readline();
        if (a.length === b.length) {
            output(a === b ? 'YES' : 'NO');
            continue;
        }
        let p = a.length - b.length + 1;
        if (a.slice(p) === b.slice(1)) {
            if (a.slice(0, p).includes(b[0])) {
                output('YES');
            } else {
                output('NO');
            }
        } else {
            output('NO');
        }
    }
}

// ------------------------
// Codeabschnitt, der für die Verarbeitung der Eingabe zuständig ist
'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 print = console.log

// ---------------------------

/**
 * Usage (Linux/Unix): cat input.txt | node index.js
 */

function main() {
    const testCases = +readline()

    for (let i = 0; i < testCases; i++) {
        let len = readline().split(" ").map(Number)

        let a = readline()
        let b = readline()

        let pos = true;
        let ind;
        for(ind = 0; ind < len[1] - 1; ind++){
            if(a[ind + 1 + len[0] - len[1]] != b[ind + 1]){
                pos = false;
            }
        }

        let pos2 = false;
        for(let ii = 0; ii < len[0] - len[1] + 1; ii++){
            if(a[ii] == b[0]){
                pos2 = true;
            }
        }

        if(!(pos && pos2)){
            print("NO")
        } else {
            print("YES")
        }
    }
}

// cls; cat .\input.txt | node .\script.js
'use strict';
let data = ''; // raw
let inputs = ''; // iterator
function read() { return inputs.next().value.trim(); };

async function solve() {
    let [a_length, b_length] = (await read()).split(' ').map(Number)
    let dataA = (await read())//.split('').map(Number)
    let dataB = (await read())//.split('').map(Number)

    const firstA = dataA.substring(0, dataA.length - dataB.length + 1);
    const secondA = dataA.substring(dataA.length - dataB.length + 1);
    const firstB = dataB[0];
    const secondB = dataB.substring(1);

    if (secondB === secondA && firstA.indexOf(firstB) != -1) {
        console.log("YES");
    } else {
        console.log("NO");
    }

}

async function main() {
    let tasks_amount = parseInt(await read())
    for (let i = 0; i < tasks_amount; i++) {
        const element = tasks_amount[i];
        await solve()
    }
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => data += input);
process.stdin.on('end', async () => {
    let splitted = data.split('\r\n')
    inputs = await splitted.values();
    await main();

});

var t = +readline()

for (var i=0; i<t; i++) {

    var line1 = readline()
    var a = readline()
    var b = readline()

    var a_len = line1.split(" ")[0]
    var b_len = line1.split(" ")[1]

    var sequence = a.substring(0, a_len-b_len + 1)
    var sequence2 = a.substring(a_len-b_len + 1, a_len)

    var b_sequence2 = b.substring(1, b_len)

    var flag0 = false
    var flag1 = false
    for (var s of sequence) {
        if (s == "0") flag0 = true
        if (s == "1") flag1 = true
    }

    var prefix = ""
    if (flag1 && flag0) {
        //x
        prefix = "x"
    } else if (flag1) {
        //11111
        prefix = "1"
    } else if (flag0) {
        //00000
        prefix = "0"
    }

    //debug
    //print("a_s2="+sequence2)
    //print("b_s2="+b_sequence2)
    //print("b[0]="+b[0])
    //print("prefix="+prefix)

    if (b_sequence2 == sequence2 && (b[0] == prefix || prefix == "x"))
        print("YES")
    else
        print("NO")
}

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    let cnt=0;
    for(let _=1;_<=t;_++)
    {
        let [n,m]=line[++cnt].split(' ').map(x=>{return parseInt(x)});
        let s1=line[++cnt];
        let s2=line[++cnt];
        let a=[],b=[];
        for(let i=0;i<s1.length;i++)
        {
            if(s1[i]==='0') a.push(0);
            else a.push(1);
        }
        for(let i=0;i<s2.length;i++)
        {
            if(s2[i]==='0') b.push(0);
            else b.push(1);
        }
        // a.shift();
        // console.log(a,b);
        let c0=0,c1=0;
        while(a.length>b.length)
        {
            if(a[0]===0) c0=1;
            else c1=1;
            a.shift();
        }
        flag=true;
        if(b[0]===0)
        {
            if(c0)
            {
                a[0]=0;
            }
        }
        else
        {
            if(c1)
            {
                a[0]=1;
            }
        }
        if(a!==b)
        {
            flag=false;
        }
        if(flag) console.log("YES");
        else console.log("NO");
    }
})

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    let cnt=0;
    for(let _=1;_<=t;_++)
    {
        let [n,m]=line[++cnt].split(' ').map(x=>{return parseInt(x)});
        let s1=line[++cnt];
        let s2=line[++cnt];
        let a=[],b=[];
        for(let i=0;i<s1.length;i++)
        {
            if(s1[i]==='0') a.push(0);
            else a.push(1);
        }
        for(let i=0;i<s2.length;i++)
        {
            if(s2[i]==='0') b.push(0);
            else b.push(1);
        }
        // a.shift();
        // console.log(a,b);
        let c0=0,c1=0;
        while(a.length>b.length)
        {
            if(a[0]===0) c0=1;
            else c1=1;
            a.shift();
        }
        flag=true;
        if(b[0]===0)
        {
            if(c0)
            {
                a[0]=0;
            }
        }
        else
        {
            if(c1)
            {
                a[0]=1;
            }
        }
        if(a[0]===b[0])
        {
            for(let i=1;i<a.length;i++)
            {
                if(a[i]!==b[i])
                {
                    if(i+1<a.length&&(Math.min(a[i],a[i+1])===b[i]||Math.max(a[i],a[i+1])===b[i]))
                    {
                        a[i]=b[i];
                    }
                    else
                    {
                        flag=false;
                        break;
                    }
                }
            }
        }
        else
        {
            flag=false;
        }
        if(flag) console.log("YES");
        else console.log("NO");
    }
})

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    let cnt=0;
    for(let _=1;_<=t;_++)
    {
        let [n,m]=line[++cnt].split(' ').map(x=>{return parseInt(x)});
        let s1=line[++cnt];
        let s2=line[++cnt];
        let a=[],b=[];
        for(let i=0;i<s1.length;i++)
        {
            if(s1[i]==='0') a.push(0);
            else a.push(1);
        }
        for(let i=0;i<s2.length;i++)
        {
            if(s2[i]==='0') b.push(0);
            else b.push(1);
        }
        // a.shift();
        // console.log(a,b);
        let c0=0,c1=0;
        while(a.length>b.length)
        {
            if(a[0]===0) c0=1;
            else c1=1;
            a.shift();
        }
        flag=true;
        if(b[0]===0)
        {
            if(c0)
            {
                a[0]=0;
            }
        }
        else
        {
            if(c1)
            {
                a[0]=1;
            }
        }
        if(a[0]===b[0])
        {
            for(let i=1;i<a.length;i++)
            {
                if(a[i]!==b[i])
                {
                    if(Math.min(a[i],a[i-1])===b[i]||Math.max(a[i],a[i-1])===b[i])
                    {
                        a[i]=b[i];
                    }
                    else
                    {
                        flag=false;
                        break;
                    }
                }
            }
        }
        else
        {
            flag=false;
        }
        if(flag) console.log("YES");
        else console.log("NO");
    }
})

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    console.log('Hello World!');
})

'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 [n, m] = readline().split(' ').map(Number);
        let a = readline();
        let b = readline();
        let firstBIndex = a.length - b.length;
        if (a === b) {
            output('YES');
            continue;
        }
        if (a.substring(firstBIndex + 1) === b.substring(1)) {
            if (a.substring(0, firstBIndex).includes(b[0])) {
                output('YES');
            } else if (b.length === 1) {
                output('YES');
            } else {
                output('NO');
            }
        } else {
            output('NO');
        }
    }
}

'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 [n, m] = readline().split(' ').map(Number);
        let a = readline();
        let b = readline();
        let firstBIndex = a.length - b.length;
        if (a === b) {
            output('YES');
            continue;
        }
        if (a.substring(firstBIndex + 1) === b.substring(1)) {
            if (a.substring(0, firstBIndex).includes(b[0])) {
                output('YES');
            } else if (b.length === 1) {
                output('YES');
            } else {
                output('NO1');
            }
        } else {
            output('NO2');
        }
    }
}

'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 [n, m] = readline().split(' ').map(Number);
        let a = readline();
        let b = readline();
        let firstBIndex = a.length - b.length;
        if (a === b) {
            output('YES');
            continue;
        }
        if (a.substring(firstBIndex + 1) === b.substring(1)) {
            if (a.substring(0, firstBIndex).includes(b[0])) {
                output('YES');
            } else output('NO');
        } else output('NO');
    }
}

'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 [n, m] = readline().split(' ').map(Number);
        let a = readline();
        let b = readline();
        let firstBIndex = a.length - b.length;
        if (a.substring(firstBIndex + 1) === b.substring(1)) {
            if (a.substring(0, firstBIndex).includes(b[0])) {
                output('YES');
            } else output('NO');
        } else output('NO');
    }
}

// ------------------------
// Codeabschnitt, der für die Verarbeitung der Eingabe zuständig ist
'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 print = console.log

// ---------------------------

/**
 * Usage (Linux/Unix): cat input.txt | node index.js
 */

function main() {
    const testCases = +readline()

    for (let i = 0; i < testCases; i++) {
        let len = readline().split(" ").map(Number)

        let a = readline()
        let b = readline()

        let pos = true;
        let ind;
        for(ind = 0; ind < len[1]; ind++){
            if(a[ind + 1 + len[0] - len[1]] != b[ind + 1]){
                pos = false;
            }
        }

        let pos2 = false;
        for(let ii = 0; ii < len[0] - ind - 1; ii++){
            if(a[ii] == b[0]){
                pos2 = true;
            }
        }

        if(!(pos && pos2)){
            print("NO")
        } else {
            print("YES")
        }
    }
}


You are given a picture consisting of $$$n$$$ rows and $$$m$$$ columns. Rows are numbered from $$$1$$$ to $$$n$$$ from the top to the bottom, columns are numbered from $$$1$$$ to $$$m$$$ from the left to the right. Each cell is painted either black or white. You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers $$$x$$$ and $$$y$$$, where $$$1 \le x \le n$$$ and $$$1 \le y \le m$$$, such that all cells in row $$$x$$$ and all cells in column $$$y$$$ are painted black.For examples, each of these pictures contain crosses:  The fourth picture contains 4 crosses: at $$$(1, 3)$$$, $$$(1, 5)$$$, $$$(3, 3)$$$ and $$$(3, 5)$$$.Following images don't contain crosses:  You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?You are also asked to answer multiple independent queries.

The first line contains an integer $$$q$$$ ($$$1 \le q \le 5 \cdot 10^4$$$) — the number of queries. The first line of each query contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 5 \cdot 10^4$$$, $$$n \cdot m \le 4 \cdot 10^5$$$) — the number of rows and the number of columns in the picture. Each of the next $$$n$$$ lines contains $$$m$$$ characters — '.' if the cell is painted white and '*' if the cell is painted black. It is guaranteed that $$$\sum n \le 5 \cdot 10^4$$$ and $$$\sum n \cdot m \le 4 \cdot 10^5$$$.

Print $$$q$$$ lines, the $$$i$$$-th line should contain a single integer — the answer to the $$$i$$$-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.

NoteThe example contains all the pictures from above in the same order.The first 5 pictures already contain a cross, thus you don't have to paint anything.You can paint $$$(1, 3)$$$, $$$(3, 1)$$$, $$$(5, 3)$$$ and $$$(3, 5)$$$ on the $$$6$$$-th picture to get a cross in $$$(3, 3)$$$. That'll take you $$$4$$$ minutes.You can paint $$$(1, 2)$$$ on the $$$7$$$-th picture to get a cross in $$$(4, 2)$$$.You can paint $$$(2, 2)$$$ on the $$$8$$$-th picture to get a cross in $$$(2, 2)$$$. You can, for example, paint $$$(1, 3)$$$, $$$(3, 1)$$$ and $$$(3, 3)$$$ to get a cross in $$$(3, 3)$$$ but that will take you $$$3$$$ minutes instead of $$$1$$$.There are 9 possible crosses you can get in minimum time on the $$$9$$$-th picture. One of them is in $$$(1, 1)$$$: paint $$$(1, 2)$$$ and $$$(2, 1)$$$.

const readline = require('readline');

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

var q, nn = 0, n, m , arr = [], ans;

rl.on("line", (line) => {
	if (q == null) q = parseInt(line);
	else if (nn == 0) {
		nn = parseInt(line.split(' ')[0]);
		m = parseInt(line.split(' ')[1]);
		n = 0;
		arr = [];
		ans = 1000000000;
	}
	else {
		arr.push(line);
		n ++;
		if (n == nn) {
			nn = 0;
			// begin to solve
			var row_cnt = arr.map( row => {
				var cnt = 0;
				for (var i = 0; i < m; i ++) if (row[i] == '*') cnt ++;
				return cnt;
			 } );
			var col_cnt = [];
			for (var i = 0; i < m; i ++) {
				var cnt = arr.reduce(
					(pre, nxt) => { if (nxt[i]=='*')  return pre+1; else return pre; },
					0
				 );
				 col_cnt.push(cnt);
			}
			for (var i = 0; i < n; i ++) {
				for (var j = 0; j < m; j ++) {
					var tmp = row_cnt[i] + col_cnt[j] - ( arr[i][j] == '*' ? 1 : 0 );
					ans = Math.min(ans, n+m-1-tmp);
				}
			}
			console.log(ans);

			// end of solve
			q --;
			if (q == 0)
				rl.close();
		}
	}
});

"use strict";

var main = function() {
    var q = +rd();
    while (q-->0) {
        var input = rdAr();
        var n = input[0];
        var m = input[1];

        var R = [];
        for (var i = 0; i < n; ++i) {
            R.push(rd());
        }

        var H = new Array(m).fill(0);
        var V = [];
        for (var i = 0; i < n; ++i) {
            V.push(0);
            for (var j = 0; j < m; ++j) {
                var isWhite = R[i][j] === '.';
                H[j] += +isWhite;
                V[i] += +isWhite;
            }
        }

        var result = +Infinity;
        for (var i = 0; i < n; ++i) {
            for (var j = 0; j < m; ++j) {
                var isWhite = R[i][j] === '.';
                var needToPaint = H[j] + V[i] - (+isWhite);
                result = Math.min(result, needToPaint);
            }
        }

        pr(result);
    }
};

var rd = readline;
var wr = write;
var pr = print;
var rdAr = () => rd().split(' ').map(v => +v);
var prAr = (a) => pr(a.join(' '));
var cmpLt = (a, b) => a - b;
var cmpGt = (a, b) => b - a;

main();


Pak Chanek, a renowned scholar, invented a card puzzle using his knowledge. In the puzzle, you are given a board with $$$n$$$ rows and $$$m$$$ columns. Let $$$(r, c)$$$ represent the cell in the $$$r$$$-th row and the $$$c$$$-th column.Initially, there are $$$k$$$ cards stacked in cell $$$(1, 1)$$$. Each card has an integer from $$$1$$$ to $$$k$$$ written on it. More specifically, the $$$i$$$-th card from the top of the stack in cell $$$(1, 1)$$$ has the number $$$a_i$$$ written on it. It is known that no two cards have the same number written on them. In other words, the numbers written on the cards are a permutation of integers from $$$1$$$ to $$$k$$$. All other cells are empty.You need to move the $$$k$$$ cards to cell $$$(n, m)$$$ to create another stack of cards. Let $$$b_i$$$ be the number written on the $$$i$$$-th card from the top of the stack in cell $$$(n, m)$$$. You should create the stack in cell $$$(n, m)$$$ in such a way so that $$$b_i = i$$$ for all $$$1 \leq i \leq k$$$.In one move, you can remove the top card from a cell and place it onto an adjacent cell (a cell that shares a common side). If the target cell already contains one or more cards, you place your card on the top of the stack. You must do each operation while satisfying the following restrictions:   Each cell other than $$$(1,1)$$$ and $$$(n,m)$$$ must not have more than one card on it.  You cannot move a card onto cell $$$(1,1)$$$.  You cannot move a card from cell $$$(n,m)$$$. Given the values of $$$n$$$, $$$m$$$, $$$k$$$ and the array $$$a$$$, determine if the puzzle is solvable.

Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 2 \cdot 10^4$$$) — the number of test cases. The following lines contain the description of each test case. The first line of each test case contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$3 \leq n, m \leq 10^6$$$, $$$nm \leq 10^6$$$, $$$1 \leq k \leq 10^5$$$) — the size of the board and the number of cards. The second line of the test case contains $$$k$$$ integers $$$a_1, a_2, \ldots, a_k$$$ — the array $$$a$$$, representing the numbers written on the cards. The values of $$$a$$$ are a permutation of integers from $$$1$$$ to $$$k$$$. It is guaranteed that the sum of $$$nm$$$ and $$$k$$$ over all test cases do not exceed $$$10^6$$$ and $$$10^5$$$ respectively.

For each test case, output "YA" (without quotes) if it is possible and "TIDAK" (without quotes) otherwise, which mean yes and no in Indonesian respectively. You can output "YA" and "TIDAK" in any case (for example, strings "tiDAk", "tidak", and "Tidak" will be recognised as a negative response).

NoteIn the first test case, the following is one way the puzzle can be done:   Move the card with $$$3$$$ written on it from cell $$$(1, 1)$$$ to cell $$$(1, 2)$$$, then cell $$$(1, 3)$$$.  Move the card with $$$6$$$ written on it from cell $$$(1, 1)$$$ to cell $$$(2, 1)$$$, then cell $$$(3, 1)$$$, then cell $$$(3, 2)$$$, then cell $$$(3, 3)$$$.  Move the card with $$$4$$$ written on it from cell $$$(1, 1)$$$ to cell $$$(1, 2)$$$.  Move the card with $$$1$$$ written on it from cell $$$(1, 1)$$$ to cell $$$(2, 1)$$$, then cell $$$(2, 2)$$$, then cell $$$(2, 3)$$$.  Move the card with $$$2$$$ written on it from cell $$$(1, 1)$$$ to cell $$$(2, 1)$$$, then cell $$$(2, 2)$$$.  Move the card with $$$5$$$ written on it from cell $$$(1, 1)$$$ to cell $$$(2, 1)$$$, then cell $$$(3, 1)$$$, then cell $$$(3, 2)$$$, then cell $$$(3, 3)$$$.  Move the card with $$$2$$$ written on it from cell $$$(2, 2)$$$ to cell $$$(2, 1)$$$.  Move the card with $$$4$$$ written on it from cell $$$(1, 2)$$$ to cell $$$(2, 2)$$$, then cell $$$(3, 2)$$$, then cell $$$(3, 3)$$$.  Move the card with $$$3$$$ written on it from cell $$$(1, 3)$$$ to cell $$$(1, 2)$$$, then cell $$$(2, 2)$$$, then cell $$$(3, 2)$$$, then cell $$$(3, 3)$$$.  Move the card with $$$2$$$ written on it from cell $$$(2, 1)$$$ to cell $$$(3, 1)$$$, then cell $$$(3, 2)$$$, then cell $$$(3, 3)$$$.  Move the card with $$$1$$$ written on it from cell $$$(2, 3)$$$ to cell $$$(3, 3)$$$. An animated illustration regarding the process mentioned above is as follows:

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

// your code goes here

// declare global variables
var input_stdin = "";
var lines = "";
var input_currentline = 0;

// standard input is stored into input_stdin
process.stdin.on('data', function (data) {
    input_stdin += data;
});

// standard input is done and stored into an array
process.stdin.on('end', function () {
    lines = input_stdin.split("\n");
    start();
});

function start() {
    const T = parseInt(lines[0])
    let line = 1
    for (let t = 1; t <= T; t++) {
        const n = parseInt(lines[line].split(' ')[0], 10)
        const m = parseInt(lines[line].split(' ')[1], 10)
        const k = parseInt(lines[line++].split(' ')[2], 10)
        let flag = new Array(k+1).fill(0);
        let current = k;
        let size = 0;
        let i = 0;
        const limit = n * m - 4;

        const a = lines[line].split(' ').map(x => parseInt(x, 10))

        for(i = 0; i < k; i++) {
            flag[a[i]] = 1;
            size++;
            while(flag[current] && current > 0) {
                current--;
                size--;
            }
            if (size > limit) {
                break;
            }
        }

        if (i < k) {
            console.log('TIDAK')
        } else {
            console.log('YA')
        }

        line++

    }
}

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

// your code goes here

// declare global variables
var input_stdin = "";
var lines = "";
var input_currentline = 0;

// standard input is stored into input_stdin
process.stdin.on('data', function (data) {
    input_stdin += data;
});

// standard input is done and stored into an array
process.stdin.on('end', function () {
    lines = input_stdin.split("\n");
    start();
});

function start() {
    const T = parseInt(lines[0])
    let line = 1
    for (let t = 1; t <= T; t++) {
        const n = parseInt(lines[line].split(' ')[0], 10)
        const m = parseInt(lines[line].split(' ')[1], 10)
        const k = parseInt(lines[line++].split(' ')[2], 10)
        let flag = new Array(k+1).fill(0);
        let current = k;
        let size = 0;
        let i = 0;
        const limit = n * m - 3;

        const a = lines[line].split(' ').map(x => parseInt(x, 10))

        for(i = 0; i < k; i++) {
            flag[a[i]] = 1;
            size++;
            while(flag[current] && current > 0) {
                current--;
                size--;
            }
            if (size > limit) {
                break;
            }
        }

        if (i < k) {
            console.log('TIDAK')
        } else {
            console.log('YA')
        }

        line++

    }
}

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

// your code goes here

// declare global variables
var input_stdin = "";
var lines = "";
var input_currentline = 0;

// standard input is stored into input_stdin
process.stdin.on('data', function (data) {
    input_stdin += data;
});

// standard input is done and stored into an array
process.stdin.on('end', function () {
    lines = input_stdin.split("\n");
    start();
});

function start() {
    const T = parseInt(lines[0])
    let line = 1
    for (let t = 1; t <= T; t++) {
        const n = parseInt(lines[line].split(' ')[0], 10)
        const m = parseInt(lines[line].split(' ')[1], 10)
        const k = parseInt(lines[line++].split(' ')[2], 10)
        let flag = new Array(k+1).fill(0);
        let current = k;
        let size = 0;
        let i = 0;
        const limit = n * m - 3;

        for(i = 0; i < k; i++) {
            const a = parseInt(lines[line].split(' ')[i], 10)
            flag[a] = 1;
            size++;
            while(flag[current] && current > 0) {
                current--;
                size--;
                console.log(current)
            }
            if (size > limit) {
                break;
            }
        }

        if (i < k) {
            console.log('TIDAK')
        } else {
            console.log('YA')
        }

        line++

    }
}


A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the i-th safe from the left is called safe i. There are n banknotes left in all the safes in total. The i-th banknote is in safe xi. Oleg is now at safe a. There are two security guards, one of which guards the safe b such that b < a, i.e. the first guard is to the left of Oleg. The other guard guards the safe c so that c > a, i.e. he is to the right of Oleg.The two guards are very lazy, so they do not move. In every second, Oleg can either take all the banknotes from the current safe or move to any of the neighboring safes. However, he cannot visit any safe that is guarded by security guards at any time, becaues he might be charged for stealing. Determine the maximum amount of banknotes Oleg can gather.

The first line of input contains three space-separated integers, a, b and c (1 ≤ b < a < c ≤ 109), denoting the positions of Oleg, the first security guard and the second security guard, respectively. The next line of input contains a single integer n (1 ≤ n ≤ 105), denoting the number of banknotes. The next line of input contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 109), denoting that the i-th banknote is located in the xi-th safe. Note that xi are not guaranteed to be distinct.

Output a single integer: the maximum number of banknotes Oleg can take.

NoteIn the first example Oleg can take the banknotes in positions 4, 5, 6 (note that there are 2 banknotes at position 5). Oleg can't take the banknotes in safes 7 and 8 because he can't run into the second security guard. Similarly, Oleg cannot take the banknotes at positions 3 and 2 because he can't run into the first security guard. Thus, he can take a maximum of 4 banknotes.For the second sample, Oleg can't take any banknotes without bumping into any of the security guards.

/*var c = readline()
var ar = []
var count = 0
var diff=9999999999999999999999999999;
var counter =0;
var k = readline().split(' ')

for(i=0,l=k.length;i<l;i++)
  {
      for(j=i+1,lp=k.length;j<lp;j++)
      {
          if(Math.abs(k[i]-k[j])<diff){
         diff=Math.abs(k[i]-k[j])
          ar.push(diff)

          }
      }
  }
for(i=0,l=k.length;i<l;i++)
{
    for(j=i+1,lp=k.length;j<lp;j++)
    {
        if((Math.abs(k[i]-k[j]==diff))||(Math.abs(k[j]-k[i])==diff)){
            counter++;
        }
    }
}

 write(diff+' '+counter)*/
/*
var l = []
var j = readline().split('');
if(j[0]!='0'){

for(i=0;i<j.length;i++){

       var d = parseInt(j[i])
       // print(d)
         if(d%3==0)
         {
           l.push(d)

         }
         else
        continue;
     }

 }

 if(l.length<=0)
{
    write(-1)
}

 if(l[0]==0&&l.length>1)
  {
      l[0]=''
     print(l.join(''))
  }

else
{
    print(l.join(''))
}
*/

var k = readline().split(' ').map(x=>parseInt(x))
var j = readline().split(' ').map(x=>parseInt(x))

var c = readline().split(' ').map(x=>parseInt(x))
var count =0;

          for(var ins=0;ins<c.length;ins++)
            {

                if(c[ins]!=k[1] && c[ins]!=k[2])
                   {

                       if(!(c[ins]>k[2] || c[ins]<k[1]))
                           //  print(c[ins])
                          count++;
                   }

            }
 print(count)

  var tmp = readline().split(' ').map(x => parseInt(x));
  var a = tmp[0];
  var b = tmp[1];
  var c = tmp[2];
  var n = parseInt(readline());
  var d = readline().split(' ').map(x => parseInt(x));
  print(d.filter(x => x > b && x < c).length);

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

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

  if (count === 1) {
    n = +d;
    count++;
    return;
  }

  const safes = d.split(' ').map(Number);
  let ans = 0;

  for (let i = 0; i < safes.length; i++) {
    if (safes[i] > b && safes[i] < c) {
      ans++;
    }
  }

  console.log(ans);

  count++;
});

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

const sol = () => {
    let line = data.trim().split(/\n/g);
    let [a, b, c]   = line[0].split(/\s/g).map(Number);
    let ans = line[2].split(/\s/g).map(Number).reduce((x,y) => x + ((y > b && y < c)?1:0), 0);
    console.log(ans);

};

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

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

const sol = () => {
    let line = data.trim().split(/\n/g);
    let [a, b, c]   = line[0].split(/\s/g).map(Number);
    let n = Number(line[1]);
    let s = line[2].split(/\s/g).map(Number);
    let ans = 0;
    for(let i of s){
        if (i > b && i < c) {
            ans++;
        }
    }

    console.log(ans);

};

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

/*var c = readline()
var ar = []
var count = 0
var diff=9999999999999999999999999999;
var counter =0;
var k = readline().split(' ')

for(i=0,l=k.length;i<l;i++)
  {
      for(j=i+1,lp=k.length;j<lp;j++)
      {
          if(Math.abs(k[i]-k[j])<diff){
         diff=Math.abs(k[i]-k[j])
          ar.push(diff)

          }
      }
  }
for(i=0,l=k.length;i<l;i++)
{
    for(j=i+1,lp=k.length;j<lp;j++)
    {
        if((Math.abs(k[i]-k[j]==diff))||(Math.abs(k[j]-k[i])==diff)){
            counter++;
        }
    }
}

 write(diff+' '+counter)*/
/*
var l = []
var j = readline().split('');
if(j[0]!='0'){

for(i=0;i<j.length;i++){

       var d = parseInt(j[i])
       // print(d)
         if(d%3==0)
         {
           l.push(d)

         }
         else
        continue;
     }

 }

 if(l.length<=0)
{
    write(-1)
}

 if(l[0]==0&&l.length>1)
  {
      l[0]=''
     print(l.join(''))
  }

else
{
    print(l.join(''))
}
*/

var k = readline().split('').map(function(x){
    return parseInt(x)}
    )
    var j = readline().split('').map(function(x){
    return parseInt(x)}
    )

    var c = readline().split('').map(function(x){
    return parseInt(x)}
    )
var count =0;
      for(var out=0;out<k.length;out++)
          for(var ins=0;ins<c.length;ins++)
            {

                if(c[ins]!=k[0])
                   count++;
                  break;
            }
 print(count-1)