function getMinSteps (a,b) {
  var countMinSteps = 0;

  var pos = Array.apply(null, Array(a+2)).map(Number.prototype.valueOf,0);

  for (var i=0; i<a; i++) {
    var item = b[i];

    pos[item] = pos[item-1] + 1;
  }

  countMinSteps = a - Math.max.apply(Math, pos);
  return countMinSteps;
}

var a = parseInt(readline());
var b = readline().split(" ").map(function(secondLine) { return parseInt(secondLine); });

print(getMinSteps (a,b));


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

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

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


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

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

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


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


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

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

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

/*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 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)


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(str => str.trim());

    main();
});

function readLine() {
    return inputString[currentLine++];
}
var gcd = function(a, b) {
    if (!b) {
      return a;
    }

    return gcd(b, a % b);
}

function main()
{
    //const name=readLine();
    //console.log(name);

    let test=readLine();
    while(test--)
    {
        aa=readLine();
        aa=aa.split(" ");
        let a=BigInt(aa[0]);
        let b=BigInt(aa[1]);
        if(a===b)
        {
            console.log(0,0);
            //cout<<0<<" "<<0<<endl;
            continue;
        }
        if(a===0 || b===0)
        {
            //console.log("Hello ",a,b);
            if(a!=0)
            {
                console.log(a.toString(),0);
                //cout<<a<<" "<<0<<endl;
            }
            else
            {
                console.log(b.toString(),0);
                //cout<<b<<" "<<0<<endl;
            }
            continue;
        }
        cur_gcd=gcd(a,b);
        //console.log("gcd ",cur_gcd);
        let mn;
        if(a<b)
            mn=a;
        else
            mn=b;
        let mx=a-b;
        if(mx<0)
            mx=b-a;
        mx=BigInt(mx)
        //console.log("Mx: ",mx);
        if(mx===cur_gcd)
        {
            console.log(mx.toString(),0);
            //cout<<cur_gcd<<" "<<0<<endl;
        }
        else
        {
            a=BigInt(a);
            b=BigInt(b);
            if(a%mx === b%mx)
            {
                let val=BigInt(a/mx);
                //console.log(val);
                let add=mx-(a- val*mx);
                add=BigInt(add)
                //console.log((a/mx));
                //console.log("add: ",add);
                //console.log(add,mx-add,Math.min(add,mx-add))
                //add=Math.min(add,mx-add);
                if((mx-add)<add)
                    add=mx-add;
                ///cout<<add<<endl;
                //console.log("add: ",add);
                if(add<mn)
                {
                    console.log(mx.toString(),add.toString());
                    //cout<<mx<<" "<<add<<endl;
                }
                else
                {
                    console.log(mx.toString(),mn.toString());
                    //cout<<mx<<" "<<mn<<endl;
                }
            }
            else
                console.log(mx.toString(),mn.toString())
                //cout<<mx<<" "<<mn<<endl;
        }
    }
}

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 => BigInt(x));

const min = (a, b) => a < b ? a : b;
const abs = a => a < 0 ? -a : a;

function main () {
	let T = rn();
	while (T--) {
		let [a, b] = rna();

		if (a == b) {
			console.log("0 0");
			continue;
		}

		const g = abs(a-b);
		const mvs = min(a % g, g - a % g);
		console.log(g.toString(), mvs.toString());
	}
}

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 solve() {
   const [a, b] = readArray(BigInt);
   const diff = a > b ? a - b : b - a;
   if (diff === 0n) {
      write('0 0');
      return;
   }
   const steps1 = a % diff;
   const steps2 = diff - steps1;
   const steps = steps1 > steps2 ? steps2 : steps1;
   write(diff + ' ' + steps);
}

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

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

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var l = 0;
    var t = +lines[l++]
    for (var i = 0; i < t; i++) {
        var [a, b] = lines[l++].trim().split(' ').map(BigInt)
        console.log(solve(a, b).join(' '))
    }
});

function solve(a, b) {
    if (a === b) return [0, 0]
    if (a > b) return solve(b, a)

    const d = a > b ? a - b : b - a
    const r = a % d
    if (r > d / 2n) {
        const op = d - r
        return [gcd(a + op, b + op), op]
    } else {
        return [gcd(a - r, b - r), r]
    }
}

function gcd(a, b) {
    if (a === 0n) return b
    if (b === 0n) return a

    while (a) {
        const r = b % a
        b = a
        a = r
    }
    return b
}

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(str => str.trim());

    main();
});

function readLine() {
    return inputString[currentLine++];
}
var gcd = function(a, b) {
    if (!b) {
      return a;
    }

    return gcd(b, a % b);
}

function main()
{
    //const name=readLine();
    //console.log(name);

    let test=readLine();
    while(test--)
    {
        aa=readLine();
        aa=aa.split(" ");
        let a=parseInt(aa[0]);
        let b=parseInt(aa[1]);
        if(a===b)
        {
            console.log(0,0);
            //cout<<0<<" "<<0<<endl;
            continue;
        }
        if(a===0 || b===0)
        {
            //console.log("Hello ",a,b);
            if(a!=0)
            {
                console.log(a,0);
                //cout<<a<<" "<<0<<endl;
            }
            else
            {
                console.log(b,0);
                //cout<<b<<" "<<0<<endl;
            }
            continue;
        }
        cur_gcd=gcd(a,b);
        //console.log("gcd ",cur_gcd);
        mn=Math.min(a,b);
        let mx=a-b;
        if(mx<0)
            mx=(-1)*mx;
        mx=BigInt(mx)
        //console.log("Mx: ",mx);
        if(mx===cur_gcd)
        {
            console.log(mx,0);
            //cout<<cur_gcd<<" "<<0<<endl;
        }
        else
        {
            a=BigInt(a);
            b=BigInt(b);
            if(a%mx === b%mx)
            {
                let val=BigInt(a/mx);
                //console.log(val);
                let add=mx-(a- val*mx);
                add=BigInt(add)
                //console.log((a/mx));
                //console.log("add: ",add);
                //console.log(add,mx-add,Math.min(add,mx-add))
                //add=Math.min(add,mx-add);
                if((mx-add)<add)
                    add=mx-add;
                ///cout<<add<<endl;
                //console.log("add: ",add);
                if(add<mn)
                {
                    console.log(mx.toString(),add.toString());
                    //cout<<mx<<" "<<add<<endl;
                }
                else
                {
                    console.log(mx.toString(),mn.toString());
                    //cout<<mx<<" "<<mn<<endl;
                }
            }
            else
                console.log(mx.toString(),mn.toString())
                //cout<<mx<<" "<<mn<<endl;
        }
    }
}

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(str => str.trim());

    main();
});

function readLine() {
    return inputString[currentLine++];
}
var gcd = function(a, b) {
    if (!b) {
      return a;
    }

    return gcd(b, a % b);
}

function main()
{
    //const name=readLine();
    //console.log(name);

    let test=readLine();
    while(test--)
    {
        aa=readLine();
        aa=aa.split(" ");
        let a=parseInt(aa[0]);
        let b=parseInt(aa[1]);
        if(a===b)
        {
            console.log(0,0);
            //cout<<0<<" "<<0<<endl;
            continue;
        }
        if(a===0 || b===0)
        {
            //console.log("Hello ",a,b);
            if(a!=0)
            {
                console.log(a,0);
                //cout<<a<<" "<<0<<endl;
            }
            else
            {
                console.log(b,0);
                //cout<<b<<" "<<0<<endl;
            }
            continue;
        }
        cur_gcd=gcd(a,b);
        //console.log("gcd ",cur_gcd);
        mn=Math.min(a,b);
        let mx=Math.abs(a-b);
        mx=BigInt(mx)
        //console.log("Mx: ",mx);
        if(mx===cur_gcd)
        {
            console.log(cur_gcd,0);
            //cout<<cur_gcd<<" "<<0<<endl;
        }
        else
        {
            a=BigInt(a);
            b=BigInt(b);
            if(a%mx === b%mx)
            {
                let val=BigInt(a/mx);
                let add=mx-(a- val*mx);
                add=BigInt(add)
                //console.log((a/mx));
                //console.log("add: ",add);
                //console.log(add,mx-add,Math.min(add,mx-add))
                //add=Math.min(add,mx-add);
                if((mx-add)<add)
                    add=mx-add;
                ///cout<<add<<endl;
                //console.log("add: ",add);
                if(add<mn)
                {
                    console.log(mx.toString(),add.toString());
                    //cout<<mx<<" "<<add<<endl;
                }
                else
                {
                    console.log(mx.toString(),mn.toString());
                    //cout<<mx<<" "<<mn<<endl;
                }
            }
            else
                console.log(mx.toString(),mn.toString())
                //cout<<mx<<" "<<mn<<endl;
        }
    }
}

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(str => str.trim());

    main();
});

function readLine() {
    return inputString[currentLine++];
}
var gcd = function(a, b) {
    if (!b) {
      return a;
    }

    return gcd(b, a % b);
}

function main()
{
    //const name=readLine();
    //console.log(name);

    let test=readLine();
    while(test--)
    {
        aa=readLine();
        aa=aa.split(" ");
        let a=parseInt(aa[0]);
        let b=parseInt(aa[1]);
        if(a===b)
        {
            console.log(0,0);
            //cout<<0<<" "<<0<<endl;
            continue;
        }
        if(a===0 || b===0)
        {
            //console.log("Hello ",a,b);
            if(a!=0)
            {
                console.log(a,0);
                //cout<<a<<" "<<0<<endl;
            }
            else
            {
                console.log(b,0);
                //cout<<b<<" "<<0<<endl;
            }
            continue;
        }
        cur_gcd=gcd(a,b);
        //console.log("gcd ",cur_gcd);
        mn=Math.min(a,b);
        let mx=Math.abs(a-b);
        mx=BigInt(mx)
        //console.log("Mx: ",mx);
        if(mx===cur_gcd)
        {
            console.log(cur_gcd,0);
            //cout<<cur_gcd<<" "<<0<<endl;
        }
        else
        {
            a=BigInt(a);
            b=BigInt(b);
            if(a%mx === b%mx)
            {
                let add=mx-(a- (a/mx)*mx);
                add=BigInt(add)
                //console.log((a/mx));
                //console.log("add: ",add);
                //console.log(add,mx-add,Math.min(add,mx-add))
                //add=Math.min(add,mx-add);
                if((mx-add)<add)
                    add=mx-add;
                ///cout<<add<<endl;
                //console.log("add: ",add);
                if(add<mn)
                {
                    console.log(mx.toString(),add.toString());
                    //cout<<mx<<" "<<add<<endl;
                }
                else
                {
                    console.log(mx.toString(),mn.toString());
                    //cout<<mx<<" "<<mn<<endl;
                }
            }
            else
                console.log(mx.toString(),mn.toString())
                //cout<<mx<<" "<<mn<<endl;
        }
    }
}

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(str => str.trim());

    main();
});

function readLine() {
    return inputString[currentLine++];
}
var gcd = function(a, b) {
    if (!b) {
      return a;
    }

    return gcd(b, a % b);
}

function main()
{
    //const name=readLine();
    //console.log(name);

    let test=readLine();
    while(test--)
    {
        aa=readLine();
        aa=aa.split(" ");
        a=parseInt(aa[0]);
        b=parseInt(aa[1]);
        if(a===b)
        {
            console.log(0,0);
            //cout<<0<<" "<<0<<endl;
            continue;
        }
        if(a===0 || b===0)
        {
            //console.log("Hello ",a,b);
            if(a!=0)
            {
                console.log(a,0);
                //cout<<a<<" "<<0<<endl;
            }
            else
            {
                console.log(b,0);
                //cout<<b<<" "<<0<<endl;
            }
            continue;
        }
        cur_gcd=gcd(a,b);
        //console.log("gcd ",cur_gcd);
        mn=Math.min(a,b);
        mx=Math.abs(a-b);
        //console.log("Mx: ",mx);
        if(mx===cur_gcd)
        {
            console.log(cur_gcd,0);
            //cout<<cur_gcd<<" "<<0<<endl;
        }
        else
        {
            if(a%mx === b%mx)
            {
                add=mx-(a-parseInt(a/mx)*mx);
                //console.log((a/mx));
                //console.log("add: ",add);
                //console.log(add,mx-add,Math.min(add,mx-add))
                add=Math.min(add,mx-add);
                ///cout<<add<<endl;
                //console.log("add: ",add);
                if(add<mn)
                {
                    console.log(mx,add);
                    //cout<<mx<<" "<<add<<endl;
                }
                else
                {
                    console.log(mx,mn);
                    //cout<<mx<<" "<<mn<<endl;
                }
            }
            else
                console.log(mx,mn)
                //cout<<mx<<" "<<mn<<endl;
        }
    }
}

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--) {
		let [a, b] = rna();

		if (a == b) {
			console.log("0 0");
			continue;
		}

		const gcd = Math.abs(a-b);
		const moves = Math.min(a % gcd, gcd - a % gcd);
		console.log(gcd, moves);
	}
}

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--) {
		let [a, b] = rna();

		if (a == b) {
			console.log("0 0");
			continue;
		}

		if ( a > b) [a, b] = [b, a];

		const gcd = b - a;
		const moves = Math.min(a, (gcd - b % gcd) % gcd);
		console.log(gcd, moves);
	}
}

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 [a, b] = rna();

		if (a == b) {
			console.log("0 0");
			continue;
		}

		const gcd = Math.abs(a - b);
		const moves = Math.min(Math.min(a, b), (gcd - a % gcd) % gcd);
		console.log(gcd, moves);
	}
}