A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.You are given an integer $$$n$$$. Your goal is to construct and print exactly $$$n$$$ different regular bracket sequences of length $$$2n$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 50$$$) — the number of test cases. Each test case consists of one line containing one integer $$$n$$$ ($$$1 \le n \le 50$$$).

For each test case, print $$$n$$$ lines, each containing a regular bracket sequence of length exactly $$$2n$$$. All bracket sequences you output for a testcase should be different (though they may repeat in different test cases). If there are multiple answers, print any of them. It can be shown that it's always possible.

var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var caseLength = parseInt(readline());
    for (var j = 1; j <= caseLength; j++)
    {
        var result = "";
        var remaining = caseLength-j;
        for (var k = 1; k <= j; k++)
        {
            result += "("
        }
        for (var k = 1; k <= j; k++)
        {
            result += ")"
        }
        for (var k = 1; k <= remaining; k++)
        {
            result += "("
        }
        for (var k = 1; k <= remaining; k++)
        {
            result += ")"
        }
        print(result);
    }
}

var t=Number(readline());
while(t--){
    var n=Number(readline());
    for(var i=1;i<=n;i++){
        var str="";
        var m=2*n;
        for(var j=1;j<=m;j++){
            if(j<=i)str+="(";
            else if(j>i && j<=2*i)str+=")";
            else if(j&1)str+="(";
            else str+=")";
        }
        print(str);
    }
}

  function readStringArray() {
    return readline().split(" ");
  }
  function readNumArray() {
    return readStringArray().map(Number);
  }

  function main() {
    var cache = {
      1: ['()']
    };
    function getSeq(n) {
      if (n == 1) {
        return cache[1]
      }
      if (!cache[n]) {
        var res = [];
        var prev = getSeq(n - 1);
        for (var c of prev) {
          res.push(
            '(' + c + ')',
            '()' + c
          )
          if (res.length > n) {
            res = res.slice(0, n);
          }
        }
        cache[n] = res;
      }
      return cache[n]
    }
    var testCasesNum = +readline();
    for (var i = 0; i < testCasesNum; i++) {
      var n = +readline();
      var resArr = getSeq(n);
      for (var j = 0; j < resArr.length; j++) {
        print(resArr[j]);
      }
    }
  }

  main();

function iamsogoodatgaming(n){
    var returnn = '';
    for(gamer = 0; gamer < n; gamer++){
        returnn += '(';
    }
    for(gamer2 = 0; gamer2 < n; gamer2++){
        returnn += ')';
    }
    return returnn;
}
let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
	var t = lines[0];
	for(i = 1; i <= t; i++){
	   var a = lines[i];
	   for(j = 1; j <= a; j++){
	       var ans = iamsogoodatgaming(j) + iamsogoodatgaming(a - j);
	       console.log(ans);
	   }
	}
});

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

let inputString = "";
let currentLine = 0;

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

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

  main();
});

function readline() {
  return inputString[currentLine++];
}
/* Common Template Ends */
function main() {
  let Q = +(readline()); // Read Input

  for (let i = 0; i < Q; i++) {
    const N = parseInt(readline());

    const results = [];
    const stringArray = [];
    go (results, stringArray, N*2, 0, 0);

    results.forEach((result) => {
      console.log(result);
    });
  }
}

const go = (results, stringArray, targetLength, currentLength, currentOpen) => {
  if (currentLength === targetLength) {
    results.push(stringArray.join(""));
    return;
  }
  if (results.length === targetLength / 2) return;

  const remain = targetLength - currentLength;
  if (currentOpen + 1 <= remain) {
    stringArray[currentLength] = '(';
    go(results, stringArray, targetLength, currentLength + 1, currentOpen + 1);
  }
  if (currentOpen > 0) {
    stringArray[currentLength] = ')';
    go(results, stringArray, targetLength, currentLength + 1, currentOpen - 1);
  }
}

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

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

let inputString = '';

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

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

    main(inputString);
});

function log(message) {
    if (process.env.NODE_ENV === "debug") {
        console.log(message);
    }
}

/**
 *
 * @param bracketPairCount integer
 * @return Array<String>
 */
const generateBrackets = (bracketPairCount) => {
    //add () to the end or wrap the whole thing
    // generate a squence exaple input:3, possible sequences = AAA -> AAW -> AWA -> WAA -> AWW -> WAW ->
    // length 3 index 0: AAA, index 1: AAW, index 3
    // ADD as many wraps as there are indexes to the end and the beginning can just be adds

    let index = 0;
    const permutations = [];

    while (index < bracketPairCount) {
        let sequence = "";
        let amountOfAdds = bracketPairCount - index;
        let amountOfWraps = bracketPairCount - amountOfAdds;

        while(amountOfAdds > 0 || amountOfWraps > 0){
            if(amountOfAdds > 0){
                sequence += "()";
                amountOfAdds--;
            }else if(amountOfWraps > 0){
                sequence = "(" + sequence + ")";
                amountOfWraps--;
            }
        }

        permutations.push(sequence);
        index++;
    }

    return permutations;
}

/**
 *
 * @param bracketPairCount Array<String>
 */
const printBrackets = (listOfPossibleBracketPermutations) => {
    listOfPossibleBracketPermutations.forEach(permuatation => console.log(permuatation))
}

function main(fileContents) {//input lines as an array
    // console.log(fileContents);
    fileContents.splice(0, 1);
    fileContents
        .map(generateBrackets)
        .forEach(printBrackets)
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var set = new Set();
		var list = [];
		for(var i = 0; i < N; i++){
			list.push("(");
			list.push(")");
		}
		set.add(myconv(list,0));
		for(var i = 1; i < 2 * N; i++){
			if(list[i] == ")" && list[i + 1] == "("){
				var tmp = list[i];
				list[i] = list[i + 1];
				list[i + 1] = tmp;
				set.add(myconv(list, 0));
				if(set.size == N){
					break;
				}
			}
		}
		set = Array.from(set);
		myout(myconv(set, 9));
	}
}

process.stdin.setEncoding('utf-8')
const readline = require('readline')

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

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    // max number 2^(53) - 1 ~~ 10^(15)
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        main()
        process.exit(0)
    }
})

function solve([num]) {
    const res =[]
    for(let i =0;i<num;++i){
        const temp=[]
        for(let j =0;j<i+1;++j){
            temp.push('()')
        }
        temp.unshift('('.repeat(num-(i+1)))
        temp.push(')'.repeat(num-(i+1)))
        res.push(temp.join(''))
    }
    console.log(res.join('\n'))
}

function main() {
    for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
	var t = lines[0];
	for(i = 1; i <= t; i++){
	    var a = lines[i].split(' ').map(Number);
	    var x = a[0], y = a[1];
	    if(y % x){
	        console.log(0, 0);
	        continue;
	    }
	    y /= x;
	    console.log(1, y);
	}
});

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].split(' ').map(Number);
    var k = lines[1].split(' ').map(Number);
    var a = new Map();
    var length = 0;
    var flag = 0;
    for(var j = 0; j < n[0]; j++){
        if(a.has(k[j]) === false){
            a.set(k[j], j + 1);
            length++;
        }
        if(length == n[1]){
            flag = 1;
            break;
        }
    }
    if(flag === 1){
        console.log('YES');
        var answer = '';
        for(var [key, value] of a){
            answer += value + ' ';
        }
        console.log(answer);
    }else{
        console.log('NO');
    }
});


Boboniu gives you  $$$r$$$ red balls,  $$$g$$$ green balls,  $$$b$$$ blue balls,  $$$w$$$ white balls. He allows you to do the following operation as many times as you want:   Pick a red ball, a green ball, and a blue ball and then change their color to white. You should answer if it's possible to arrange all the balls into a palindrome after several (possibly zero) number of described operations.

The first line contains one integer $$$T$$$ ($$$1\le T\le 100$$$) denoting the number of test cases. For each of the next $$$T$$$ cases, the first line contains four integers $$$r$$$, $$$g$$$, $$$b$$$ and $$$w$$$ ($$$0\le r,g,b,w\le 10^9$$$).

For each test case, print "Yes" if it's possible to arrange all the balls into a palindrome after doing several (possibly zero) number of described operations. Otherwise, print "No".

NoteIn the first test case, you're not able to do any operation and you can never arrange three balls of distinct colors into a palindrome.In the second test case, after doing one operation, changing $$$(8,1,9,3)$$$ to $$$(7,0,8,6)$$$, one of those possible palindromes may be "rrrwwwbbbbrbbbbwwwrrr".A palindrome is a word, phrase, or sequence that reads the same backwards as forwards. For example, "rggbwbggr", "b", "gg" are palindromes while "rgbb", "gbbgr" are not. Notice that an empty word, phrase, or sequence is palindrome.

const isPossiblePalindrome = (input) => {
  var oddCount = 0;

  for (var j = 0; j < 4; j++) {
    if (input[j] % 2) {
      oddCount++;
    }
  }

  return oddCount <= 1;
};

