Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.Your program has to support two operations:   Paint all cells in row ri in color ai;  Paint all cells in column ci in color ai. If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.Your program has to print the resulting table after k operation.

The first line of the input contains three integers n, m and k (1  ≤  n,  m  ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively. Each of the next k lines contains the description of exactly one query:    1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;  2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.

Print n lines containing m integers each — the resulting table after all operations are applied.

NoteThe figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.

try {require('codef');} catch (e){global = this};
function readLineAsArray(separator){return readline().split(typeof separator == "undefined" ? ' ' : separator)}
function readLineAsIntegerArray(separator){return readLineAsArray(separator).map(function(v){return +v})}
Array.prototype.list = function() {var length = arguments.length; for(var i=0; i < length; i++){global[arguments[i]] = this[i]}};
String.prototype.repeat = function(n){return new Array(n + 1).join(this);}

var tmp = readLineAsIntegerArray(),
	n = tmp[0],
	m = tmp[1],
	k = tmp[2];

var arr = [],
	moves = [];

for(var i = 0; i < n; i++) {
	arr.push([]);
	for(var j = 0; j < m; j++) {
		arr[i].push(0);
	}
}

function markH(index, c){
	index--;
	for(var j = 0; j < m; j++) {
		arr[index][j] = c;
	}
}
function markV(index, c){
	index--;
	for(var j = 0; j < n; j++) {
		arr[j][index] = c;
	}
}

function printM(){
	for(var i = 0; i < n; i++) {
		write(arr[i].join(' ') + '\n')
	}
}

var map = {1: {}, 2: {}};
var moves = [];

for(var i = 0 ; i < k; i++) {
	var item;
	moves.push(item = readLineAsIntegerArray());
	if (map[item[0]][item[1]]) {
		moves[map[item[0]][item[1]]] = false;
	}
	map[item[0]][item[1]] = i;
}

for(var i = 0; i < moves.length; i++) {
	if (moves[i]) {
		(moves[i][0] == 1 ? markH : markV)(moves[i][1], moves[i][2]);
	}
}

printM();

var arr = readline().split(" ", 3).map(Number);
var n = arr[0], m = arr[1], k = arr[2];

var rown = new Array(n), rowc = new Array(n);
var coln = new Array(m), colc = new Array(m);

for (var i = 0; i < k; ++i) {
	arr = readline().split(" ", 3).map(Number);
	--arr[1];
	if (arr[0] === 1) {
		rown[arr[1]] = i + 1;
		rowc[arr[1]] = arr[2];
	} else {
		coln[arr[1]] = i + 1;
		colc[arr[1]] = arr[2];
	}
}

for (var i = 0; i < n; ++i) {
	var ans = "";
	for (var j = 0; j < m; ++j) {
		if (rown[i]) {
			if (coln[j]) {
				ans += (rown[i] > coln[j] ? rowc[i] : colc[j]) + " ";
			} else {
				ans += rowc[i] + " ";
			}
		} else {
			if (coln[j]) {
				ans += colc[j] + " ";
			} else {
				ans += "0 ";
			}
		}
	}
	print(ans);
}

var arr = readline().split(" ", 3).map(Number);
var n = arr[0], m = arr[1], k = arr[2];

var map = new Array(n);
for (var i = 0; i < n; ++i) {
	map[i] = new Array(m);
	for (var j = 0; j < m; ++j) {
		map[i][j] = 0;
	}
}

var key = new Array(k);
for (var i = 0; i < k; ++i) {
	key[i] = readline().split(" ", 3).map(Number);
}

var rowu = new Array(n), rown = n;
var colu = new Array(m), coln = m;

var kk = k - 1;
while(rown !== 0 && coln !== 0 && kk >= 0) {
	var t = key[kk][1] - 1;
	if (key[kk][0] === 1) {
		if (!rowu[t]) {
			rowu[t] = true;
			--rown;
			for (var i = 0; i < m; ++i) {
				if (map[t][i] === 0) {
					map[t][i] = key[kk][2];
				}
			}
		}
	} else {
		if (!colu[t]) {
			colu[t] = true;
			--coln;
			for (var i = 0; i < n; ++i) {
				if (map[i][t] === 0) {
					map[i][t] = key[kk][2];
				}
			}
		}
	}
	--kk;
}

for (var i = 0; i < n; ++i) {
	print(map[i].join(" "));
}

try {require('codef');} catch (e){global = this};
function readLineAsArray(separator){return readline().split(typeof separator == "undefined" ? ' ' : separator)}
function readLineAsIntegerArray(separator){return readLineAsArray(separator).map(function(v){return +v})}
Array.prototype.list = function() {var length = arguments.length; for(var i=0; i < length; i++){global[arguments[i]] = this[i]}};
String.prototype.repeat = function(n){return new Array(n + 1).join(this);}

tmp = readLineAsIntegerArray();
var n = tmp[0],
	m = tmp[1],
	k = tmp[2];

var arr = [];
for(var i = 0; i < n; i++) {
	arr.push([]);
	for(var j = 0; j < m; j++) {
		arr[i].push(0);
	}
}

function markH(index, c){
	index--;
	for(var j = 0; j < m; j++) {
		arr[index][j] = c;
	}
}
function markV(index, c){
	index--;
	for(var j = 0; j < n; j++) {
		arr[j][index] = c;
	}
}

function printM(){
	for(var i = 0; i < n; i++) {
		write(arr[i].join(' '));
	}
}

for(var i = 0 ; i < k; i++) {
	var tmp = readLineAsIntegerArray();
	(tmp[0] == 1 ? markH : markV)(tmp[1], tmp[2]);
	//printM();
	//console.log('================');
}
printM();


Stepan had a favorite string s which consisted of the lowercase letters of the Latin alphabet. After graduation, he decided to remember it, but it was a long time ago, so he can't now remember it. But Stepan remembers some information about the string, namely the sequence of integers c1, c2, ..., cn, where n equals the length of the string s, and ci equals the number of substrings in the string s with the length i, consisting of the same letters. The substring is a sequence of consecutive characters in the string s.For example, if the Stepan's favorite string is equal to "tttesst", the sequence c looks like: c = [7, 3, 1, 0, 0, 0, 0].Stepan asks you to help to repair his favorite string s according to the given sequence c1, c2, ..., cn.

The first line contains the integer n (1 ≤ n ≤ 2000) — the length of the Stepan's favorite string. The second line contains the sequence of integers c1, c2, ..., cn (0 ≤ ci ≤ 2000), where ci equals the number of substrings of the string s with the length i, consisting of the same letters. It is guaranteed that the input data is such that the answer always exists.

Print the repaired Stepan's favorite string. If there are several answers, it is allowed to print any of them. The string should contain only lowercase letters of the English alphabet.

NoteIn the first test Stepan's favorite string, for example, can be the string "kkrrrq", because it contains 6 substrings with the length 1, consisting of identical letters (they begin in positions 1, 2, 3, 4, 5 and 6), 3 substrings with the length 2, consisting of identical letters (they begin in positions 1, 3 and 4), and 1 substring with the length 3, consisting of identical letters (it begins in the position 3).

var n = parseInt(readline());
var a = readline().split(" ").map(Number);

var s = "";
var cur = 'a';
for (var i = n - 1; i >= 0; i--) {
	while (a[i]) {
		for (var j = 0; j <= i; j++) {
			s += cur;
			a[j] -= (i - j + 1);
		}
		if (cur=="a") cur = "b"; else cur = "a";
	}
}
print(s);

var n = +readline();
var v = readline().split(' ').map(function(k){return +k;});
v.splice(0,0,0);
var ans = [];
for(var i = n; i > 0; i--){
    if(v[i] === 0)
        continue;
    for(var k = 0; k < v[i]; k++)
        ans.push(i);
    for(var j = i - 1; j > 0; j--)
        v[j] -= v[i] * (i - j + 1);
}
for(var i = 0; i < ans.length; i++){
    for(var j = 0; j < ans[i]; j++){
        if(i % 2 == 1) write("b");
        else write("a");
    }
}

var n = +readline();
var a = readline().split(' ').map(function(v) { return +v; });
var groups = [];
for (var i = n-1; i >= 0; i--) {
    var knt = a[i];
    for (var j = 0; j < knt; j++) {
        groups.push(i+1);
    }
    for (var j = 0; j <= i; j++) {
        a[i-j] -= knt * (j+1);
    }
}
var res = "";
var c = 'a';
for (var i = 0; i < groups.length; i++) {
    for (var j = 0; j < groups[i]; j++) {
        res += c;
    }
    c = (c == 'a') ? 'b' : 'a';
}
print(res);


You are given a positive integer $$$n$$$.The weight of a permutation $$$p_1, p_2, \ldots, p_n$$$ is the number of indices $$$1\le i\le n$$$ such that $$$i$$$ divides $$$p_i$$$. Find a permutation $$$p_1,p_2,\dots, p_n$$$ with the minimum possible weight (among all permutations of length $$$n$$$).A permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 10^4$$$). The description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of permutation. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print a line containing $$$n$$$ integers $$$p_1, p_2,\dots, p_n$$$ so that the permutation $$$p$$$ has the minimum possible weight. If there are several possible answers, you can print any of them.