const main = () => {
  const N = Number(readline());

  for (var i = 0; i < N; i++) {
    var input = readline()
      .split(" ")
      .map((i) => Number(i));

    if (isPossiblePalindrome(input)) {
      print("Yes");
      continue;
    }

    var min = Math.min(input[0], input[1], input[2]);

    if (min === 0) {
      print("No");
      continue;
    }

    input[0]--;
    input[1]--;
    input[2]--;
    input[3] += 3;

    if (isPossiblePalindrome(input)) {
      print("Yes");
      continue;
    }

    if (min === 1) {
      print("No");
      continue;
    }

    input[0]--;
    input[1]--;
    input[2]--;
    input[3] += 3;

    if (isPossiblePalindrome(input)) {
      print("Yes");
    } else {
      print("No");
    }
  }
};

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++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const x = readline();
    var cases = parseInt(x);
    //console.log("Cases",cases);
    for(var i=1;i<=cases;i++){
         //console.log("case ",i);
         var line2 = readline();
         var dims = line2.split(" ");
         var r = parseInt(dims[0]);
         var g = parseInt(dims[1]);
         var b = parseInt(dims[2]);
         var w = parseInt(dims[3]);
         console.log(getresult(r,g,b,w));
    }

}

function getresult(r,g,b,w){
    var numOdds = 0;
    var min = Math.min(r,g,b);

    if(r%2 == 1){
        numOdds++;
    }
    if(g%2 == 1){
        numOdds++;
    }
    if(b%2 == 1){
        numOdds++;
    }
    if(numOdds == 3){
        return "Yes";
    }
    if(numOdds == 2){
        return (w%2 === 1 && min >= 1) ? "Yes" : "No";
    }
    if(numOdds == 1){
       return w%2 === 0 ? "Yes":"No";
    }
    if(numOdds === 0){
        return "Yes";
    }

    return "No"
}

var readline=require("readline");
var rl=readline.createInterface({
    input:process.stdin,
    output:process.stdout
});
var arr=[];
rl.on('line',function(inp){
    arr.push(inp);
    if(arr.length>1){
        var t=arr[arr.length-1].split(' ');
        for(var i=0;i<t.length;i++) t[i]=parseInt(t[i]);
        var ans=0;
        for(var i=0;i<t.length;i++) if(t[i]%2==1) ans++;
        if(ans>1){
            var flag=0;
            for(var i=0;i<t.length-1;i++){
                if(t[i]===0){
                    console.log("No");
                    flag=1;break;
                }
            }
            if(flag==0){
                t[t.length-1]+=3;ans=0;
                for(var i=0;i<t.length-1;i++) t[i]--;
                for(var i=0;i<t.length;i++) if(t[i]%2==1) ans++;
                if(ans>1) console.log("No");
                else console.log("Yes");
            }
        }
        else console.log("Yes");
    }
    if(arr.length==(parseInt(arr[0])+1)) process.exit(0);
});

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const cases = +readLine()
    for(let i = 0; i < cases; i++) {
        console.log(possiblePali(readLine().split(' ').map(Number)) ? 'Yes' : 'No')
    }
}

function possiblePali(balls) {
    for(let i = 0; i < 3; i++) {
        if(balls.filter(b => b&1).length < 2) return true
        const [r, g, b, w] = balls
        if(r > 0 && g > 0 && b > 0) balls = [r - 1, g - 1, b - 1, w + 1]
    }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    let [countOdd, countEven, count0] = [0, 0, 0];
    let [a, b, c, d] = readLine()
      .split(" ")
      .map((n, index) => {
        n = parseInt(n);
        if (n % 2 === 0) countEven++;
        else countOdd++;
        if (n === 0 && index !== 3) count0++;
        return n;
      });
    if (count0 > 0 && countEven < 3) {
      console.log("No");
    } else {
      if (count0 === 4 || countOdd <= 1 || countOdd >= 3) {
        console.log("Yes");
      } else console.log("No");
    }
  }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n');
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array(t);
  for(var i = 0; i < t; i++){
    var tmp = nextIntArray();
    var r = tmp[0];
    var g = tmp[1];
    var b = tmp[2];
    var w = tmp[3];
    if(r > 0 && g > 0 && b > 0){

      for(var j = 0; j <= 3; j++){
        var list = [r - j, b - j, g - j, w + (j * 3)];
        var oddCount = 0;
        var isOK = false;
        var isNG = false;
        for(var k = 0; k < 4; k++){
          if(list[k] < 0){
            isNG = true;
            break;
          }
          if(list[k] % 2 == 1){
            oddCount++;
          }
        }
        if(isNG){
          break;
        }
        if(oddCount <= 1){
          output[i] = "Yes";
          isOK = true;
          break;
        }
      }
      if(output[i] == null){
        output[i] = "No";
      }
    }else{
      var odd = 0;
      odd += (r % 2 != 0) ? 1 : 0;
      odd += (g % 2 != 0) ? 1 : 0;
      odd += (b % 2 != 0) ? 1 : 0;
      odd += (w % 2 != 0) ? 1 : 0;
      if(odd > 1){
        output[i] = "No";
      }else{
        output[i] = "Yes";
      }
    }
  }
  myout(myconv(output, 9));
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
  const t = Number(readLine())
  for (let i = 0; i < t; i++) {
    const counts = readLine().split(/\s/).map(Number)
    const w = counts.pop()
    const oddCount = counts.reduce((acc, curr) => acc + (curr % 2), 0)
    if (w % 2 === 0) {
      console.log(oddCount === 2 ? 'No' : 'Yes')
    } else {
      switch (oddCount) {
        case 0:
        case 3:
          console.log('Yes')
          break
        case 1:
          console.log('No')
          break
        case 2:
          console.log(counts.every(count => count !== 0) ? 'Yes' : 'No')
          break
      }
    }
  }
}

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

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

function main() {
	let n = readLine() >> 0;
	while (n--) {
		let odd = 0,
			even = 0,
			zero = 0;
		let c = readLine()
			.split(' ')
			.map((x, i) => {
				x = x >> 0;
				if (i < 3 && x === 0) zero++;
				if ((x & 1) === 1) {
					odd++;
				} else {
					even++;
				}
				return x;
			});

		if (even >= 3) {
			console.log('Yes');
		} else {
			if (zero > 0) console.log('No');
			else {
				if (odd > even) [odd, even] = [even, odd];
				if (even >= 3) {
					console.log('Yes');
				} else {
					console.log('No');
				}
			}
		}
	}
}

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

    A();
});

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

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = parseInt(a[i]);

    return a;
}

function pi(x){
    return parseInt(x);
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [r,g,b,w] = ti(readline().split(' '));
        if(r%2 === 0 && g%2 === 0 && b%2 === 0){
            console.log('Yes');
            continue;
        }else if(r%2 === 0 && g%2 === 0 && b%2 !== 0 || r%2 === 0 && g%2 !== 0 && b%2 === 0 || r%2 !== 0 && g%2 === 0 && b%2 === 0){
            if(w%2 === 0)
                console.log('Yes');
            else
                console.log('No');
            continue;
        }else if(r%2 !== 0 && g%2 !== 0 && b%2 === 0 && b !== 0 || r%2 !== 0 && g%2 === 0 && b%2 !== 0 && g !== 0 || r%2 === 0 && g%2 !== 0 && b%2 !== 0 && r !== 0){
            if(w%2 !== 0)
                console.log('Yes');
            else
                console.log('No');
            continue;
        }else if(r%2 !== 0 && g%2 !== 0 && b%2 !== 0){
            console.log('Yes');
            continue;
        }
        else{
            console.log('No');
        }
    }
}

const main = () => {
  const N = Number(readline());

  for (var i = 0; i < N; i++) {
    var input = readline()
      .split(" ")
      .map((i) => Number(i));

    var min = Math.min(input[0], input[1], input[2]);

    if (input[0] === min) {
      input[0] = 0;
      input[1] -= min;
      input[2] -= min;
    } else if (input[1] === min) {
      input[0] -= min;
      input[1] = 0;
      input[2] -= min;
    } else {
      input[0] -= min;
      input[1] -= min;
      input[2] = 0;
    }

    input[3] += 3 * min;

    var oddCount = 0;
    var positiveCount = 0;

    for (var j = 0; j < 4; j++) {
      if (input[j] % 2) {
        oddCount++;
      }
      if (input[j] > 0) {
        positiveCount++;
      }
    }

    if (oddCount === 1 || positiveCount <= 1) {
      print("Yes");
    } else {
      print("No");
    }
  }
};

main();

const isPossiblePalindrome = (input) => {
  var oddCount = 0;
  var positiveCount = 0;

  for (var j = 0; j < 4; j++) {
    if (input[j] % 2) {
      oddCount++;
    }
    if (input[j] > 0) {
      positiveCount++;
    }
  }

  return oddCount === 1 || positiveCount <= 1;
};