NoteIn the first test case, the only valid permutation is $$$p=[1]$$$. Its weight is $$$1$$$.In the second test case, one possible answer is the permutation $$$p=[2,1,4,3]$$$. One can check that $$$1$$$ divides $$$p_1$$$ and $$$i$$$ does not divide $$$p_i$$$ for $$$i=2,3,4$$$, so the weight of this permutation is $$$1$$$. It is impossible to find a permutation of length $$$4$$$ with a strictly smaller weight.

t = readline()
for(var i = 0; i < t;i++)
{
    n = readline();
    print(n, ' ');
    for(var j = 1 ; j < n;j++)
    {
        print(j, ' ');
    }
}

var a = parseInt(readline());

for(var i = 0; i < a; i++){
	var n = parseInt(readline());

	var arr = [n];

	// arr.push(n);

	for(var j = 1; j < n; j++){
		arr.push(j);
	}

	// arr.push(1);

	// if(n === 1){
	// 	print(1);
	// }
	// else{
	// 	print(arr.join(' '));
	// }

	print(arr.join(' '));
}

var a = parseInt(readline());

for(var i = 0; i < a; i++){
	var n = parseInt(readline());

	var arr = [n];

	arr.push(1);

	for(var j = 2; j < n; j++){
		arr.push(j);
	}

	if(n === 1){
		print(1);
	}
	else{
		print(arr.join(' '));
	}
}

var t = parseInt(readline());

while (t--) {
    var n = parseInt(readline());
    var result = [];
    for (var i = 0; i < n - 1; i++) {
        result.push(i + 2);
    }
    result.push(1);
    print(result.join(" "));
}

var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var value = parseInt(readline());
    var result = "";
    for (var j = 2; j <= value; j++)
    {
        result += `${j} `;
    }
    result += "1 ";
    print(result);
}

var tests = parseInt(readline());
    for (var t=0; t < tests; t++) {
        var n = parseInt(readline());
        var ans = [ n ];
        for (var i = 0; i < n-1; i++) {
            ans.push(i+1);
        }
        print(ans.join(' '));
    }

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

    }

});

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		if(N == 1){
			myout(1);
			continue;
		}
		var output = [N];
		for(var i = 1; i < N ; i++){
			output.push(i);
		}
		myout(myconv(output, 8));
	}
}

'use strict';

const fs = require('fs');

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', function() {
    inputString = inputString.split('\n');

    main();
});

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

function calc(n) {
    if (n == 1) {
        console.log(1)
        return
    } else if (n == 2) {
        console.log("2 1")
        return
    } else if (n == 3) {
        console.log("3 1 2")
        return
    }

    let s = "2 1"
    for (let i = 3; i <= n - 1; i++) {
        s += " " + (i + 1)
    }

    s += " 3"
    console.log(s)
}

function main() {
    // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);

    const test_cases = parseInt(readLine().trim(), 10);

    for (let gItr = 0; gItr < test_cases; gItr++) {
        const n = parseInt(readLine().trim(), 10);

        if (n >= 1 && n <= 100000) {
           // const val = readLine().replace(/\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));
            let output = calc(n);
            // console.log(output)
        }
        // ws.write(result + '\n');
    }

    // ws.end();
}

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

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

let inputString = "";
let currentLine = 0;

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

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

function readNumbersLine() {
    return readline().split(" ").map(el => +el);
}

let arr = {};
let ans = [0, 0];

function main() {
    let k = +readline()
    for (let i = 0; i < k; i++) {
        let n = +readline()
        let res = ""
        for (let j = 2; j <= n; j++) {
            res += j +' ';
        }
        res += 1;
        console.log(res);
    }

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main(){
    var tests = parseInt(readline());
    for (let t = 0;t < tests; ++t) {
        var n = parseInt(readline());
        let arr = [n];
        for (let i = 1;i < n;++i) {
            arr.push(i);
        }
        console.log(arr.join(' ').toString());
    }

}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}
function getValue() {
  return parseInt(readline());
}
let mod = BigInt(1e9 + 7);
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue(),
      res = [];
    if (n === 1) console.log(1);
    else {
      let arr = new Array(n).fill(0).map((cur, ind) => ind + 1);
      for (let i = 0; i + 1 < n; i += 2) {
        [arr[i], arr[i + 1]] = [arr[i + 1], arr[i]];
      }
      if (n % 2 === 0) console.log(arr.join(" "));
      else {
        [arr[0], arr[n - 1]] = [arr[n - 1], arr[0]];
        console.log(arr.join(" "));
      }
    }
  }
};
solve();

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

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

    for (let test = 0; test < N; test++) {
        let n = parseInt(readline(), 10);

        let result = [];

        for (let i = 2; i <= n; i++) {
            result.push(i);
        }
        result.push(1);

        output(result.join(' '));
    }
}

t = readline()
for(var i = 0; i < t;i++ )
{
var start = readline(), end = readline();
var arr = [];

arr.push(end)
for (var i = start; i < end; i++) { arr.push(i) }

print(start)
print(arr.join(' '))
}

t = readline()
for(var i = 0; i < t;i++ )
{
    n = readline(), start = readline(), end = readline();
var arr = [];

arr.push(end)
for (var i = start; i < end; i++) { arr.push(i) }

print(start)
print(arr.join(' '))
}

var n = readline(), start = readline(), end = readline();
var arr = [];

arr.push(end)
for (var i = start; i < end; i++) { arr.push(i) }

print(start)
print(arr.join(' '))

for (var x = 2; x < parseInt(n); x++) {
	var end = readline();
	var arr = [];

	arr.push(end)
	for (var i = start; i < end; i++) { arr.push(i) }
	print(arr.join(' '))
}

var n = readline(), start = readline(), end = readline();
var arr = [];

arr.push(end)
for (var i = start; i < end; i++) { arr.push(i) }

print(start)
print(arr.join(' '))

for (var x = 2; x < parseInt(n); x++) {
	var end = readline();
	var arr = [];

	arr.push(end)
	for (var i = start; i < end; i++) { arr.push(i) }

	print(start)
	print(arr.join(' '))
}

var n = readline(), start = readline(), end = readline();
var arr = [];

arr.push(end)
for (var i = start; i < end; i++) { arr.push(i) }

print(start)
print(arr.join(' '))

for (var x = 2; x < parseInt(n); x++) {
	var start = end, end = readline();
	var arr = [];

	arr.push(end)
	for (var i = start; i < end; i++) { arr.push(i) }

	print(start)
	print(arr.join(' '))
}

var n = readline(), start = readline(), end = readline();
var arr = [];

arr.push(end)
for (var i = start; i < end; i++) { arr.push(i) }

print(start)
print(arr.join(' '))

for (var x = 1; x < parseInt(n); x++) {
	var start = end, end = readline();
	var arr = [];

	arr.push(end)
	for (var i = start; i < end; i++) { arr.push(i) }

	print(start)
	print(arr.join(' '))
}