const main = () => {
  const N = Number(readline());

  for (var i = 0; i < N; i++) {
    var input = readline()
      .split(" ")
      .map((i) => Number(i));

    if (isPossiblePalindrome(input)) {
      print("Yes");
      continue;
    }

    var min = Math.min(input[0], input[1], input[2]);

    if (input[0] === min) {
      input[0] = 0;
      input[1] -= min;
      input[2] -= min;
    } else if (input[1] === min) {
      input[0] -= min;
      input[1] = 0;
      input[2] -= min;
    } else {
      input[0] -= min;
      input[1] -= min;
      input[2] = 0;
    }

    input[3] += 3 * min;

    if (isPossiblePalindrome(input)) {
      print("Yes");
    } else {
      print("No");
    }
  }
};

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++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const x = readline();
    var cases = parseInt(x);
    //console.log("Cases",cases);
    for(var i=1;i<=cases;i++){
         //console.log("case ",i);
         var line2 = readline();
         var dims = line2.split(" ");
         var r = parseInt(dims[0]);
         var g = parseInt(dims[1]);
         var b = parseInt(dims[2]);
         var w = parseInt(dims[3]);
         console.log(getresult(r,g,b,w));
    }

}

function getresult(r,g,b,w){
    var numOdds = 0;
    var min = Math.min(r,g,b);
    if(r%2 == 1){
        numOdds++;
    }
    if(g%2 == 1){
        numOdds++;
    }
    if(b%2 == 1){
        numOdds++;
    }
    if(numOdds == 3){
        return true;
    }
    if(numOdds == 2){
        return (w%2 === 1 && min >= 1) ? "Yes" : "No";
    }
    if(numOdds == 1){
       return w%2 === 0 ? "Yes":"No";
    }
    if(numOdds === 0){
        return "Yes";
    }

    return "No"
}

function minChanges(arr){
   var pathCovered = [];

   var dp = [];

   for(var i =0; i<arr.length;i++){
       var rw = [];
       var cl = arr[0].length;
       for(var j=0;j<cl;j++){
           rw.push(0);
       }
       dp.push(rw);
   }

   dp[0][0] = 0;

   var cleng = arr[0].length;

   var rowLast = arr[arr.length-1][cleng-1];

   for(var row = 0;row<arr.length;row++){
       var colLength = arr[0].length;
       for(var col = 0; col < colLength ; col++){
           var minValFromLeft = 10000;
           var minValFromTop = 10000;
           if(row === 0 && col === 0){
              minValFromLeft = 0;
              minValFromTop = 0;
           }
           if(col>0){
               var leftElem = arr[row][col-1];
               if(leftElem == "R"){
                  minValFromLeft = dp[row][col-1];
               }
               else{
                minValFromLeft = 1+dp[row][col-1];
               }
           }
           if(row>0){
                var topElem = arr[row-1][col];
                if(topElem == "D"){
                    minValFromTop = dp[row-1][col];
                }
                else{
                    minValFromTop = 1+dp[row-1][col];
                }
           }
          dp[row][col] = Math.min(minValFromLeft,minValFromTop);
       }
   }

   return dp[arr.length-1][cleng-1];
}

var readline=require("readline");
var rl=readline.createInterface({
    input:process.stdin,
    output:process.stdout
});
var arr=[];
rl.on('line',function(inp){
    arr.push(inp);
    if(arr.length>1){
        var t=arr[arr.length-1].split(' ');
        for(var i=0;i<t.length;i++) t[i]=parseInt(t[i]);
        var minn=1e12,ans=0;
        for(var i=0;i<t.length-1;i++) minn=Math.min(minn,t[i]);
        for(var i=0;i<t.length;i++){
            if(i==t.length-1) t[i]+=minn;
            else t[i]-=minn;
            if(t[i]%2!=0) ans++;
        }
        if(ans>1) console.log("No");
        else console.log("Yes");
    }
    if(arr.length==(parseInt(arr[0])+1)) process.exit(0);
});

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const cases = +readLine()
    for(let i = 0; i < cases; i++) {
        console.log(possiblePali(readLine().split(' ').map(Number)) ? 'Yes' : 'No')
    }
}

function possiblePali(balls) {
    console.log(balls)

    for(let i = 0; i < 3; i++) {
        if(balls.filter(b => b&1).length < 2) return true
        const [r, g, b, w] = balls
        console.log({r, g, b, w})
        if(r > 0 && g > 0 && b > 0) balls = [r - 1, g - 1, b - 1, w + 1]
    }
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const cases = +readLine()
    for(let i = 0; i < cases; i++) {
        console.log(possiblePali(readLine().split(' ').map(Number)) ? 'Yes' : 'No')
    }
}

function possiblePali(balls) {
    console.log(balls)

    for(let i = 0; i < 3; i++) {
        if(balls.filter(b => b&1).length < 2) return true
        const [r, g, b, w] = balls
        if(r > 0 && g > 0 && b > 0) balls = [r - 1, g - 1, b - 1, w + 1]
    }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    let [a, b, c, d] = readLine()
      .split(" ")
      .map((n) => parseInt(n));

    if (a === 0 && b === 0 && c === 0 && d === 0) {
      console.log("Yes");
    } else {
      if (a === 0 || b === 0 || c === 0 || d === 0) {
        console.log("No");
      } else {
        const min = Math.min(a, b, c);
        a = a - min;
        b = b - min;
        c = c - min;
        d = d + 3 * min;
        let [countEven, countOdd] = [0, 0];
        if (a % 2 === 0) countEven++;
        else countOdd++;
        if (b % 2 === 0) countEven++;
        else countOdd++;
        if (c % 2 === 0) countEven++;
        else countOdd++;
        if (d % 2 === 0) countEven++;
        else countOdd++;

        if ((countOdd === 1 && countEven === 3) || countOdd === 4 || countEven === 4) console.log("Yes");
        else console.log("No");
      }
    }
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    let [countOdd, countEven, count0] = [0, 0, 0];
    let [a, b, c, d] = readLine()
      .split(" ")
      .map((n) => {
        n = parseInt(n);
        if (n % 2 === 0) countEven++;
        else countOdd++;
        if (n === 0) count0++;
        return n;
      });
    if ((a === 0 || b === 0 || c === 0) && count0 < 3) {
      console.log("No");
    } else {
      if (count0 === 4 || countOdd <= 1 || countOdd >= 3) {
        console.log("Yes");
      } else console.log("No");
    }
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    let [a, b, c, d] = readLine()
      .split(" ")
      .map((n) => parseInt(n));

    if (a === 0 && b === 0 && c === 0 && d === 0) {
      console.log("Yes");
    } else {
      if (a === 0 || b === 0 || c === 0 || d === 0) {
        console.log("No");
      } else {
        const min = Math.min(a, b, c);
        a = a - min;
        b = b - min;
        c = c - min;
        d = d + 3 * min;
        let [countEven, countOdd] = [0, 0];
        if (a % 2 === 0) countEven++;
        else countOdd++;
        if (b % 2 === 0) countEven++;
        else countOdd++;
        if (c % 2 === 0) countEven++;
        else countOdd++;
        if (d % 2 === 0) countEven++;
        else countOdd++;

        if (countOdd === 1 || countOdd === 4 || countEven === 4) console.log("Yes");
        else console.log("No");
      }
    }
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    const [a, b, c, d] = readLine()
      .split(" ")
      .map((n) => parseInt(n));

    if (a === 0 && b === 0 && c === 0 && d === 0) {
      console.log("YES");
    } else {
      if (a === 0 || b === 0 || c === 0 || d === 0) {
        console.log("NO");
      } else {
        console.log("YES");
      }
    }
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    let [countOdd, countEven, count0] = [0, 0, 0];
    let [a, b, c, d] = readLine()
      .split(" ")
      .map((n) => {
        n = parseInt(n);
        if (n % 2 === 0) countEven++;
        else countOdd++;
        if (n === 0) count0++;
        return n;
      });
    if (count0 > 0 && count0 < 3) {
      console.log("No");
    } else {
      if (count0 === 4 || countOdd <= 1 || countOdd >= 3) {
        console.log("Yes");
      } else console.log("No");
    }
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    let [a, b, c, d] = readLine()
      .split(" ")
      .map((n) => parseInt(n));

    if (a === 0 && b === 0 && c === 0) {
      console.log("Yes");
    } else {
      if (a === 0 || b === 0 || c === 0) {
        console.log("No");
      } else {
        const min = Math.min(a, b, c);
        a = a - min;
        b = b - min;
        c = c - min;
        d = d + 3 * min;
        let [countEven, countOdd] = [0, 0];
        if (a % 2 === 0) countEven++;
        else countOdd++;
        if (b % 2 === 0) countEven++;
        else countOdd++;
        if (c % 2 === 0) countEven++;
        else countOdd++;
        if (d % 2 === 0) countEven++;
        else countOdd++;

        if ((a === min && b === min && c === min) || countOdd === 1 || countEven === 4) console.log("Yes");
        else console.log("No");
      }
    }
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    let [countOdd, countEven, count0] = [0, 0, 0];
    let [a, b, c, d] = readLine()
      .split(" ")
      .map((n) => {
        n = parseInt(n);
        if (n % 2 === 0) countEven++;
        else countOdd++;
        if (n === 0) count0++;
        return n;
      });
    if ((a === 0 || b === 0 || c === 0) && count0 !== 4) {
      console.log("No");
    } else {
      if (count0 === 4 || countOdd <= 1 || countOdd >= 3) {
        console.log("Yes");
      } else console.log("No");
    }
  }
}

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

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

function main() {
	let n = readLine() >> 0;
	while (n--) {
		let odd = 0,
			even = 0,
			zero = 0;
		let c = readLine()
			.split(' ')
			.map(x => {
				x = x >> 0;
				if (x === 0) zero++;
				if ((x & 1) === 1) {
					odd++;
				} else {
					even++;
				}
				return x;
			});

		let s = c.reduce((a, c) => a + c);

		if (even >= 3) {
			console.log('Yes');
		} else {
			if (zero > 0) console.log('No');
			else {
				if (odd > even) [odd, even] = [even, odd];
				if (even >= 3) {
					console.log('Yes');
				} else {
					console.log('No');
				}
			}
		}
	}
}

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

    A();
});

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

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = parseInt(a[i]);

    return a;
}

function pi(x){
    return parseInt(x);
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [r,g,b,w] = ti(readline().split(' '));
        if(r%2 === 0 && g%2 === 0 && b%2 === 0){
            console.log('Yes');
            continue;
        }else if(r%2 === 0 && g%2 === 0 && b%2 !== 0 || r%2 === 0 && g%2 !== 0 && b%2 === 0 || r%2 !== 0 && g%2 === 0 && b%2 === 0){
            console.log('Yes');
            continue;
        }else if(r%2 !== 0 && g%2 !== 0 && b%2 === 0 && b !== 0 || r%2 !== 0 && g%2 === 0 && b%2 !== 0 && g !== 0 || r%2 === 0 && g%2 !== 0 && b%2 !== 0 && r !== 0){
            console.log('yes');
            continue;
        }else{
            console.log('No');
            continue;
        }
    }
}


Madoka as a child was an extremely capricious girl, and one of her favorite pranks was drawing on her wall. According to Madoka's memories, the wall was a table of $$$n$$$ rows and $$$m$$$ columns, consisting only of zeroes and ones. The coordinate of the cell in the $$$i$$$-th row and the $$$j$$$-th column ($$$1 \le i \le n$$$, $$$1 \le j \le m$$$) is $$$(i, j)$$$.One day she saw a picture "Mahou Shoujo Madoka Magica" and decided to draw it on her wall. Initially, the Madoka's table is a table of size $$$n \times m$$$ filled with zeroes. Then she applies the following operation any number of times:Madoka selects any rectangular subtable of the table and paints it in a chess coloring (the upper left corner of the subtable always has the color $$$0$$$). Note that some cells may be colored several times. In this case, the final color of the cell is equal to the color obtained during the last repainting.  White color means $$$0$$$, black means $$$1$$$. So, for example, the table in the first picture is painted in a chess coloring, and the others are not. For better understanding of the statement, we recommend you to read the explanation of the first test.Help Madoka and find some sequence of no more than $$$n \cdot m$$$ operations that allows you to obtain the picture she wants, or determine that this is impossible.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 100$$$) — the size of the table. Each of the following $$$n$$$ lines contains a string of length $$$m$$$ consisting only of $$$1$$$ and $$$0$$$ — description of the picture that Madoka wants to obtain.

If it is impossible to obtain the given picture, print $$$-1$$$. Otherwise, print in the first line a single integer $$$q$$$ ($$$0 \leq q \leq n \cdot m$$$) — the number of operations you need to obtain the picture. Note that you do not need to minimize the number of operations. Then for each operation (in the order of execution) print a single line containing four numbers — the coordinates of the upper-left corner and the lower-right corner of the rectangle.

NoteThe description of the first test case is below.  In the third test case, it is impossible to paint the desired picture.In the fourth test case, the initial table is already the desired picture.

function solve() {
    const [n, m] = readArray(Number);
    const matr = [];
    function canDraw(x, y) {
        if (x < 0 || x >= n) {
            return false;
        }
        if (y < 0 || y >= m) {
            return false;
        }
        return matr[x][y] === '0';
    }
    for (let i = 0; i < n; i++) {
        matr.push(read());
    }
    if (matr[0][0] === '1') {
        write(-1);
        return;
    }
    const ans = [];
    for (let i = n - 1; i > 0; i--) {
        for (let j = m - 1; j >= 0; j--) {
            if (matr[i][j] === '1') {
                ans.push([i, j + 1, i + 1, j + 1]);
            }
        }
    }
    for (let j = m - 1; j > 0; j--) {
        if (matr[0][j] === '1') {
            ans.push([1, j, 1, j + 1]);
        }
    }
    write(ans.length);
    for (const draw of ans) {
        write(draw.join(' '));
    }
}

function start() {
    var T = 1;
    T = Number(read());
    for (var t = 0; t < T; t++) {
        solve();
    }
    writeAns();
}

try {
    initInput(start);
} catch (e) {
    write(e);
}

var MEMORY;
var MEMORY_INDEX;
function readArray(f) {
    return read().split(' ').map(f);
}
var ANS;
function write(value) {
    ANS += value + '\n';
}
function writeAns() {
    console.log(ANS);
}
function read() {
    return MEMORY[MEMORY_INDEX++];
}
function initInput(callback) {
    var fs = require('fs');
    var isLocalStart = process.argv[2] === 'lorelvate';
    if (isLocalStart) {
        var path = require('path');
        fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {
            if (err) {
                write(err);
                return;
            }
            MEMORY = data.split('\r\n');
            ANS = '';
            MEMORY_INDEX = 0;
            callback();
        });
        return;
    }
    MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
    ANS = '';
    MEMORY_INDEX = 0;
    callback();
}

function solve() {
    const [n, m] = readArray(Number);
    const matr = [];
    function canDraw(x, y) {
        if (x < 0 || x >= n) {
            return false;
        }
        if (y < 0 || y >= m) {
            return false;
        }
        return matr[x][y] === '0';
    }
    for (let i = 0; i < n; i++) {
        matr.push(read());
    }
    if (matr[0][0] === '1') {
        write(-1);
        return;
    }
    const ans = [];
    for (let i = n - 1; i > 0; i--) {
        for (let j = m - 1; j >= 0; j--) {
            if (matr[i][j] === '1') {
                ans.push([i, j + 1, i + 1, j + 1]);
            }
        }
    }
    for (let j = m - 1; j > 0; j--) {
        if (matr[0][j] === '1') {
            ans.push([1, j, 1, j + 1]);
        }
    }
    write(ans.length);
    for (const draw of ans) {
        write(draw.join(' '));
    }
}

function start() {
    var T = 1;
    T = Number(read());
    for (var t = 0; t < T; t++) {
        solve();
    }
}

try {
    initInput(start);
} catch (e) {
    write(e);
}

var MEMORY;
var MEMORY_INDEX;
function readArray(f) {
    return read().split(' ').map(f);
}
function write(value) {
    console.log(value);
}
function read() {
    return MEMORY[MEMORY_INDEX++];
}
function initInput(callback) {
    var fs = require('fs');
    var isLocalStart = process.argv[2] === 'lorelvate';
    if (isLocalStart) {
        var path = require('path');
        fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {
            if (err) {
                write(err);
                return;
            }
            MEMORY = data.split('\r\n');
            MEMORY_INDEX = 0;
            callback();
        });
        return;
    }
    MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
    MEMORY_INDEX = 0;
    callback();
}

function solve() {
   const [n, m] = readArray(Number);
   const matr = [];
   function canDraw(x, y) {
      if (x < 0 || x >= n) {
         return false;
      }
      if (y < 0 || y >= m) {
         return false;
      }
      return matr[x][y] === '0';
   }
   for (let i = 0; i < n; i++) {
      matr.push(read());
   }
   if (matr[0][0] === '1') {
      write(-1);
      return;
   }
   const ans = [];
   for (let i = n - 1; i > 0; i--) {
      for (let j = m - 1; j >= 0; j--) {
         if (matr[i][j] === '1') {
            ans.push([i, j + 1, i + 1, j + 1]);
         }
      }
   }
   for (let j = m - 1; j > 0; j--) {
      if (matr[0][j] === '1') {
         ans.push([1, j, 1, j + 1]);
      }
   }
   write(ans.length);
   for (const draw of ans) {
      write(draw.join(' '));
   }
}

function countBeatyMul(x, d, start) {
   if (x % d !== 0) {
      return 0;
   }
   if (isBeaty(x, d)) {
      return 1;
   }
   let ans = 0;
   for (let i = start; i <= Math.floor(Math.sqrt(x)); i++) {
      if (x % i !== 0) {
         continue;
      }
      const xDivI = Math.floor(x / i);
      if (xDivI < start) {
         continue;
      }
      if (isBeaty(i, d)) {
         ans += countBeatyMul(xDivI, d, i)
      }
   }
   return ans;
}

function isBeaty(x, d) {
   return x % d === 0 && x % (d * d) !== 0;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

   var path = require('path');

   var inTextName;
   var outTextName;

   var needWriteFile = false;

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

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

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

"use strict";

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

let inputStr = "";
let currentLne = 0;

process.stdin.on('data' , inputStdin =>{

	 inputStr += inputStdin;
})

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

main();
})