var n = readline(), start = readline(), end = readline();
var arr = [];

arr.push(end)
for (var i = start; i < end; i++) { arr.push(i) }

print(start)
print(arr.join(' '))

for (var x = 1; x < n; x++) {
	var start = end, end = readline();
	var arr = [];

	arr.push(end)
	for (var i = start; i < end; i++) { arr.push(i) }

	print(start)
	print(arr.join(' '))
}

var n = readline(), start = readline(), end = readline();
var arr = [];

arr.push(end)
for (var i = start; i < end; i++) { arr.push(i) }

print(start)
print(arr.join(' '))

for (var i = 0; i < n - 1; i++) {
	var start = end, end = readline();
	var arr = [];

	arr.push(end)
	for (var i = start; i < end; i++) { arr.push(i) }

	print(start)
	print(arr.join(' '))
}

var n = readline(), start = readline(), end = readline();
var arr = [];

arr.push(end)
for (var i = start; i < end; i++) { arr.push(i) }

print(start)
print(arr.join(' '))

for (var i = 0; i < n; i++) {
	var start = end, end = readline();
	var arr = [];

	arr.push(end)
	for (var i = start; i < end; i++) { arr.push(i) }

	print(start)
	print(arr.join(' '))
}

var n = readline(), start = readline(), end = readline();
var arr = [];

arr.push(end)
for (var i = start; i < end; i++) { arr.push(i) }

print(start)
print(arr.join(' '))

for (var i = 0; i <= n; i++) {
	var start = end, end = readline();
	var arr = [];

	arr.push(end)
	for (var i = start; i < end; i++) { arr.push(i) }

	print(start)
	print(arr.join(' '))
}

var n = readline(), start = readline(), end = readline();
var arr = [];

arr.push(end)
for (var i = start; i < end; i++) { arr.push(i) }

print(1)
print(arr.join(' '))

var n = readline(), start = readline(), end = readline();
var arr = [];

arr.push(end)
for (var i = start; i < end; i++) { arr.push(i) }

print(arr.join(' '))

var n = readline(), start = readline(), end = readline();
var arr = [];

for (var i = start; i <= end; i++) { arr.push(i) }
arr.reverse()

print(arr.join(' '))

var n = readline(), start = readline(), end = readline();
var arr = [];

for (var i = start; i < end; i++) { arr.push(i) }

arr.reverse()

print(arr.join(' '))

var a = parseInt(readline());

for(var i = 0; i < a; i++){
	var n = parseInt(readline());

	var arr = [n];

	arr.push(n);

	for(var j = 1; j < n; j++){
		arr.push(j);
	}

	// arr.push(1);

	// if(n === 1){
	// 	print(1);
	// }
	// else{
	// 	print(arr.join(' '));
	// }

	print(arr.join(' '));
}

var a = parseInt(readline());

for(var i = 0; i < a; i++){
	var n = parseInt(readline());

	var arr = [n];

	arr.push(n);

	for(var j = 2; j < n; j++){
		arr.push(j);
	}

	// arr.push(1);

	// if(n === 1){
	// 	print(1);
	// }
	// else{
	// 	print(arr.join(' '));
	// }

	print(arr.join(' '));
}

var a = parseInt(readline());

for(var i = 0; i < a; i++){
	var n = parseInt(readline());

	var arr = [n];

	// arr.push(1);

	for(var j = 2; j < n; j++){
		arr.push(j);
	}

	arr.push(1);

	// if(n === 1){
	// 	print(1);
	// }
	// else{
	// 	print(arr.join(' '));
	// }

	print(arr.join(' '));
}

var a = parseInt(readline());

for(var i = 0; i < a; i++){
	var n = parseInt(readline());

	var arr = [n];

	arr.push(1);

	for(var j = 2; j < n; j++){
		arr.push(j);
	}

	print(arr.join(' '));
}

var a = parseInt(readline());

for(var i = 0; i < a; i++){
	var n = parseInt(readline());

	var arr = [n];

	arr.push(1);

	for(var j = 2; j <= n; j++){
		arr.push(j);
	}

	print(arr.join(' '));
}

var a = parseInt(readline());

for(var i = 0; i < a; i++){
	var n = parseInt(readline());

	var arr = [n];

	for(var j = 1; j <= n; j++){
		arr.push(j);
	}

	print(arr.join(' '));
}

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

});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    var k = lines[1].split(' ').map(Number)
    var a = k[k.length - 1] + ' '
    for(j = 1; j < n ;j ++){
        a +k[j] + ' '
    }

});

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

    }
    console.log(1)
    console.log(1 + ' ' + 2 + ' ' + 3 + ' ' + 4)

});

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

    }
    console.log(1)
    console.log(2 + ' ' + 1 + ' ' + 4 + ' ' + 3)

});

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		if(N == 1){
			myout(1);
			continue;
		}
		var output = [];
		for(var i = 0; i < N / 2; i++){
			output.push(i * 2 + 2);
			output.push(i * 2 + 1);
		}
		myout(myconv(output, 8));
	}
}

'use strict';

const fs = require('fs');

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', function() {
    inputString = inputString.split('\n');

    main();
});

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

function calc(n) {
    if (n == 1) {
        console.log(1)
        return
    }

    let s = "2 1"
    for (let i = 3; i <= n - 1; i++) {
        s += " " + (i + 1)
    }

    s += " 3"
    console.log(s)
}

function main() {
    // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);

    const test_cases = parseInt(readLine().trim(), 10);

    for (let gItr = 0; gItr < test_cases; gItr++) {
        const n = parseInt(readLine().trim(), 10);

        if (n >= 1 && n <= 100000) {
           // const val = readLine().replace(/\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));
            let output = calc(n);
            // console.log(output)
        }
        // ws.write(result + '\n');
    }

    // ws.end();
}

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

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

let inputString = "";
let currentLine = 0;

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

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

function readNumbersLine() {
    return readline().split(" ").map(el => +el);
}

let arr = {};
let ans = [0, 0];

function main() {
    let k = +readline()
    for (let i = 0; i < k; i++) {
        let n = +readline()
        let res = ""
        for (let j = 2; j <= n; j++) {
            res += j;
        }
        res += 1;
        console.log(res);
    }

}


Burenka and Tonya are playing an old Buryat game with a chip on a board of $$$n \times m$$$ cells.At the beginning of the game, the chip is located in the lower left corner of the board. In one move, the player can move the chip to the right or up by any odd number of cells (but you cannot move the chip both to the right and up in one move). The one who cannot make a move loses.Burenka makes the first move, the players take turns. Burenka really wants to win the game, but she is too lazy to come up with a strategy, so you are invited to solve the difficult task of finding it. Name the winner of the game (it is believed that Burenka and Tonya are masters of playing with chips, so they always move in the optimal way).    Chip's starting cell is green, the only cell from which chip can't move is red. if the chip is in the yellow cell, then blue cells are all options to move the chip in one move.

The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The following is a description of the input data sets. The only line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 10^9$$$) — the dimensions of the game board.

For each test case print a single line — the name of the winner of the game ("Burenka" or "Tonya").

Tonya
Burenka
Burenka
Tonya
Burenka
Burenka

NoteIn the first case, Burenka has no move, so Tonya wins.In the second case, Burenka can move $$$3$$$ cells to the right, after which Tony will not be able to make a move, which means that Burenka wins.In the third case, Burenka can move $$$5$$$ squares to the right. Then we can say that we have a game on a board of $$$1 \times 5$$$ cells, and Tonya is the first player. In such game the second player wins, so in the original one Burenka will win.

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

var data = [];
var sum = 0;
readline.once("line", (_n) => {
  readline.on("line", (line) => {
    data.push(line);
    if (data.length == _n) {
      data.map((m) => {
        [a, b] = m.split(" ");
        let x= parseInt(a);
        let y= parseInt(b);
        if ((x&1 && y&1) || (x%2 === 0 && y%2 === 0)) {
            console.log('Tonya');
        }
        else
            console.log('Burenka');

      });
      readline.close();
    }
  });
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0],e=0, k = 0
    for(j = 1; j <= n; j++){
        k = lines[j].split(' ').map(Number)
        a = k[0]
        b = k[1]
        if(a % 2 === 0 && b % 2 === 0 || a % 2 == 1 && b % 2 == 1){
            console.log('Tonya')
        }else{
            console.log("Burenka");

        }
    }

});

'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 solve(x, y){
    if ((x + y) % 2){
        console.log("Burenka");
    }
    else
        console.log("Tonya");
}

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

    while (t--){
        let [a,b] = readline().split(" ").map(x => parseInt(x));
        solve(a,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((string) => {
      return string.trim();
    });

  main();
});

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

/***
Codeforces Round #814 (Div. 2)
2022-08-16

A. Chip Game
***/

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

  for (let i = 0; i < t; i++) {
    const board = readline().split(" ");
    const n = parseInt(board[0]);
    const m = parseInt(board[1]);

    // not-odd chip game solved in Explorations
    // we need n=m or even number of squares to diagonal for P2 to win
    console.log((m - n) % 2 == 0 ? "Tonya" : "Burenka");
  }
}

function formula(a, b, c) {
  return (a ^ b) + (b ^ c) + (a ^ 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++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, m] = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, m) ? 'Burenka' : 'Tonya'
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, m) {
    return (cal(n) + cal(m)) & 1
}
function cal(n) {
    if (n === 1) return 0
    return ((n - 1) & 1) ? 1 : 2
}

'use strict';

const fs = require('fs');

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', function() {
    inputString = inputString.split('\n');

    main();
});

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

function isPossible(n, x, heights) {
    heights.sort();
    heights.sort(function(a, b) {
        return a - b;
      });
    // //console.log(heights)

    let front = []
    let back = []

    for (let i = 0; i < heights.length; i++) {
        if (i < n) {
            front.push(heights[i])
        } else {
            back.push(heights[i])
        }
    }

    // //console.log(front)
    // //console.log(back)
    for (let j = 0; j < front.length; j++) {
        if (back[j] - front[j] < x) {
            // //console.log(back[j] + " " + front[j])
            return "NO";
        }
    }

    return "YES";
}

function calc(a, m) {
    let s = "";
    for (let index = 0; index < m; index++) {
        s += "B"
    }

   for (let index = 0; index < a.length; index++) {
        let ai = a[index];

        if (ai < (m + 1 - ai)) {
            let _s = s.replaceAt(ai - 1, "A");
            if (compare(_s, s) < 0) {
                s = _s;
                continue;
            } else if (compare(_s, s) >= 0) {
                    let __ss = s.replaceAt(m + 1 - ai - 1, "A");
                    if (compare(__ss, s) < 0) {
                        s = __ss;
                        continue;
                    }
            }
         }  else {
            let _s = s.replaceAt(m + 1 - ai - 1, "A");
            if (compare(_s, s) < 0) {
                s = _s;
                continue;
            }  if (compare(_s, s) >= 0) {
                    let __ss = s.replaceAt(ai - 1, "A");
                    if (compare(__ss, s) < 0) {
                        s = __ss;
                        continue;
                    }
            }
    }
}

   return s;
}

function compare(s1, s2) {
    return s1.localeCompare(s2)
}

String.prototype.replaceAt = function(index, replacement) {
    return this.substring(0, index) + replacement + this.substring(index + replacement.length);
}

function main() {
    // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);

    const test_cases = parseInt(readLine().trim(), 10);

    for (let gItr = 0; gItr < test_cases; gItr++) {
        // const n = parseInt(readLine().trim(), 10);
        const arr = readLine().replace(/\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));

        const n = arr[0]
        const m = arr[1]

        if (n == 1 && m == 1) {
            console.log("Tonya")
        } else {
            if ((n%2 ==0 && m%2 == 0) || (n%2 == 1 && m%2 == 1))  {
                console.log("Tonya")
            } else {
                console.log("Burenka")
            }
        }

    }

    // ws.end();
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var k = lines[i].split(' ').map(Number);
        var a = k[0], b = k[1];
        if((a % 2 === 0 && b % 2 === 0) || (a % 2 !== 0 && b % 2 !== 0)){
			console.log('Tonya');
		}
		else{
			console.log("Burenka");
		}
    }
});

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var M = nextInt();
		if((N + M) % 2 == 0){
			myout("Tonya");
		}else{
			myout("Burenka");
		}
	}
}

const fs = require("fs");

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

const testCases = [];
let T;

function parseInput() {
  T = parseInt(input[0]);
  let index = 0;

  for (let i = 0; i < T; i++) {
    index++;
    const [n, m] = input[index].split(" ").map((item) => parseInt(item));
    const testCase = {
      n,
      m,
    };

    testCases.push(testCase);
  }
}

function solution(testCase) {
  const { n, m } = testCase;

  let result = (n + m) % 2 ? "Burenka" : "Tonya";
  console.log(result);
}

parseInput();

testCases.forEach(solution);

'use strict';

function solve(a) {
  const [n, m] = a;
  if ((n & 1) === (m & 1)) return 'Tonya';
  return 'Burenka';
}

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

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

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

    for (let test = 0; test < N; test++) {
        const [n, m] = readline().split(' ').map(Number);

        const nEven = n % 2 === 0;
        const mEven = m % 2 === 0;

        if ((nEven && mEven) || (!nEven && !mEven)) {
            output('Tonya');
        } else {
            output('Burenka');
        }
    }
}

let i = '';
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL); /*your input text, split by lines*/
    let cases = parseInt(lines[0])
    //const splitLines = lines.map(x => x.split(" ").map(x => parseInt(x)))
    for (let i = 1; i <= cases; i ++)
    {
        let a = lines[i].split(" ").map(x => parseInt(x))
        if ((a[0] + a[1]) % 2 == 0)
        {
            console.log("Tonya")
        }
        else{
            console.log("Burenka")
        }
    }
})

var n, m;

    var tests = parseInt(readline());
    for (var t=0; t<tests;t++) {
        var nm = readline().split(' ').map(x=>parseInt(x));
        n = nm[0];
        m = nm[1];
        if ((n+m) & 1) {
            print('Burenka')
        } else {
            print('Tonya')
        }
    }

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

var data = [];
var sum = 0;
readline.once("line", (_n) => {
  readline.on("line", (line) => {
    data.push(line);
    if (data.length == _n) {
      data.map((m) => {
        [a, b] = m.split(" ");
        let x= parseInt(a);
        let y= parseInt(b);
        if ((x === 1 && y === 1) || (x%2 === 0 && y%2 === 0)) {
            console.log('Tonya');
        }
        else
            console.log('Burenka');

      });
      readline.close();
    }
  });
});

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

var data = [];
var sum = 0;
readline.once("line", (_n) => {
  readline.on("line", (line) => {
    data.push(line);
    if (data.length == _n) {
      data.map((m) => {
        [a, b] = m.split(" ");
        let x= parseInt(a);
        let y= parseInt(b);
        if (x === y) {
            console.log('Tonya');
        }
        else if(x !== y && (x%2 === 1 || y%2 ===1))
            console.log('Burenka');

      });
      readline.close();
    }
  });
});

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

var data = [];
var sum = 0;
readline.once("line", (_n) => {
  readline.on("line", (line) => {
    data.push(line);
    if (data.length == _n) {
      data.map((m) => {
        [a, b] = m.split(" ");
        let x= parseInt(a);
        let y= parseInt(b);
        if (x === y) {
            console.log('Tonya');
        }
        else
            console.log('Burenka');

      });
      readline.close();
    }
  });
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0],e=0, k = 0
    for(j = 1; j <= n; j++){
        k = lines[j].split(' ').map(Number)
        a = k[0]
        b = k[1]
        if(a % 2 === 0 && b % 2 === 0){
            console.log('Tonya')
        }else{
            console.log("Burenka");

        }
    }

});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    var a = 0
    for(j = 1; j <= n ;j ++){
    var k = lines[j].split(' ').map(Number)
    if(k[0] == k[1]){
        console.log('Tonya')
    }else{
         console.log('Burenka')
    }
    }

});

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