function readline(){
   return inputStr[currentLne++];
}

function main(){
   let t = parseInt(readline());
   let c =0;

   while(c<t){
        let mat = readline().split(" ").map(a => parseInt(a));
        let tr = mat[0];
        let count =0;
        let arrd=[]
           while(count<tr){
              let rows = readline().split("").map(b=> parseInt(b));
              arrd.push(rows);
              count++;
           }
         let newarr = new Array();
         let co =0;
         for (var i = arrd.length-1; i>=0 ; i--) {
               for (var j = arrd[0].length-1; j >=0  ; j--) {
                if(arrd[i][j]==1){
                     co++;
                }
            }
         }

         if(arrd[0][0] ==1){
           console.log(-1);
         }else{
             console.log(co);
             for (var i = arrd.length-1; i>=0 ; i--) {
             for (var j = arrd[0].length-1; j >=0  ; j--) {
                if(arrd[i][j]==1){
                     co++;
                          if(j - 1 >= 0) {
                              console.log(i+1,j,i+1,j+1);

                          }
                          else {
                             console.log(i,j+1,i+1,j+1);

                          }
                     }
                 }
             }
         }
      c++
   }

}

//type input.txt | node code.js

'use strict'; /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  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++];
}

module.exports = E;

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

const EPS = 1e-6;

E.s2a = (arr)=>arr.map(a=>a.split('').map(c=>c=='0' ? 0 : 1))

const calc = (arr)=>{
  arr = E.s2a(arr);
  if (arr[0][0]==1)
    return false;
  let q = [];
  let n = arr.length;
  let m = arr[0].length;
  for (let i=n-1; i>=0; i--){
    for (let j=m-1; j>=0; j--){
      if (arr[i][j]){
        if (i)
          q.push({fromI: i-1, toI: i, fromJ: j, toJ: j});
        else
          q.push({fromI: i, toI: i, fromJ: j-1, toJ: j});
      }
      else
          q.push({fromI: i, toI: i, fromJ: j, toJ: j});
    }
  }
  return q
};

function main() {
    let T = +readline();
    while (T--){
      let [n, m] = ra();
      let arr = [];
      for (let i=0;i<n;i++)
        arr.push(readline());
      let q = calc(arr);
      if (!q)
        print(-1)
      else {
        print(q.length);
        for (let p of q){
          print(p.fromI+1, p.fromJ+1, p.toI+1, p.toJ+1);
        }
      }
    }
}

E.calc = calc;

"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 stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let [n, m] = iInpArr();
    let arr = [];
    for (let i = 0; i < n; i++) arr.push(iInpArr1());
    const helper = (arr) => {
      let ans = [];
      for (let i = n - 1; i >= 0; i--) {
        for (let j = m - 1; j >= 0; j--) {
          if (arr[i][j] === 1) {
            if (i === 0) {
              if (j === 0) return false;
              ans.push([i + 1, j, i + 1, j + 1]);
            } else {
              if (j === 0) ans.push([i, j + 1, i + 1, j + 1]);
              else ans.push([i + 1, j, i + 1, j + 1]);
            }
          }
        }
      }
      return ans;
    };
    let ans = helper(arr);
    if (ans === false) console.log(-1);
    else if (ans.length === 0) console.log(0);
    else {
      console.log(ans.length);
      for (let i = 0; i < ans.length; i++) console.log(ans[i].join(" "));
    }
  }
};
solve();

'use strict';

var readline = require('readline');

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

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function solve(n, m, s) {
  if (s[0][0] === '1') return -1;
  let res = [];
  for (let i = n - 1; i >= 0; i--) {
    for (let j = m - 1; j >= 0; j--) {
      if (s[i][j] === '1') res.push(j === 0 ? [i, j + 1, i + 1, j + 1] : [i + 1, j, i + 1, j + 1]);
    }
  }
  return res.length + '\n' + res.map(arr => arr.join(' ')).join('\n');
}

async function main(read) {
  let t = Number(await read());
  let res = [];
  while (t--) {
    const [n, m] = (await read()).split(' ').map(Number);
    const a = [];
    let tmp = n;
    while (tmp--) {
      a.push(await read());
    }
    res.push(solve(n, m, a));
  }
  console.log(res.join('\n'));
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();

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() {
  let testCases = Number(readline());
  for (let t = 0; t < testCases; t++) {
    let [m, n] = readline().split(" ").map(Number);
    let board = [];

    let row = readline().split("").map(Number);
    board.push(row);

    if (board[0][0] === 1) {
      console.log(-1);
      for (let i = 1; i < m; i++) {
        readline();
      }
    } else {
      for (let i = 1; i < m; i++) {
        let row = readline().split("").map(Number);
        board.push(row);
      }
      console.log(m * n);
      for (let i = m - 1; i >= 0; i--) {
        for (let j = n - 1; j >= 0; j--) {
          if (board[i][j] === 1) {
            if (j === 0) {
              console.log(i - 1 + 1, j + 1, i + 1, j + 1);
            } else {
              console.log(i + 1, j - 1 + 1, i + 1, j + 1);
            }
          } else {
            console.log(i + 1, j + 1, i + 1, j + 1);
          }
        }
      }
    }
  }
}

var tests = parseInt(readline());
    var n,m;
    var mat;
    for (var ti=0; ti < tests; ti++) {
        var nm = readline().split(' ').map(x=>parseInt(x));
        n = nm[0];
        m = nm[1];
        mat = [];
        for (var i = 0; i < n; i++) {
            var row = readline().split('').map(x=>parseInt(x));
            mat.push(row);
        }
        if (mat[0][0]) {
            print('-1');
            continue;
        }

        var ans = [];
        for (var r = n-1; r >= 0; r--) {
            for (var c = m-1; c >= 1; c--) {
                if (mat[r][c]) {
                    ans.push([r+1, c, r+1, c+1]);
                }
            }
        }

        for (var r = n-1; r > 0; r--) {
            if (mat[r][0]) {
                ans.push([r, 1, r+1, 1]);
            }
        }

        print(ans.length);
        for (var i = 0; i < ans.length; i++) {
            print(ans[i].join(' '));
        }
    }

"use strict";

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

let inputStr = "";
let currentLne = 0;

process.stdin.on('data' , inputStdin =>{

	 inputStr += inputStdin;
})

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

main();
})

function readline(){
   return inputStr[currentLne++];
}

function main(){
   let t = parseInt(readline());
   let c =0;

   while(c<t){
        let mat = readline().split(" ").map(a => parseInt(a));
        let tr = mat[0];
        let count =0;
        let arrd=[]
           while(count<tr){
              let rows = readline().split("").map(b=> parseInt(b));
              arrd.push(rows);
              count++;
           }

let newarr = new Array();
// let x =[]
// for (var o = 0; o < newarr.length; o++) {
//     newarr[o] = new Array(5).fill(0);
// }

// let m =0;
// let n =0;
// let co =0;
let co =0;

for (var i = arrd.length-1; i>=0 ; i--) {
      for (var j = arrd[0].length-1; j >=0  ; j--) {
       if(arrd[i][j]==1){
            co++;
       }
   }
}
console.log(co);
if(arrd[0][0] ==1){
  console.log(-1);
}else{
    for (var i = arrd.length-1; i>=0 ; i--) {
    for (var j = arrd[0].length-1; j >=0  ; j--) {
       if(arrd[i][j]==1){
            co++;
                 if(j - 1 >= 0) {
                     console.log(i+1,j,i+1,j+1);
                     // cout << i + 1 << " " << j << " ";
                     // cout << i + 1 << " " << j + 1 << endl;
                 }
                 else {
                    console.log(i,j+1,i+1,j+1)
                      // cout << i << " " << j + 1 << " " ;
                      // cout << i + 1 << " " << j + 1 << endl;
                 }
      }
     }
    }
}
// console.log(newarr);

      c++
   }

}

//type input.txt | node code.js

"use strict";

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

let inputStr = "";
let currentLne = 0;

process.stdin.on('data' , inputStdin =>{

	 inputStr += inputStdin;
})

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

main();
})

function readline(){
   return inputStr[currentLne++];
}

function main(){
   let t = parseInt(readline());
   let c =0;

   while(c<t){
        let mat = readline().split(" ").map(a => parseInt(a));
        let tr = mat[0];
        let count =0;
        let arrd=[]
           while(count<tr){
              let rows = readline().split("").map(b=> parseInt(b));
              arrd.push(rows);
              count++;
           }

let newarr = new Array();
// let x =[]
// for (var o = 0; o < newarr.length; o++) {
//     newarr[o] = new Array(5).fill(0);
// }

// let m =0;
// let n =0;
// let co =0;
let co =0;

for (var i = arrd.length-1; i>=0 ; i--) {
      for (var j = arrd[0].length-1; j >=0  ; j--) {
       if(arrd[i][j]==1){
            co++;
       }
   }
}
console.log(co);
if(arrd[0][0] ==1){
  console.log(-1);
}else{
    for (var i = arrd.length-1; i>=0 ; i--) {
    for (var j = arrd[0].length-1; j >=0  ; j--) {
       if(arrd[i][j]==1){
            co++;
                 if(j - 1 >= 0) {
                     console.log(i+1," ",j," ",i+1," ",j+1);
                     // cout << i + 1 << " " << j << " ";
                     // cout << i + 1 << " " << j + 1 << endl;
                 }
                 else {
                    console.log(i," ",j+1," ",i+1," ",j+1)
                      // cout << i << " " << j + 1 << " " ;
                      // cout << i + 1 << " " << j + 1 << endl;
                 }
      }
     }
    }
}
// console.log(newarr);

      c++
   }

}