/***
Codeforces Round #814 (Div. 2)
2022-08-16

A. Chip Game
***/

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

  for (let i = 0; i < t; i++) {
    const board = readline().split(" ");
    const n = parseInt(board[0]);
    const m = parseInt(board[1]);

    // same as not-odd chip game, solved in Explorations
    console.log(Math.floor(n / 2) == Math.floor(m / 2) ? "Tonya" : "Burenka");
  }
}

function formula(a, b, c) {
  return (a ^ b) + (b ^ c) + (a ^ c);
}

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

/***
Codeforces Round #814 (Div. 2)
2022-08-16

A. Chip Game
***/

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

  for (let i = 0; i < t; i++) {
    const board = readline().split(" ");
    const n = parseInt(board[0]);
    const m = parseInt(board[1]);

    // same as not-odd chip game, solved in Explorations
    console.log(n == m ? "Tonya" : "Burenka");
  }
}

function formula(a, b, c) {
  return (a ^ b) + (b ^ c) + (a ^ 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++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, m] = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, m) ? 'Burenka' : 'Tonya'
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, m) {
    if (n > m) return solve(m, n)
    // [1, odd] - false
    // [1, even] - true
    if (n === 1) return (m - 1) & 1
    if ((n & 1) || (m & 1)) return true
    return false
}

'use strict';

const fs = require('fs');

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', function() {
    inputString = inputString.split('\n');

    main();
});

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

function isPossible(n, x, heights) {
    heights.sort();
    heights.sort(function(a, b) {
        return a - b;
      });
    // //console.log(heights)

    let front = []
    let back = []

    for (let i = 0; i < heights.length; i++) {
        if (i < n) {
            front.push(heights[i])
        } else {
            back.push(heights[i])
        }
    }

    // //console.log(front)
    // //console.log(back)
    for (let j = 0; j < front.length; j++) {
        if (back[j] - front[j] < x) {
            // //console.log(back[j] + " " + front[j])
            return "NO";
        }
    }

    return "YES";
}

function calc(a, m) {
    let s = "";
    for (let index = 0; index < m; index++) {
        s += "B"
    }

   for (let index = 0; index < a.length; index++) {
        let ai = a[index];

        if (ai < (m + 1 - ai)) {
            let _s = s.replaceAt(ai - 1, "A");
            if (compare(_s, s) < 0) {
                s = _s;
                continue;
            } else if (compare(_s, s) >= 0) {
                    let __ss = s.replaceAt(m + 1 - ai - 1, "A");
                    if (compare(__ss, s) < 0) {
                        s = __ss;
                        continue;
                    }
            }
         }  else {
            let _s = s.replaceAt(m + 1 - ai - 1, "A");
            if (compare(_s, s) < 0) {
                s = _s;
                continue;
            }  if (compare(_s, s) >= 0) {
                    let __ss = s.replaceAt(ai - 1, "A");
                    if (compare(__ss, s) < 0) {
                        s = __ss;
                        continue;
                    }
            }
    }
}

   return s;
}

function compare(s1, s2) {
    return s1.localeCompare(s2)
}

String.prototype.replaceAt = function(index, replacement) {
    return this.substring(0, index) + replacement + this.substring(index + replacement.length);
}

function main() {
    // const ws = fs.createWriteStream(process.env.OUTPUT_PATH);

    const test_cases = parseInt(readLine().trim(), 10);

    for (let gItr = 0; gItr < test_cases; gItr++) {
        // const n = parseInt(readLine().trim(), 10);
        const arr = readLine().replace(/\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));

        const n = arr[0]
        const m = arr[1]

        if (n == 1 && m == 1) {
            console.log("Tonya")
        } else {
            if (n%2 ==0 && m%2 == 0) {
                console.log("Tonya")
            } else {
                console.log("Burenka")
            }
        }

    }

    // ws.end();
}


Even if it's a really easy question, she won't be able to answer it— Perfect Memento in Strict SenseCirno's perfect bitmasks classroom has just started!Cirno gave her students a positive integer $$$x$$$. As an assignment, her students need to find the minimum positive integer $$$y$$$, which satisfies the following two conditions:$$$$$$x\ \texttt{and}\ y > 0$$$$$$ $$$$$$x\ \texttt{xor}\ y > 0$$$$$$Where $$$\texttt{and}$$$ is the bitwise AND operation, and $$$\texttt{xor}$$$ is the bitwise XOR operation.Among the students was Mystia, who was truly baffled by all these new operators. Please help her!

The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of input test cases. For each test case, the only line of input contains one integer $$$x$$$ ($$$1 \leq x \leq 2^{30}$$$).

For each test case, print a single integer — the minimum number of $$$y$$$.

function getMinY(x) {
    const rightBit = x % 2;
    let countOfEqualRightBits = 0;
    let res = 0;
    let shiftedX = x;
    while (shiftedX % 2 === rightBit) {
        shiftedX >>= 1;
        ++countOfEqualRightBits;
    }

    const shiftedBits = 1 << countOfEqualRightBits;
    if (rightBit === 0) {
        res = shiftedBits;

        if (res == x) {
            ++res;
        }
    } else {
        res += 1;

        if (x === 1) {
            res += shiftedBits;
        }
    }

    return res;
}

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

    while (t > 0) {

        const curX = +readline();
        console.log(getMinY(curX));
        --t;
    }
}

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

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

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

    const isPowerOfTwo = n => n && (n & (n - 1)) === 0;

    for (let test = 0; test < N; test++) {
        let x = parseInt(readline(), 10);
        if (x === 1) {
            output('3');
            continue;
        }
        let str = x.toString(2).split('').reverse();
        let first1 = str.indexOf('1');
        let isPow2 = isPowerOfTwo(x);
        let res = 2 ** first1;
        if (isPow2) {
            res += 1;
        }
        output(res);
    }
}

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

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

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

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

const calc = (t)=>{
    /* read */
    // let [a, b, c, d] = ra();
    let x = +readline();
    if (x === 1) return 3;

    let one = -1;
    let ones = 0;
    let zero = -1;

    for (let i = 0; i < 31; i++) {
        if (x & (1 << i)) {
            if (one === -1) one = i;
            ones++;
        }
    }

    if (ones > 1) {
        return (1 << one);
    } else {
        return (1 << one) + 1;
    }
};

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

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        output[i] = solve(n)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n) {
    if (n === 1) return 3
    const s = n.toString(2)
    let one = 0
    let ans = 0
    let p = 1
    for (let i = s.length - 1; i >= 0; i--) {
        if (s[i] === '1') {
            one++
            if (!ans) {
                ans = p
            }
        }
        p *= 2
    }
    return one > 1 ? ans : ans + 1
}

'use strict';

function solve(n) {
  let t = -1,
      one = 0;
  for (let i = 0; i < 31; i++) {
    if (n & 1 << i) {
      if (t === -1) t = i;
      one++;
    }
  }
  let res = 1 << t;
  if (one > 1) return res;
  if (t > 0) return res | 1;else return 3;
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    while (t--) {
      const n = Number(await read());
      res.push(solve(n));
    }
    console.log(res.join('\n'));
  } catch (error) {
    console.log(error);
  }
}

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

function getMinY(x) {
    const rightBit = x % 2;
    let countOfEqualRightBits = 0;
    let res = 0;
    let shiftedX = x;
    while (shiftedX % 2 === rightBit) {
        shiftedX >>= 1;
        ++countOfEqualRightBits;
    }

    const shiftedBits = 1 << countOfEqualRightBits;
    if (rightBit === 0) {
        res = shiftedBits;

        if (res == x) {
            ++res;
        }
    } else {
        res += 1;

        if (shiftedBits - 1 === x) {
            res += shiftedBits;
        }
    }

    return res;
}

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

    while (t > 0) {

        const curX = +readline();
        console.log(getMinY(curX));
        --t;
    }
}

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

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

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

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