//type input.txt | node code.js

'use strict'; /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  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++];
}

module.exports = E;

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

const EPS = 1e-6;

E.s2a = (arr)=>arr.map(a=>a.split('').map(c=>c=='0' ? 0 : 1))

const calc = (arr)=>{
  arr = E.s2a(arr);
  if (arr[0][0]==1)
    return false;
  let q = [];
  let n = arr.length;
  let m = arr[0].length;
  for (let i=n-1; i>=0; i--){
    for (let j=m-1; j>=0; j--){
      if (arr[i][j]){
        if (i)
          q.push({fromI: i-1, toI: i, fromJ: j, toJ: j});
        else
          q.push({fromI: i, toI: i, fromJ: j-1, toJ: j});
      }
      else
          q.push({fromI: i, toI: i, fromJ: j, toJ: j});
    }
  }
  return q
};

function main() {
    let T = +readline();
    while (T--){
      let [n, m] = ra();
      let arr = [];
      for (let i=0;i<n;i++)
        arr.push(readline());
      let q = calc(arr);
      if (!q)
        print(-1)
      else {
        print(q.length);
        for (let p of q){
          print(p.fromI, p.fromJ, p.toI, p.toJ);
        }
      }
    }
}

E.calc = calc;


This is an easy 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^5$$$, $$$1 \leq b < d \leq 10^5$$$).

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

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

function solve(a, b, c, d) {
    // const af = factors(a)
    // const bf = factors(b)
// console.log(af, bf)
    const prod = a * b
    const pf = factors(prod)
// console.log(pf)
    for (let i = 0; i < pf.length; i++) {
        const k1 = pf[i]
        const k2 = prod / pf[i]
//     for (let i = 0; i < af.length; i++) {
//         for (let j = 0; j < bf.length; j++) {
//             const k1 = af[i] * bf[j]
//             const k2 = prod / k1
            const r1 = has(k1, a, c)
            const r2 = has(k2, b, d)
// console.log(k1, k2, r1, r2)
            if (r1 < 0 || r2 < 0) continue
            return [r1, r2]
//         }
    }
    return [-1, -1]
}
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
}

let buf='';

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

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    let z=0;
    let gcd=(a,b)=>{
        if(!b) return a;
        return gcd(b,a%b);
    }
    for(let _=1;_<=t;_++)
    {
        let [a,b,c,d]=line[_].split(' ').map(x=>{return parseInt(x)});
        let x=a*b;
        let ansx=-1,ansy=-1;
        for(let i=a+1;i<=c;i++)
        {
            let z=gcd(i,x);
            let num=x/z;
            let k=Math.floor((b+1)/num);
            if(k*num<b+1) k++;
            if(k*num<=d)
            {
                ansx=i,ansy=k*num;
            }
        }
        console.log(ansx,ansy);
    }
})

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

function solve(a, b, c, d) {
    const af = factors(a)
    const bf = factors(b)
    const prod = a * b
    for (let i = 0; i < af.length; i++) {
        for (let j = 0; j < bf.length; j++) {
            const k1 = af[i] * bf[j]
            const k2 = prod / k1
            const r1 = has(k1, a, c)
            const r2 = has(k2, b, d)
            if (r1 < 0 || r2 < 0) continue
            return [r1, r2]
        }
    }
    return [-1, -1]
}
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.floor(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
}


Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sending it to the magazine 2Char, he needs to adapt the text to the format of the journal. To do so, he removes some words from the chosen article, in such a way that the remaining text can be written using no more than two distinct letters.Since the payment depends from the number of non-space characters in the article, Andrew wants to keep the words with the maximum total length.

The first line of the input contains number n (1 ≤ n ≤ 100) — the number of words in the article chosen by Andrew. Following are n lines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct, in this case you are allowed to use a word in the article as many times as it appears in the input.

Print a single integer — the maximum possible total length of words in Andrew's article.

NoteIn the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}.In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}.

var n = parseInt(readline()),
    lettersUsed = [],
    pairs = [],
    words = [],
    res = 0,
    currRes = 0;

for (var i = 0; i < n; i++) {
    var word = readline();
    var isGood = true,
        let1 = word.charAt(0),
        let2 = '';
    for (var j = 1; j < word.length; j++) {
        if (word.charAt(j) != let1) {
            if (let2 == '') let2 = word.charAt(j);
            else if (word.charAt(j) != let2) {
                isGood = false;
                break;
            }
        }
    }
    if (isGood) {
        words.push(word);
        if ( lettersUsed.indexOf(let1) == -1 ) lettersUsed.push(let1);
        if ( lettersUsed.indexOf(let2) == -1 && let2 != '' ) lettersUsed.push(let2);
    }
}

if (lettersUsed.length > 1) {
	for (var i = 0; i < lettersUsed.length - 1; i++) {
	    for (var j = i+1; j < lettersUsed.length; j++) {
	        pairs.push( [lettersUsed[i], lettersUsed[j]] );
	    }
	}
} else {
	pairs.push( [lettersUsed[0], lettersUsed[0]] );
}

for (var i = 0; i < pairs.length; i++) {
    currRes = 0;
    for (var j = 0; j < words.length; j++) {
        var good = true;
        for (var k = 0; k < words[j].length; k++) {
            if (words[j].charAt(k) != pairs[i][0] && words[j].charAt(k) != pairs[i][1]) {
                good = false;
                break;
            }
        }
        if (good) currRes += words[j].length;
    }
    if (currRes > res) res = currRes;
}

print(res);

var $ = "abcdefghijklmnopqrstuvwxyz";
var a = [];
var n = parseInt(readline());
for(var i=0;i<26;i++) a[i] = 0;
var c = []
for(var i=0;i<26;i++) {
    var ddd = [];
    for(var j=0;j<26;j++) ddd[j] = 0;
    c[i] = ddd;
}
for(var i=0;i<n;i++) {
    var s = readline();
    var m = s.length;
    var b = [];
    for(var j=0;j<26;j++) b[j] = false;
    var tmp = 0;
    for(var j=0;j<m;j++) {
        for(var k=0;k<26;k++) {
            if(s[j] == $[k]) {
                if(b[k] == false) tmp++;
                b[k] = true;
                break;
            }
        }
    }
    if(tmp ==1) {
        for(var j=0;j<26;j++) if(b[j] == true) a[j] += m;
    }
    else if(tmp == 2) {
        var id = [];
        id[0] = 'A';
        id[1] = 'A';
        for(var j=0;j<26;j++) if(b[j] == true) {
            if(id[0] == 'A') id[0] = j;
            else {
                id[1] = j;
                break;
            }
        }
        c[ id[0] ][ id[1] ] += m;
    }
}
var ans = 0;
for(var i=0;i<26;i++) {
    if(a[i] > ans) ans = a[i];
    for(var j=i+1;j<26;j++) {
        var tmp = a[i] + a[j] + c[i][j];
        if(tmp > ans) ans = tmp;
    }
}
print(ans);
// var ss = "";
// for(var i=0;i<26;i++) ss += " " + a[i];
// print(ss);
// for(var i=0;i<26;i++) {
//     ss = "";
//     for(var j=0;j<26;j++) {
//         ss += " " + c[i][j];
//     }
//     print(ss);
// }

var n = parseInt(readline()),
    lettersUsed = [],
    pairs = [],
    words = [],
    res = 0,
    currRes = 0;

for (var i = 0; i < n; i++) {
    var word = readline();
    var isGood = true,
        let1 = word.charAt(0),
        let2 = '';
    for (var j = 1; j < word.length; j++) {
        if (word.charAt(j) != let1) {
            if (let2 == '') let2 = word.charAt(j);
            else if (word.charAt(j) != let2) {
                isGood = false;
                break;
            }
        }
    }
    if (isGood) {
        words.push(word);
        if ( lettersUsed.indexOf(let1) == -1 ) lettersUsed.push(let1);
        if ( lettersUsed.indexOf(let2) == -1 && let2 != '' ) lettersUsed.push(let2);
    }
}

for (var i = 0; i < lettersUsed.length - 1; i++) {
    for (var j = i+1; j < lettersUsed.length; j++) {
        pairs.push( [lettersUsed[i], lettersUsed[j]] );
    }
}

for (var i = 0; i < pairs.length; i++) {
    currRes = 0;
    for (var j = 0; j < words.length; j++) {
        var good = true;
        for (var k = 0; k < words[j].length; k++) {
            if (words[j].charAt(k) != pairs[i][0] && words[j].charAt(k) != pairs[i][1]) {
                good = false;
                break;
            }
        }
        if (good) currRes += words[j].length;
    }
    if (currRes > res) res = currRes;
}