const calc = (t)=>{
    /* read */
    // let [a, b, c, d] = ra();
    let x = +readline();
    let one = -1;
    let ones = 0;
    let zero = -1;

    for (let i = 0; i < 31; i++) {
        if (x & (1 << i)) {
            if (one === -1) one = i;
            ones++;
        }
    }
    for (let i = 0; i < 31; i++) {
        if ((x ^ (1 << i)) & (1 << i)) {
            zero = i;
            break;
        }
    }

    if (zero === -1) {
        return x + 2;
    } else if (ones > 1) {
        return (1 << one);
    } else {
        return (1 << one) + 1;
    }
};

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


There are $$$n$$$ segments $$$[l_i, r_i]$$$ for $$$1 \le i \le n$$$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.To optimize testing process you will be given multitest.

The first line contains one integer $$$T$$$ ($$$1 \le T \le 50000$$$) — the number of queries. Each query contains description of the set of segments. Queries are independent. First line of each query contains single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — number of segments. It is guaranteed that $$$\sum{n}$$$ over all queries does not exceed $$$10^5$$$. The next $$$n$$$ lines contains two integers $$$l_i$$$, $$$r_i$$$ per line ($$$1 \le l_i \le r_i \le 2 \cdot 10^5$$$) — the $$$i$$$-th segment.

For each query print $$$n$$$ integers $$$t_1, t_2, \dots, t_n$$$ ($$$t_i \in \{1, 2\}$$$) — for each segment (in the same order as in the input) $$$t_i$$$ equals $$$1$$$ if the $$$i$$$-th segment will belongs to the first group and $$$2$$$ otherwise. If there are multiple answers, you can print any of them. If there is no answer, print $$$-1$$$.

NoteIn the first query the first and the second segments should be in different groups, but exact numbers don't matter.In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $$$-1$$$.In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $$$6$$$ possible is correct.

function calc(pairs) {
  pairs = pairs.map((pair, index) => {
    return {
      pair: pair,
      index: index
    }
  });

  pairs.sort((a, b) => a.pair[0] - b.pair[0]);

  var max = -1;
  var group = 1;

  pairs.map(obj => {
    if (max === -1) {
      obj.group = group; //1
      max = obj.pair[1];
    } else if (group === 2) {
      obj.group = group; //2
    } else if (obj.pair[0] > max) {
      group = 2;
      obj.group = group; //2
    } else {
      obj.group = group; //1

      if (obj.pair[1] > max) {
        max = obj.pair[1];
      }
    }

    return obj;
  });

  if (!pairs.filter(obj => obj.group === 2).length) {
    return -1;
  }

  return pairs.sort((a,b) => a.index - b.index).map(obj => obj.group).join(" ");
}

var T = parseInt(readline());
var n, pairs;

for (var i = 0; i < T; i++) {
  n = parseInt(readline());
  pairs = [];

  for (var j = 0; j < n; j++) {
    pairs.push(readline().split(" ").map(elem => parseInt(elem)));
  }

  print(calc(pairs));
}


This is an hard version of the problem. The only difference between an easy and a hard version is the constraints on $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$.You are given $$$4$$$ positive integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ with $$$a < c$$$ and $$$b < d$$$. Find any pair of numbers $$$x$$$ and $$$y$$$ that satisfies the following conditions: $$$a < x \leq c$$$, $$$b < y \leq d$$$, $$$x \cdot y$$$ is divisible by $$$a \cdot b$$$.Note that required $$$x$$$ and $$$y$$$ may not exist.

The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10$$$), the number of test cases. The descriptions of the test cases follow. The only line of each test case contains four integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$1 \leq a < c \leq 10^9$$$, $$$1 \leq b < d \leq 10^9$$$).

For each test case print a pair of numbers $$$a < x \leq c$$$ and $$$b < y \leq d$$$ such that $$$x \cdot y$$$ is divisible by $$$a \cdot b$$$. If there are multiple answers, print any of them. If there is no such pair of numbers, then print -1 -1.

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const [a, b, c, d] = rns();
  const cnt = new Map();
  const calc = n => {
    var _cnt$get2;
    for (let i = 2; i <= n / i; i++) {
      if (n % i === 0) {
        while (n % i === 0) {
          var _cnt$get;
          cnt.set(i, ((_cnt$get = cnt.get(i)) !== null && _cnt$get !== void 0 ? _cnt$get : 0) + 1);
          n /= i;
        }
      }
    }
    if (n > 1) cnt.set(n, ((_cnt$get2 = cnt.get(n)) !== null && _cnt$get2 !== void 0 ? _cnt$get2 : 0) + 1);
  };
  calc(a);
  calc(b);
  const p = [...cnt.entries()];
  const [A, B, C, D] = [a, b, c, d].map(BigInt);
  const t = A * B;
  const check = (a, b, c) => {
    if (c > a && c <= b) return c;
    let x = a / c;
    if (x * c <= a) x++;
    if (x * c <= b) return x * c;
    return -1n;
  };
  let res = [-1n, -1n];
  const dfs = (i, num) => {
    if (i === p.length) {
      if (num > t) return false;
      let a = check(A, C, num),
          b = check(B, D, t / num);
      if (a !== -1n && b !== -1n) {
        res = [a, b];
        return true;
      }
      return false;
    }
    const [x, y] = p[i];
    for (let j = 0; j <= y; j++) {
      if (dfs(i + 1, num * BigInt(x ** j))) return true;
    }
  };
  dfs(0, 1n);
  return res.join(' ');
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\r?\n/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [a, b, c, d] = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(a, b, c, d).join(' ')
    }
    console.log(output.join('\n'))
// })()
})
// const PRIMES = primes(4e4)
// console.log(PRIMES.slice(-3))
const PRIMES = primes(Math.ceil(Math.sqrt(1e9)))
function primes(n) {
    const filtered = Array(n + 1)
    const ps = []
    let count = 0
    // const phi = Array(n + 1).fill(0)
    // phi[1] = 1
    // const mu = Array(n + 1).fill(0)
    // mu[1] = 1

    for (let i = 2; i <= n; i++) {
        if (!filtered[i]) {
            ps[count++] = i
            // phi[i] = i - 1
            // mu[i] = -1
        }
        for (let j = 0; j < count; j++) {
            const k = i * ps[j]
            if (k > n) break

            filtered[k] = 1
            if (i % ps[j]) {
                // phi[k] = phi[i] * (ps[j] - 1)
                // mu[k] = -mu[i]
            } else {
                // phi[k] = phi[i] * ps[j]
                // mu[k] = 0
                break
            }
        }
    }
    return ps
}
function getFactors(n) {
    if (n < 2) return [[n, 1]]

    const r = []
    let x = n
    PRIMES.some(p => {
        let c = 0
        while (!(x % p)) {
            c++
            x /= p
        }
        if (c) r.push([p, c])
        if (p >= x) return true
    })
    if (x > 1) r.push([x, 1])
    return r
}
function solve(a, b, c, d) {
    const af = getFactors(a)
    const bf = getFactors(b)
// console.log(af, bf)
    const m = {}
    for (let [p, k] of af) {
        m[p] = (m[p] || 0) + k
    }
    for (let [p, k] of bf) {
        m[p] = (m[p] || 0) + k
    }
// console.log(m)
    //
    // return []
    const prod = BigInt(a) * BigInt(b)
    const max = 1000000000n
    const ks = Object.keys(m).map(k => {
        k = BigInt(k)
        // key, count, pow
        return [k, m[k], k ** BigInt(m[k])]
    })
    let count = Array(ks.length).fill(0)
    let now = 1n
    let ok = true
    while (ok) {
// console.log(now, count)
        let k1 = now
        let k2 = prod / k1
        if (k1 > max || k2 > max) {
            update()
            continue
        }
        k1 = Number(k1)
        k2 = Number(k2)
        const r1 = has(k1, a, c)
        const r2 = has(k2, b, d)
// console.log(k1, k2, r1, r2)
        if (r1 < 0 || r2 < 0) {
            update()
        } else {
            return [r1, r2]
        }
    }
    return [-1, -1]

    function update() {
        let i = 0
        while (i < ks.length) {
            if (count[i] + 1 <= ks[i][1]) {
                count[i]++
                now *= ks[i][0]
                return
            } else {
                count[i] = 0
                now /= ks[i][2]
                i++
            }
        }
        ok = false
    }
}
function has(k, a, b) {
    // (a, b]
    let r = Math.ceil(a / k) * k
    if (r === a) r += k
    return r <= b ? r : -1
}
function factors(n) {
    const limit = Math.ceil(Math.sqrt(n))
    const r = []
    for (let i = 1; i < limit; i++) {
        if (!(n % i)) {
            r.push(i, n / i)
        }
    }
    if (!(n % limit)) r.push(limit)
    return r
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [a, b, c, d] = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(a, b, c, d).join(' ')
    }
    console.log(output.join('\n'))