print(res);

var n = parseInt(readline()),
	lettersUsed = [],
	pairs = [],
	words = [],
	res = 0,
	currRes = 0;

for (var i = 0; i < n; i++) {
	var word = readline();
	var isGood = true,
		let1 = word.charAt(0),
		let2 = '';
	for (var j = 1; j < word.length; j++) {
		if (word.charAt(i) != let1) {
			if (let2 == '') let2 = word.charAt(i);
			else if (word.charAt(i) != let2) {
				isGood = false;
				break;
			}
		}
	}
	if (isGood) {
		words.push(word);
		if ( lettersUsed.indexOf(let1) == -1 ) lettersUsed.push(let1);
		if ( lettersUsed.indexOf(let2) == -1 && let2 != '' ) lettersUsed.push(let2);
	}
}

for (var i = 0; i < lettersUsed.length - 1; i++) {
	for (var j = i+1; j < lettersUsed.length; j++) {
		pairs.push( [lettersUsed[i], lettersUsed[j]] );
	}
}

for (var i = 0; i < pairs.length; i++) {
	currRes = 0;
	for (var j = 0; j < words.length; j++) {
		var good = true;
		for (var k = 0; k < words[j].length; k++) {
			if (words[j].charAt(k) != pairs[i][0] && words[j].charAt(k) != pairs[i][1]) {
				good = false;
				break;
			}
		}
		if (good) currRes += words[j].length;
	}
	if (currRes > res) res = currRes;
}

print(res);


You are given $$$n$$$ distinct points on a plane. The coordinates of the $$$i$$$-th point are $$$(x_i, y_i)$$$.For each point $$$i$$$, find the nearest (in terms of Manhattan distance) point with integer coordinates that is not among the given $$$n$$$ points. If there are multiple such points — you can choose any of them.The Manhattan distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of points in the set. The next $$$n$$$ lines describe points. The $$$i$$$-th of them contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le 2 \cdot 10^5$$$) — coordinates of the $$$i$$$-th point. It is guaranteed that all points in the input are distinct.

Print $$$n$$$ lines. In the $$$i$$$-th line, print the point with integer coordinates that is not among the given $$$n$$$ points and is the nearest (in terms of Manhattan distance) to the $$$i$$$-th point from the input. Output coordinates should be in range $$$[-10^6; 10^6]$$$. It can be shown that any optimal answer meets these constraints. If there are several answers, you can print any of them.

const coords = {};
const nbrs = {};
const points = require("fs").readFileSync(0, "utf8").split("\n").slice(1).filter(Boolean).map(point => {
    let [x,y] = point.split(" ").map(n => parseInt(n, 10));
    const str = `${x} ${y}`;
    coords[str] = [x,y];
    nbrs[str] = [
        `${x+1} ${y}`,`${x-1} ${y}`,`${x} ${y-1}`,`${x} ${y+1}`
    ];
    return str;
});

const map = {};
for(let point of points) {
    map[ point ] = [];
    for(ne of nbrs[point]) {
        if(map[ne]) {
            map[ne].push(point);
            map[point].push(ne);
        }
    }
}

let best = {}, wset = [];
for(let point of points) {
    if(map[point].length < 4) {
        wset.push(point);
        best[point] = nbrs[point].find(pt => !map[point].includes(pt));
    }
}

while(wset.length) {
    wset = wset.map(point => nbrs[point].filter(ne => {
        if(map[ne] && !best[ne]) {
            best[ne] = best[point];
            return true;
        }
    })).flat(1);
}

for(let point of points) {
    console.log(best[point]);
}

'use strict'; /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  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++];
}

module.exports = E;

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

const EPS = 1e-6;

const getDist = (p1, p2)=>Math.abs(p1[0]-p2[0])+Math.abs(p1[1]-p2[1])

class GDB {
  constructor(points){
    let XA = this.XA = {};
    let YA = this.YA = {};
    for (let p of points){
      let [x, y] = p;
      if (!XA[x]) XA[x] = new Set();
      XA[x].add(y);
      if (!YA[y]) YA[y] = new Set();
      YA[y].add(x);
    }
    //console.log('XA', XA)
    //console.log('YA', YA)
    /**
    for (let x in XA){
      XA[x].sort((a, b)=>a-b);
    }
    for (let y in YA){
      YA[y].sort((a, b)=>a-b);
    }*/
  }
  getExcluded(point){
    this.cache = new Map();
    let [x, y] = point;
    let bestPoint = [1e6, 1e6];
    let bestDist = getDist(point, bestPoint)
    for (let d=0; d<bestDist; d++){ // potentially binary search
      let closestPoint = this.findClosest(point, d, bestDist-d);
      //console.log('GG', {point, closestPoint, bestDist, d})
      if (!closestPoint)
        continue;
      let dist = getDist(point, closestPoint);
      if (dist < bestDist){
        bestDist = dist;
        bestPoint = closestPoint;
      }
    }
    return bestPoint;
  }
  findClosest(point, dist, maxShift){
    let [x, y] = point;
    let bestPoint = null;
    let bestDist = Infinity;
    let updAns = p=>{
      let d = getDist(point, p);
      if (d<bestDist){
        bestDist = d;
        bestPoint = p;
      }
    };
    let gapY = this.findGap('XA', x+dist, y, maxShift);
    //console.log('AAA', gapY)
    if (gapY!==null)
      updAns([x+dist, gapY])
    gapY = this.findGap('XA', x-dist, y, maxShift);
    if (gapY!==null)
      updAns([x-dist, gapY])
    let gapX = this.findGap('YA', y+dist, x, maxShift);
    if (gapX!==null)
      updAns([gapX, y+dist]);
    gapX = this.findGap('YA', y-dist, x, maxShift);
    if (gapX!==null)
      updAns([gapX, y-dist]);
    // update maxShift?
    return bestPoint;
  }
  findGap(name, s, startPos, maxShift){
    let set = this[name][s];
    if (!set)
      return startPos;
    let K = [name, s, startPos, maxShift].join(';');
    if (0)
    if (this.cache.has(K))
      return this.cache.get(K);
    for (let shift=0; shift<=maxShift; shift++){ // binary search?
      if (!set.has(startPos+shift)){
        this.cache.set(K, startPos+shift)
        return startPos+shift;
      }
      if (shift && !set.has(startPos-shift)){
        this.cache.set(K, startPos-shift)
        return startPos-shift;
      }
    }
    this.cache.set(K, null)
    return null;
  }
}

let dx = [0, 0, 1, -1]
let dy = [-1, 1, 0, 0]
let p2s = p=>p[0]+';'+p[1];
const calc = (points)=>{
  let ansMap = new Map();
  for (let point of points){
    ansMap.set(p2s(point), null);
  }
  let queue = [], qi = 0;
  for (let point of points){
    let [x, y] = point;
    for (let di=0; di<4; di++){
      let dPoint = [x+dx[di], y+dy[di]];
      if (!ansMap.has(p2s(dPoint))){
        ansMap.set(p2s(point), dPoint);
        queue.push(point);
      }
    }
  }
  while (qi<queue.length){
    let point = queue[qi++];
    let [x, y] = point;
    let pointAns = ansMap.get(p2s(point));
    for (let di=0; di<4; di++){
      let dPoint = [x+dx[di], y+dy[di]];
      if (ansMap.has(p2s(dPoint)) && ansMap.get(p2s(dPoint))==null){
        ansMap.set(p2s(dPoint), pointAns);
        queue.push(dPoint);
      }
    }
  }
  return points.map(p=>ansMap.get(p2s(p)))
};

function main() {
    let T = 1 || +readline() /// DISABLE T
    while (T--){
      let n = +readline();
      let arr = []; // [x, y]
      for (let i=0; i<n; i++)
        arr.push(ra());
      print(calc(arr).map(p=>p.join(' ')).join('\n'));
    }
}

E.calc = calc;

const coords = [];
const points = require("fs").readFileSync(0, "utf8").split("\n").slice(1).filter(Boolean).map(point => {
    let [x,y] = point.split(" ").map(n => parseInt(n, 10));
    const str = `${x},${y}`;
    coords[str] = [x,y];
    return str;
});

const nbrs = (pt) => {
    let [x,y] = coords[pt];
    return [`${x+1}${y}`,`${x-1}${y}`,`${x}${y-1}`,`${x}${y+1}`];
}

const map = {};
for(let point of points) {
    map[ point ] = [];
    for(ne of nbrs(point)) {
        if(map[ne]) {
            map[ne].push(point);
            map[point].push(ne);
        }
    }
}

let best = {}, wset = [];
for(let point of points) {
    if(map[point].length < 4) {
        wset.push(point);
        best[point] = nbrs(point).find(pt => !map[point].includes(pt));
    }
}

while(wset.length) {
    wset = wset.map(point => nbrs(point).filter(ne => {
        if(map[ne] && !best[ne]) {
            best[ne] = best[point];
            return true;
        }
    })).flat(1);
}