// })()
})
const PRIMES = primes(Math.ceil(Math.sqrt(1e9)))
function primes(n) {
    const filtered = Array(n + 1)
    const ps = []
    let count = 0
    // const phi = Array(n + 1).fill(0)
    // phi[1] = 1
    // const mu = Array(n + 1).fill(0)
    // mu[1] = 1

    for (let i = 2; i <= n; i++) {
        if (!filtered[i]) {
            ps[count++] = i
            // phi[i] = i - 1
            // mu[i] = -1
        }
        for (let j = 0; j < count; j++) {
            const k = i * ps[j]
            if (k > n) break

            filtered[k] = 1
            if (i % ps[j]) {
                // phi[k] = phi[i] * (ps[j] - 1)
                // mu[k] = -mu[i]
            } else {
                // phi[k] = phi[i] * ps[j]
                // mu[k] = 0
                break
            }
        }
    }
    return ps
}
function getFactors(n) {
    if (n < 2) return [[n, 1]]

    const r = []
    let x = n
    PRIMES.some(p => {
        let c = 0
        while (!(x % p)) {
            c++
            x /= p
        }
        if (c) r.push([p, c])
        if (p >= x) return true
    })
    return r
}
function solve(a, b, c, d) {
    const af = getFactors(a)
    const bf = getFactors(b)
// console.log(af, bf)
    const m = {}
    for (let [p, k] of af) {
        m[p] = (m[p] || 0) + k
    }
    for (let [p, k] of bf) {
        m[p] = (m[p] || 0) + k
    }
// console.log(m)
    //
    // return []
    const prod = BigInt(a) * BigInt(b)
    const max = 1000000000n
    const ks = Object.keys(m).map(k => {
        k = BigInt(k)
        // key, count, pow
        return [k, m[k], k ** BigInt(m[k])]
    })
    let count = Array(ks.length).fill(0)
    let now = 1n
    let ok = true
    while (ok) {
// console.log(now, count)
        let k1 = now
        let k2 = prod / k1
        if (k1 > max || k2 > max) {
            update()
            continue
        }
        k1 = Number(k1)
        k2 = Number(k2)
        const r1 = has(k1, a, c)
        const r2 = has(k2, b, d)
// console.log(k1, k2, r1, r2)
        if (r1 < 0 || r2 < 0) {
            update()
        } else {
            return [r1, r2]
        }
    }
    return [-1, -1]

    function update() {
        let i = 0
        while (i < ks.length) {
            if (count[i] + 1 <= ks[i][1]) {
                count[i]++
                now *= ks[i][0]
                return
            } else {
                count[i] = 0
                now /= ks[i][2]
                i++
            }
        }
        ok = false
    }
}
function has(k, a, b) {
    // (a, b]
    let r = Math.ceil(a / k) * k
    if (r === a) r += k
    return r <= b ? r : -1
}
function factors(n) {
    const limit = Math.ceil(Math.sqrt(n))
    const r = []
    for (let i = 1; i < limit; i++) {
        if (!(n % i)) {
            r.push(i, n / i)
        }
    }
    if (!(n % limit)) r.push(limit)
    return r
}


There is a grid with $$$n$$$ rows and $$$m$$$ columns. Some cells are colored black, and the rest of the cells are colored white.In one operation, you can select some black cell and do exactly one of the following:   color all cells in its row black, or  color all cells in its column black. You are given two integers $$$r$$$ and $$$c$$$. Find the minimum number of operations required to make the cell in row $$$r$$$ and column $$$c$$$ black, or determine that it is impossible.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains four integers $$$n$$$, $$$m$$$, $$$r$$$, and $$$c$$$ ($$$1 \leq n, m \leq 50$$$; $$$1 \leq r \leq n$$$; $$$1 \leq c \leq m$$$) — the number of rows and the number of columns in the grid, and the row and column of the cell you need to turn black, respectively. Then $$$n$$$ lines follow, each containing $$$m$$$ characters. Each of these characters is either 'B' or 'W' — a black and a white cell, respectively.

For each test case, if it is impossible to make the cell in row $$$r$$$ and column $$$c$$$ black, output $$$-1$$$.  Otherwise, output a single integer — the minimum number of operations required to make the cell in row $$$r$$$ and column $$$c$$$ black.

9

3 5 1 4

WBWWW

BBBWB

WWBBB

4 3 2 1

BWW

BBW

WBB

WWB

2 3 2 2

WWW

WWW

2 2 1 1

WW

WB

5 9 5 9

WWWWWWWWW

WBWBWBBBW

WBBBWWBWW

WBWBWBBBW

WWWWWWWWW

1 1 1 1

B

1 1 1 1

W

1 2 1 1

WB

2 1 1 1

W

B

NoteThe first test case is pictured below.  We can take the black cell in row $$$1$$$ and column $$$2$$$, and make all cells in its row black. Therefore, the cell in row $$$1$$$ and column $$$4$$$ will become black.  In the second test case, the cell in row $$$2$$$ and column $$$1$$$ is already black.In the third test case, it is impossible to make the cell in row $$$2$$$ and column $$$2$$$ black.The fourth test case is pictured below.  We can take the black cell in row $$$2$$$ and column $$$2$$$ and make its column black.   Then, we can take the black cell in row $$$1$$$ and column $$$2$$$ and make its row black.   Therefore, the cell in row $$$1$$$ and column $$$1$$$ will become black.

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

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

let nl = nextLine();

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

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

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

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

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

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++) {
		let [h, w, r, c] = nl.nums();
		r--;
		c--;
		let p = [];
		for(let j = 0; j < h; j++){
			p.push(nl.line().split('').map(e => 'B' === e));
		}
		if (p[r][c]){
			ans.push(0);
		} else {
			let flag = p[r].some(e => e);
			if (!flag) {
				for(let j = 0; j < h && !flag; j++){
					flag  = p[j][c];
				}
			}
			if (flag) {
				ans.push(1);
			} else {
				if (p.some(e => e.some(e => e))) {
					ans.push(2);
				} else {
					ans.push(-1);
				}
			}
		}
	}
	console.log(ans.join('\n'));
};

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

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}

var T = readline();
for(var q=1;q<=T;q++) {
            var [n,m,r,c] = readline().split(" ").map(w => parseInt(w))
            var g = []
            for(var i=0;i<n;i++) {
                var f = readline();
                g.push(f)
            }
            var inf = 100000000000;
            console.log(solve(g))
            function solve(g) {
                if(g[r-1][c-1] == 'B') return 0;
            	var ans = inf;
            	for(var i=0;i<g.length;i++) {
            	  for(var j=0;j<g[i].length;j++) {
            	  	if(g[i][j] == 'B') {
            	  		ans = 2;
            	  		if(j+1 == c || i+1 == r) {
            	  		  ans = 1;
            	  		  return 1;
            	  		}
            	  	}
            	  }
            	}
            	return ans == inf ? -1 : ans;
            }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

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

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

    for (let test = 0; test < N; test++) {
        let [n, m, r, c] = readline().split(' ').map(Number);

        let grid = new Array(n);
        for (let i = 0; i < n; i++) {
            grid[i] = readline().split('');
        }

        if (grid[r - 1][c - 1] === 'B') {
            output(0);
            continue;
        }

        let rowBlack = false;
        for (let i = 0; i < m; i++) {
            if (grid[r - 1][i] === 'B') {
                rowBlack = true;
                break;
            }
        }
        let colBlack = false;
        for (let i = 0; i < n; i++) {
            if (grid[i][c - 1] === 'B') {
                colBlack = true;
                break;
            }
        }

        if (rowBlack || colBlack) {
            output(1);
            continue;
        }

        let black = false;
        for (let i = 0; i < n; i++) {
            for (let j = 0; j < m; j++) {
                if (grid[i][j] === 'B') {
                    black = true;
                    break;
                }
            }
        }

        if (black) {
            output(2);
        } else {
            output(-1);
        }
    }
}

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

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

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

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

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

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

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

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

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

function solve() {
        let t=readSingleInt();
        while(t--){
            let br = false;
            let [n,m,r,c] = readIntArray();
            // console.log(n,m,r,c)
            let grid = [];
            for(let i=0;i<n;i++){
                grid.push(Array.from(readLine()));
            }
            if(grid[r-1][c-1]=='B'){
                console.log(0);
                continue;
            }
            if(grid[r-1].includes('B')){
                console.log("1");
                continue;
            }
            for(let i=0;i<n;i++){
                if(grid[i][c-1]=='B'){
                    console.log('1');
                    br=true;
                    break;
                }
            }
            if(br){
                continue;
            }
            for(let i=0;i<n;i++){
                if(grid[i].includes('B')){
                    console.log("2");
                    br=true;
                    break;
                }
            }
            if(!br){
                console.log('-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));

const INF = 99;

const g = [];

function main () {
	let T = rn();
	while (T--) {
		let [n, m, r, c] = rna();
		r--;c--;

		let ans = INF;
		for (let i = 0; i < n; i++) {
			g[i] = rl();
			for (let j = 0; j < m; j++) {
				if (g[i][j] == 'B') {
					if (i == r && j == c)
						ans = Math.min(ans, 0);
					else if (i == r || j == c)
						ans = Math.min(ans, 1);
					else
						ans = Math.min(ans, 2);
				}
			}
		}

		console.log(ans == INF ? -1 : ans);
	}
}

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

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;
	let t = inputReader.readNumber();
	//let t = 1;
	function solve() {
	  let [n, m, x, y] = inputReader.readNumberArray();
	  let grid = [];
	  for(let i = 0; i < n; i++) {
	    let row = inputReader.readLine();
	    grid.push(row);
	  }
	  if(grid[x-1][y-1]=='B') {
	    console.log(0);
	    return;
	  }
	  let ans = Infinity;
	  for(let i = 0; i < n; i++) {
	    for(let j = 0; j < m; j++) {
	      if(grid[i][j] == 'B') {
	        if(i == x - 1 || j == y - 1) {
	          ans = Math.min(ans, 1);
	        }
	        else {
	          ans = Math.min(ans, 2);
	        }
	      }
	    }
	  }
	  console.log(ans==Infinity?-1:ans);

	}

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

}

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

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

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

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

	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}

	return {
		readNumber,
		readLine,
		readNumberArray,
	}
}

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

let inputString = "";
let currentLine = 0;

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

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

    main();
});

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

function main() {
    //take input according to the format;
    const t = +(readline());
    for(let i =0; i<t; ++i){

        let [m,n,p,q] = readline().split(" ").map(el => parseInt(el));
        let arr = [];
        let columnStr = '';
        for(let j =0; j<m; ++j){

            let str = readline();
            columnStr += str[q-1];
            arr.push(str)
        }

        if(arr[p-1][q-1]==="B"){
                console.log(0);
            }
            else
            if(arr[p-1].includes("B")){
                console.log(1);
            }
            else
            if(columnStr.includes('B')){
                console.log(1);
            }
            else
            if(arr.join('').includes('B')){
                console.log(2);
            }
            else
            console.log(-1)

    }
}

 var t = parseInt(readline());
  function solve(){
    var inp = readline()
      .split(" ")
      .map((data) => +data);
    var arr = []
    var count = 0
    for(var i = 0; i < inp[0]; i++){
      var s = readline()
      arr[i] = s
      for(var j = 0; j < inp[1]; j++){
          if(s[j] === "B"){
            count++
          }
      }
    }
    if(count === 0) return -1;

    var r1 = 0;
    var c1 = 0;

        for(var j = 0; j < inp[1]; j++){
            if(arr[inp[2]-1][j]==='B')
            {
                r1=1;
                break;
            }
        }
        for(var j = 0; j < inp[0]; j++){
            if(arr[j][inp[3]-1]==='B')
            {
                c1=1;
                break;
            }
        }

       if(arr[inp[2]-1][inp[3]-1]=='B') return 0;
        else if(r1==1 || c1==1) return 1;
        else return 2;
  }

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

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

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

let nl = nextLine();

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

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

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

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

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

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++) {
		let [h, w, r, c] = nl.nums();
		r--;
		c--;
		let p = [];
		for(let j = 0; j < h; j++){
			p.push(nl.line().split('').map(e => 'B' === e));
		}
		console.log(p);
		if (p[r][c]){
			ans.push(0);
		} else {
			let flag = p[r].some(e => e);
			if (!flag) {
				for(let j = 0; j < h && !flag; j++){
					flag  = p[j][c];
				}
			}
			if (flag) {
				ans.push(1);
			} else {
				if (p.some(e => e.some(e => e))) {
					ans.push(2);
				} else {
					ans.push(-1);
				}
			}
		}
	}
	console.log(ans.join('\n'));
};

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

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}

var T = readline();
for(var q=1;q<=T;q++) {
            var [n,m,r,c] = readline().split(" ").map(w => parseInt(w))
            var g = []
            for(var i=0;i<n;i++) {
                var f = readline();
                g.push(f)
            }
            var inf = 100000000000;
            console.log(solve(g))
            function solve(g) {
            	var ans = inf;
            	for(var i=0;i<g.length;i++) {
            	  for(var j=0;j<g[i].length;j++) {
            	  	if(g[i][j] == 'B') {
            	  		ans = 2;
            	  		if(j+1 == c || i+1 == r) {
            	  		  ans = 1;
            	  		  return 1;
            	  		}
            	  	}
            	  }
            	}
            	return ans == inf ? -1 : ans;
            }
}

 var t = parseInt(readline());
  function solve(){
    var inp = readline()
      .split(" ")
      .map((data) => +data);
    var arr = []
    var count = 0
    for(var i = 0; i < inp[0]; i++){
      var s = readline()
      arr[i] = s
      for(var j = 0; j < inp[1]; j++){
          if(s[j] === "B"){
            count++
          }
      }
    }
    if(count === 0) return -1;

    var r1 = 0;
    var c1 = 0;

        for(var j = 0; j < inp[1]; j++){
            if(arr[inp[2]-1][i]=='B')
            {
                r1=1;
                break;
            }
        }
        for(var j = 0; j < inp[0]; j++){
            if(arr[j][inp[3]-1]=='B')
            {
                c1=1;
                break;
            }
        }

       if(arr[inp[2]-1][inp[3]-1]=='B') return 0;
        else if(r1==1 || c1==1) return 1;
        else return 2;
  }

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

 var t = parseInt(readline());
  function solve(){
    var inp = readline()
      .split(" ")
      .map((data) => +data);
    var arr = []
    var count = 0
    for(var i = 0; i < inp[0]; i++){
      var s = readline()
      arr[i] = s
      for(var j = 0; j < inp[1]; j++){
          if(s[j] === "B"){
            count++
          }
      }
    }
    if(count === 0) return -1;

    var r1 = 0;
    var c1 = 0;

        for(var j = 0; j < inp[1]; j++){
            if(arr[inp[2]-1][i]=='B')
            {
                r1=1;
                break;
            }
        }
        for(var j = 0; j < inp[0]; j++){
            if(arr[j][inp[3]-1]=='B')
            {
                r1=1;
                break;
            }
        }

       if(arr[inp[2]-1][inp[3]-1]=='B') return 0;
        else if(r1==1 || c1==1) return 1;
        else return 2;
  }

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