for(let point of points) {
    console.log(coords[point][0], coords[point][1]);
}

const points = require("fs").readFileSync(0, "utf8").split("\n").slice(1).filter(Boolean).map(point => {
    let [x,y] = point.split(" ").map(n => parseInt(n, 10));
    return x + (y << 18);
});

const map = {};
for(let point of points) {
    map[ point ] = [];
    for(ne of [point-1, point+1, point - (1<<18), point + (1<<18)]) {
        if(map[ne]) {
            map[ne].push(point);
            map[point].push(ne);
        }
    }
}

let best = {}, wset = [];
for(let point of points) {
    if(map[point].length < 4) {
        wset.push(point);
        best[point] = [point-1,point+1,point-(1<<18),point+(1<<18)].find(pt => !map[point].includes(pt));
    }
}

while(wset.length) {
    wset = wset.map(point => [point-1,point+1,point-(1<<18),point+(1<<18)].filter(ne => {
        if(map[ne] && !best[ne]) {
            best[ne] = best[point];
            return true;
        }
    })).flat(1);
}

for(let point of points) {
    console.log(best[point] & ((1<<18) - 1), best[point] >> 18);
}

const points = require("fs").readFileSync(0, "utf8").split("\n").slice(1).filter(Boolean).map(point => {
    let [x,y] = point.split(" ").map(n => parseInt(n, 10));
    return x + (y << 16);
});

const map = {};
for(let point of points) {
    map[ point ] = [];
    for(ne of [point-1, point+1, point - (1<<16), point + (1<<16)]) {
        if(map[ne]) {
            map[ne].push(point);
            map[point].push(ne);
        }
    }
}

let best = {}, wset = [];
for(let point of points) {
    if(map[point].length < 4) {
        wset.push(point);
        best[point] = [point-1,point+1,point-(1<<16),point+(1<<16)].find(pt => !map[point].includes(pt));
    }
}

while(wset.length) {
    wset = wset.map(point => [point-1,point+1,point-(1<<16),point+(1<<16)].filter(ne => {
        if(map[ne] && !best[ne]) {
            best[ne] = best[point];
            return true;
        }
    })).flat(1);
}

for(let point of points) {
    console.log(best[point] & ((1<<16) - 1), best[point] >> 16);
}

'use strict'; /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  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++];
}

module.exports = E;

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

const EPS = 1e-6;

const getDist = (p1, p2)=>Math.abs(p1[0]-p2[0])+Math.abs(p1[1]-p2[1])

class GDB {
  constructor(points){
    let XA = this.XA = {};
    let YA = this.YA = {};
    for (let p of points){
      let [x, y] = p;
      if (!XA[x]) XA[x] = new Set();
      XA[x].add(y);
      if (!YA[y]) YA[y] = new Set();
      YA[y].add(x);
    }
    //console.log('XA', XA)
    //console.log('YA', YA)
    /**
    for (let x in XA){
      XA[x].sort((a, b)=>a-b);
    }
    for (let y in YA){
      YA[y].sort((a, b)=>a-b);
    }*/
  }
  getExcluded(point){
    this.cache = new Map();
    let [x, y] = point;
    let bestPoint = [1e6, 1e6];
    let bestDist = getDist(point, bestPoint)
    for (let d=0; d<bestDist; d++){ // potentially binary search
      let closestPoint = this.findClosest(point, d, bestDist-d);
      //console.log('GG', {point, closestPoint, bestDist, d})
      if (!closestPoint)
        continue;
      let dist = getDist(point, closestPoint);
      if (dist < bestDist){
        bestDist = dist;
        bestPoint = closestPoint;
      }
    }
    return bestPoint;
  }
  findClosest(point, dist, maxShift){
    let [x, y] = point;
    let bestPoint = null;
    let bestDist = Infinity;
    let updAns = p=>{
      let d = getDist(point, p);
      if (d<bestDist){
        bestDist = d;
        bestPoint = p;
      }
    };
    let gapY = this.findGap('XA', x+dist, y, maxShift);
    //console.log('AAA', gapY)
    if (gapY!==null)
      updAns([x+dist, gapY])
    gapY = this.findGap('XA', x-dist, y, maxShift);
    if (gapY!==null)
      updAns([x-dist, gapY])
    let gapX = this.findGap('YA', y+dist, x, maxShift);
    if (gapX!==null)
      updAns([gapX, y+dist]);
    gapX = this.findGap('YA', y-dist, x, maxShift);
    if (gapX!==null)
      updAns([gapX, y-dist]);
    // update maxShift?
    return bestPoint;
  }
  findGap(name, s, startPos, maxShift){
    let set = this[name][s];
    //console.log('findGap', {set, startPos, maxShift})
    if (!set)
      return startPos;
    let K = [name, s, startPos, maxShift].join(';');
    if (this.cache.has(K))
      return this.cache.get(K);
    for (let shift=0; shift<=maxShift; shift++){ // binary search?
      if (!set.has(startPos+shift)){
        this.cache.set(K, startPos+shift)
        return startPos+shift;
      }
      if (shift && !set.has(startPos-shift))
        this.cache.set(K, startPos-shift)
        return startPos-shift;
    }
    this.cache.set(K, null)
    return null;
  }
}

const calc = (points)=>{
  let gdb = new GDB(points);
  let ans = [];
  for (let point of points){
    ans.push(gdb.getExcluded(point))
  }
  return ans;
};

function main() {
    let T = 1 || +readline() /// DISABLE T
    while (T--){
      let n = +readline();
      let arr = []; // [x, y]
      for (let i=0; i<n; i++)
        arr.push(ra());
      print(calc(arr).map(p=>p.join(' ')).join('\n'));
    }
}

E.calc = calc;

'use strict'; /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  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++];
}

module.exports = E;

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

const EPS = 1e-6;

const getDist = (p1, p2)=>Math.abs(p1[0]-p2[0])+Math.abs(p1[1]-p2[1])

class GDB {
  constructor(points){
    let XA = this.XA = {};
    this.cache = new Map();
    let YA = this.YA = {};
    for (let p of points){
      let [x, y] = p;
      if (!XA[x]) XA[x] = new Set();
      XA[x].add(y);
      if (!YA[y]) YA[y] = new Set();
      YA[y].add(x);
    }
    //console.log('XA', XA)
    //console.log('YA', YA)
    /**
    for (let x in XA){
      XA[x].sort((a, b)=>a-b);
    }
    for (let y in YA){
      YA[y].sort((a, b)=>a-b);
    }*/
  }
  getExcluded(point){
    let [x, y] = point;
    let bestPoint = [1e6, 1e6];
    let bestDist = getDist(point, bestPoint)
    for (let d=0; d<bestDist; d++){ // potentially binary search
      let closestPoint = this.findClosest(point, d, bestDist-d);
      //console.log('GG', {point, closestPoint, bestDist, d})
      if (!closestPoint)
        continue;
      let dist = getDist(point, closestPoint);
      if (dist < bestDist){
        bestDist = dist;
        bestPoint = closestPoint;
      }
    }
    return bestPoint;
  }
  findClosest(point, dist, maxShift){
    let [x, y] = point;
    let bestPoint = null;
    let bestDist = Infinity;
    let updAns = p=>{
      let d = getDist(point, p);
      if (d<bestDist){
        bestDist = d;
        bestPoint = p;
      }
    };
    let gapY = this.findGap('XA', x+dist, y, maxShift);
    //console.log('AAA', gapY)
    if (gapY!==null)
      updAns([x+dist, gapY])
    gapY = this.findGap('XA', x-dist, y, maxShift);
    if (gapY!==null)
      updAns([x-dist, gapY])
    let gapX = this.findGap('YA', y+dist, x, maxShift);
    if (gapX!==null)
      updAns([gapX, y+dist]);
    gapX = this.findGap('YA', y-dist, x, maxShift);
    if (gapX!==null)
      updAns([gapX, y-dist]);
    // update maxShift?
    return bestPoint;
  }
  findGap(name, s, startPos, maxShift){
    let set = this[name][s];
    //console.log('findGap', {set, startPos, maxShift})
    if (!set)
      return startPos;
    let K = [name, s, startPos, maxShift].join(';');
    if (this.cache.has(K))
      return this.cache.get(K);
    for (let shift=0; shift<=maxShift; shift++){ // binary search?
      if (!set.has(startPos+shift)){
        this.cache.set(K, startPos+shift)
        return startPos+shift;
      }
      if (shift && !set.has(startPos-shift))
        this.cache.set(K, startPos-shift)
        return startPos-shift;
    }
    this.cache.set(K, null)
    return null;
  }
}

const calc = (points)=>{
  let gdb = new GDB(points);
  let ans = [];
  for (let point of points){
    ans.push(gdb.getExcluded(point))
  }
  return ans;
};

function main() {
    let T = 1 || +readline() /// DISABLE T
    while (T--){
      let n = +readline();
      let arr = []; // [x, y]
      for (let i=0; i<n; i++)
        arr.push(ra());
      print(calc(arr).map(p=>p.join(' ')).join('\n'));
    }
}

E.calc = calc;