You are given a chess board with $$$n$$$ rows and $$$n$$$ columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.A knight is a chess piece that can attack a piece in cell ($$$x_2$$$, $$$y_2$$$) from the cell ($$$x_1$$$, $$$y_1$$$) if one of the following conditions is met:  $$$|x_1 - x_2| = 2$$$ and $$$|y_1 - y_2| = 1$$$, or  $$$|x_1 - x_2| = 1$$$ and $$$|y_1 - y_2| = 2$$$. Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).  A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.

The first line contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of rows (and columns) in the board.

Print $$$n$$$ lines with $$$n$$$ characters in each line. The $$$j$$$-th character in the $$$i$$$-th line should be W, if the cell ($$$i$$$, $$$j$$$) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.

NoteIn the first example, there are $$$8$$$ duels:  the white knight in ($$$1$$$, $$$1$$$) attacks the black knight in ($$$3$$$, $$$2$$$);  the white knight in ($$$1$$$, $$$1$$$) attacks the black knight in ($$$2$$$, $$$3$$$);  the white knight in ($$$1$$$, $$$3$$$) attacks the black knight in ($$$3$$$, $$$2$$$);  the white knight in ($$$1$$$, $$$3$$$) attacks the black knight in ($$$2$$$, $$$1$$$);  the white knight in ($$$3$$$, $$$1$$$) attacks the black knight in ($$$1$$$, $$$2$$$);  the white knight in ($$$3$$$, $$$1$$$) attacks the black knight in ($$$2$$$, $$$3$$$);  the white knight in ($$$3$$$, $$$3$$$) attacks the black knight in ($$$1$$$, $$$2$$$);  the white knight in ($$$3$$$, $$$3$$$) attacks the black knight in ($$$2$$$, $$$1$$$).

const process = require('process');

let inp = "";
process.stdin.on('data', chunk => inp += chunk);
process.stdin.on('end', () => {
    const n = +inp;
    let u = "";
    let v = "";
    for (let i = 0; i < n; ++i) {
        u += 'W';
        v += 'B';
        [u, v] = [v, u];
    }
    for (let i = 0; i < n; ++i)
        console.log(i % 2 === 1 ? u : v);
});

"use strict";

var n = parseInt(readline());
var arr = [];

for(var i=0 ; i<n ; i++){
    var str = '';
    if(i%2===1) {
        str+='W';
    }
    else {
        str+='B';
    }

    for(var j =1 ; j<n ; j++){
        if(str[j-1]==='B'){
            str+='W';
        }else {
            str+='B';
        }
    }

    arr.push(str);
}

write(arr.join('\n'));

"use strict";

var n = parseInt(readline());
var arr = [];

for (var i = 0; i < n; i++) {
  var str = '';

  if (i % 2 === 1) {
    str += 'W';
  } else {
    str += 'B';
  }

  for (var j = 1; j < n; j++) {
    if (str[j - 1] === 'B') {
      str += 'W';
    } else {
      str += 'B';
    }
  }

  arr.push(str);
}

write(arr.join('\n'));


Consider the array $$$a$$$ composed of all the integers in the range $$$[l, r]$$$. For example, if $$$l = 3$$$ and $$$r = 7$$$, then $$$a = [3, 4, 5, 6, 7]$$$.Given $$$l$$$, $$$r$$$, and $$$k$$$, is it possible for $$$\gcd(a)$$$ to be greater than $$$1$$$ after doing the following operation at most $$$k$$$ times?   Choose $$$2$$$ numbers from $$$a$$$.  Permanently remove one occurrence of each of them from the array.  Insert their product back into $$$a$$$. $$$\gcd(b)$$$ denotes the greatest common divisor (GCD) of the integers in $$$b$$$.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The description of test cases follows. The input for each test case consists of a single line containing $$$3$$$ non-negative integers $$$l$$$, $$$r$$$, and $$$k$$$ ($$$1 \leq l \leq r \leq 10^9, \enspace 0 \leq k \leq r - l$$$).

For each test case, print "YES" if it is possible to have the GCD of the corresponding array greater than $$$1$$$ by performing at most $$$k$$$ operations, and "NO" otherwise (case insensitive).

NoteFor the first test case, $$$a = [1]$$$, so the answer is "NO", since the only element in the array is $$$1$$$.For the second test case the array is $$$a = [3, 4, 5]$$$ and we have $$$1$$$ operation. After the first operation the array can change to: $$$[3, 20]$$$, $$$[4, 15]$$$ or $$$[5, 12]$$$ all of which having their greatest common divisor equal to $$$1$$$ so the answer is "NO".For the third test case, $$$a = [13]$$$, so the answer is "YES", since the only element in the array is $$$13$$$.For the fourth test case, $$$a = [4]$$$, so the answer is "YES", since the only element in the array is $$$4$$$.

let y = '';
process.stdin.on('data', c => y += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = y.split(EOL);
	var t = lines[0];
	for(i = 1; i <= t; i++){
	    var a = lines[i].split(' ').map(Number);
	    var l = a[0], r = a[1], k = a[2];
	    if(l == r){
	        if(l > 1){
	            console.log('YES');
	        }else{
	            console.log('NO');
	        }
	    }else{
	        var odd = Math.floor((r - l + 1) / 2);
	        var even = Math.ceil((r - l + 1) / 2);
	        if(r % 2 == l % 2){
	            if(r % 2 == 1){
	                odd++;
	            }else{
	                even++;
	            }
	        }
	        if(k >= odd){
	            console.log('YES');
	        }else{
	            console.log('NO');
	        }
	    }
	}
});

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

// LIBRARY START //

const isOdd = (x) => {
  return x & 1;
};
const isEven = (x) => {
  return !(x & 1);
};

const reverseText = (s) => {
  return s.split("").reverse().join("");
};
const hasDuplicates = (str) => /([a-z])\1/i.test(str);

const hasDuplicateChar = (str, char) =>
  str.indexOf(char) !== str.lastIndexOf(char);

const isSorted = (arr) => arr.every((v, i, a) => !i || a[i - 1] <= v);

const findAllIndicesOfChar = (str, char) => {
  str = str.split("");
  let indices = [];
  for (let i = 0; i < str.length; i++) {
    if (str[i] === char) indices.push(i);
  }
  return indices;
};

const splitAt = (index) => (x) => [x.slice(0, index), x.slice(index)];

const isUpper = (str) => !/[a-z]/.test(str) && /[A-Z]/.test(str);

const escapeRegExp = (string) =>
  string.replace(/[.*+\-?^$$${}()|[\]\\]/g, "$$$&");

const replaceAll = (str, find, replace) =>
  str.replace(new RegExp(escapeRegExp(find), "g"), replace);

const findUnique = (str) => {
  return [...str].reduce((acc, curr) => {
    return acc.includes(curr) ? acc : acc + curr;
  }, "");
};

const unique = (str) => {
  const cleanStr = str.replace(/ /gi, "");
  const set = [...new Set(cleanStr)];
  return set;
};

const sortASC = (array) => {
  // var numArray = new Uint32Array(array)
  // var numArray = new Int32Array(array)
  var numArray = new Float64Array(array);
  numArray = numArray.sort();
  return numArray;
};

const removeDuplicates = (array) => [...new Set(array)];

// LIBRARY END

function solve() {
  let [l, r, k] = readline().split(" ").map(Number);
  if (l == 1 && r == 1) {
    console.log("NO");
    return;
  }

  if (l == r) {
    console.log("YES");
    return;
  }

  let minMoves = (r - l + 1) - ( Math.floor(r/2) - Math.floor((l-1)/2));
  if(minMoves <= k){
    console.log("YES");
  }
  else{
    console.log("NO");
  }
}

function main() {
  let tc = +readline();
  while (tc--) {
    solve();
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

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

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

    for (let test = 0; test < N; test++) {
        let [l,r,k] = readline().split(' ').map(Number);
        if (l === r) {
            output(l === 1 ? 'NO': 'YES');
            continue;
        }
        let ol = l % 2 === 1 ? l : l + 1;
        let or = r % 2 === 1 ? r : r - 1;
        let odd = ((or - ol) / 2) + 1;
        output(odd <= k ? 'YES': 'NO');
    }
}

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

var T = readline();
for(var q=1;q<=T;q++) {
            var [l,r,k] = readline().split(" ").map(w => parseInt(w))
            console.log(solve())
        	function solve() {
        		var n = (r-l)+1;
        		if(k == 0) {
        			if(n > 1) return 'NO'
        			else {
        				if(l == 1) return 'NO'
        				else return 'YES'
        			}
        		}
        		var sum = (r-l)+1;
        		if(sum %2 == 0) sum /= 2;
        		else {
        			if(l%2 == 0) sum = 1 + Math.floor(sum/2);
        			else sum = Math.floor(sum/2)
        		}

        		var odd = n-sum;
        		if(odd < k+1) return 'YES';
        		else return 'NO'
        	}
}

let y = '';
process.stdin.on('data', c => y += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = y.split(EOL);
	var t = lines[0];
	for(i = 1; i <= t; i++){
	    var a = lines[i].split(' ').map(Number);
	    var l = a[0], r = a[1], k = a[2];
	    if(l == r){
	        if(l > 1){
	            console.log('YES');
	        }else{
	            console.log('NO');
	        }
	    }else{
	        var odd = Math.floor((r - l + 1) / 2);
	        var even = Math.floor((r - l + 1) / 2);
	        if(r % 2 == 1){
	            odd++;
	        }else{
	            even++;
	           }
	        if(k >= odd){
	            console.log('YES');
	        }else{
	            console.log('NO');
	        }
	    }
	}
});

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

// LIBRARY START //

const isOdd = (x) => {
  return x & 1;
};
const isEven = (x) => {
  return !(x & 1);
};

const reverseText = (s) => {
  return s.split("").reverse().join("");
};
const hasDuplicates = (str) => /([a-z])\1/i.test(str);

const hasDuplicateChar = (str, char) =>
  str.indexOf(char) !== str.lastIndexOf(char);

const isSorted = (arr) => arr.every((v, i, a) => !i || a[i - 1] <= v);

const findAllIndicesOfChar = (str, char) => {
  str = str.split("");
  let indices = [];
  for (let i = 0; i < str.length; i++) {
    if (str[i] === char) indices.push(i);
  }
  return indices;
};

const splitAt = (index) => (x) => [x.slice(0, index), x.slice(index)];

const isUpper = (str) => !/[a-z]/.test(str) && /[A-Z]/.test(str);

const escapeRegExp = (string) =>
  string.replace(/[.*+\-?^$$${}()|[\]\\]/g, "$$$&");

const replaceAll = (str, find, replace) =>
  str.replace(new RegExp(escapeRegExp(find), "g"), replace);

const findUnique = (str) => {
  return [...str].reduce((acc, curr) => {
    return acc.includes(curr) ? acc : acc + curr;
  }, "");
};

const unique = (str) => {
  const cleanStr = str.replace(/ /gi, "");
  const set = [...new Set(cleanStr)];
  return set;
};

const sortASC = (array) => {
  // var numArray = new Uint32Array(array)
  // var numArray = new Int32Array(array)
  var numArray = new Float64Array(array);
  numArray = numArray.sort();
  return numArray;
};

const removeDuplicates = (array) => [...new Set(array)];

// LIBRARY END

function solve() {
  let [l, r, k] = readline().split(" ").map(Number);

  if (l == 1 && r == 1) {
    console.log("NO");
    return;
  }

  if (l == r) {
    console.log("YES");
    return;
  }

  let minMoves = r - l + 1 - (r / 2 - (l - 1) / 2);
  let ans = minMoves <= k ? "YES" : "NO";
  console.log(ans);
}

function main() {
  let tc = +readline();
  while (tc--) {
    solve();
  }
}


Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.A snake is a pattern on a n by m table. Denote c-th cell of r-th row as (r, c). The tail of the snake is located at (1, 1), then it's body extends to (1, m), then goes down 2 rows to (3, m), then goes left to (3, 1) and so on.Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#').Consider sample tests in order to understand the snake pattern.

The only line contains two integers: n and m (3 ≤ n, m ≤ 50).  n is an odd number.

Output n lines. Each line should contain a string consisting of m characters. Do not output spaces.

function answer(input){
    input = input.split(' ');
    var n = input[0];
    var m = input[1];
    var emptyLine = '';
    for(var i = 0; i < m; i++){
        emptyLine += '.';
    }
    var fullLine = emptyLine.replace(/\./g,'#');
    var snakeSideLine = emptyLine.slice(0,-1);
    var rightSnake = snakeSideLine+'#';
    var leftSnake = '#'+snakeSideLine;
    var output = [];
    var steps = [fullLine,rightSnake,fullLine,leftSnake];

    for(var i = 0; i < n; i++){
        output.push(steps[i%4]);
    }
    output.forEach(function(el){
        print(el);
    });
}

answer(readline());

var line = readline().split(" ");
var n = parseInt(line[0]);
var m = parseInt(line[1]);
for (var i = 0; i < n; i++) {
    if ((i + 1) % 2 === 0) {
        if ((i + 1) % 4 === 0) {
            write("#");
            for (var j = 1; j < m; j++) {
                write(".");
            }
        } else {
            for (var j = 1; j < m; j++) {
                write(".");
            }
            write("#");
        }
    } else {
        for (var j = 0; j < m; j++) {
            write("#");
        }
    }
    write("\n");
}

///////////////////////////////////////////////////////////////////////////////
function readNumber () { return Number(readline()); }
function readNumbersArray () { return readline().split(' ').map(Number); }
function algebraicSum (startValue, finishValue, size) { return (startValue + finishValue) * size / 2; }
///////////////////////////////////////////////////////////////////////////////

var array = readNumbersArray();
var n = array[0], m = array[1];

var a = '';
for (var i = 0; i < m; i++) a += '#';

var ba = '#';
for (var i = 1; i < m; i++) ba += '.';

var ab = '';
for (var i = 1; i < m; i++) ab += '.';
ab += '#';

var result = [];
for (var i = 0; i < n; i++) result.push(a);
for (var i = 1; i < n; i += 4) result[i] = ab;
for (var i = 3; i < n; i += 4) result[i] = ba;

print(result.join('\n'));

var s = readline().split(" ");
var n = Number(s[0]), m = Number(s[1]);
for(var i = 0; i<n; i++) {
    var str = '';
    for(var j = 0; j<m; j++) {
        if (i%2==0) {
            str = str + '#'
        }
        else if (i%4 == 1 && j == m-1) {
            str = str + '#'
        }
        else if (i%4 == 3 && j == 0) {
            str = str + '#'
        }
        else {
            str = str + '.'
        }
    }
    print(str);
}

function solve(){
    var input = readline().split(" ");
    var n = parseInt(input[0]);
    var m = parseInt(input[1]);
    var flag = 1;
    for(var i = 0; i < n; ++i){
        if(i % 2 == 0){
           print(Array(m + 1).join("#"));
        } else {
            flag = 1 - flag;
            if(flag){
                print("#" + Array(m).join("."));
            } else {
                print(Array(m).join(".") + "#");
            }
        }
    }
}
solve();

'use strict'
String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

let array = readline().getNumArray(),
    n = array[0],
    m = array[1],
    empty = '.',
    filled = '#',
    snake = [],
    a = 0;

const isHashExist = (row) => row.indexOf('#') === -1;

for (let i = 0; i < n; i++) {
  let str = '';
  for (let j = 0; j < m; j++) {
    if (i % 2 === 0) {
      str += filled;
    } else {
      if (
        (a % 2 === 0 && j === m - 1 && isHashExist(str)) ||
        (a % 2 !== 0 && j === 0 && isHashExist(str))
        ) {
        str += filled;
          a++;
      } else {
        str += empty;
      }
    }
  }
  snake.push(str);
}
for (let i = 0; i < snake.length; i++){
  write(snake[i] + '\n');
};

var main = function(n, m)
{
    var arrHelpToCreateTrueSnake = [], allInSharp = [], arrResult = [];
    for (var i = 1; i <= m; i++)
    {
        if (i !== 1) arrHelpToCreateTrueSnake.push('.');
        else arrHelpToCreateTrueSnake.push('#');
        allInSharp.push('#');
    }
    for (i = 1; i <= n; i++)
    {
        if (i % 2 === 1) print(allInSharp.join(''));
        else print(arrHelpToCreateTrueSnake.reverse().join(''));
    }
    return 0;
}
var input = readline();
input = input.split(' ');
main(+input[0], +input[1]);

var nm = readline().split(' ').map(Number);
var n = nm[0],
	m = nm[1];

var fullRow = Array.apply(null, new Array(m)).map(function () { return '#'; }).join('');
var turnLeft = Array.apply(null, new Array(m - 1)).map(function () { return '.'; }).join('') + '#';
var turnRight = turnLeft.split('').reverse().join('');

var dir = 'left';

for (var i = 0; i < n; i++) {
	if (i % 2 == 0) {
		print(fullRow);
	} else {
		if (dir == 'left') {
			print(turnLeft);
			dir = 'right';
		} else {
			print(turnRight);
			dir = 'left';
		}
	}
};

var inputs = readline().split(" ");
var n = inputs[1]
var m = inputs[0]
var r = 1;
var str = "";
for (var i = 0; i < m; i++) {
  for (var j = 0; j < n; j++) {
      if (i%2 == 0)
          str += "#";
      else {
          if (r==1) {
              if (j!=n-1)
                  str += ".";
              else
                  str += "#";
          }
          else if (r == 0) {
              if (j!=0)
                  str += ".";
              else
                  str += "#";
          }
      }
  }
  if (i%2 != 0) {
      if (r==1) r = 0;
      else r = 1;
  }
  str += '\n'
}
print(str)

var params = readline().split(" ").map(value => +value);
var n = params[0], m = params[1];
var full = first = last = "";

for(var i = 0; i < m; i++) {full += "#";}
first += "#";  for(var i = 0; i < m - 1; i++) {first += ".";}
for(var i = 0; i < m - 1; i++) {last += ".";} last += "#";

for(var i = 0; i < n; i++) {
	if ((i + 1) % 2 === 1)
		print(full);
	else if ((i + 1) % 4 === 0)
		print(first);
	else
		print(last);
}

"use strict";

var input = readline().split(' ').map(value => +value);
var n = input[0];
var m = input[1];

var a = new Array(m).fill('#').join('');
var b = new Array(m - 1).fill('.').join('') + '#';
var c = '#' + new Array(m - 1).fill('.').join('');

var d = [a, b, a, c];

for (let i = 0; i < n; ++i) {
    print(d[i % 4]);
}

var input = readline().split(' ');var row = input[0];var coulmns = input[1];var result = "";var pin = 0;var pervious=0;

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

if (pin == 0){
	for(var s = 0; s < coulmns; s++){result+="#";}
 pin=1;print(result); result="";
  }else{

 for(var d = 0; d < (coulmns-1); d++){result+=".";}

 if(pervious == 0){result+="#";pervious="1";}else{result="#" + result;pervious="0";}
 pin=0;print(result);result="";}}

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

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var n = one[0];
  var m = one[1];
  var output = new Array(n);
  for(var i = 0; i < n; i++){
    if(i % 2 == 0){
      output[i] = new Array(m).fill("#").join("");
    }else{
      var tmp = new Array(m).fill(".");
      if(i % 4 == 1){
        tmp[m - 1] = "#";
      }else{
        tmp[0] = "#";
      }
      output[i] = tmp.join("");
    }
  }
  myout(myconv(output, 9));
}

const readline = require('readline');

let secondLine = false;

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

let inputs = [];

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

// Read Inputs
rl.on('close', () => {
    const line1 = inputs[0].split(' ');
    const rows = parseInt(line1[0]);
    const cols = parseInt(line1[1]);
    let snake = '';
    let turning = false;
    let direction = 'ltr';

    for (let i = 0; i < rows; i++) {
        for (let j = 0; j < cols; j++) {

            if (!turning) {
                snake += '#';
            } else {
                if (direction == 'rtl') {
                    if (j === cols - 1)
                        snake += '#';
                    else
                        snake += '.';
                } else {
                    if (j === 0)
                        snake += '#';
                    else
                        snake += '.';

                }
            }

        }

        if (!turning) {
            if (direction == 'rtl') {
                direction = 'ltr'
            } else {
                direction = 'rtl'
            }
        }

        turning = !turning;

        console.log(snake);
        snake = ''
    }

});

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

rl.on('line', (d) => {
  const [r, c] = d.split(' ').map(Number);
  let isStart = false;
  let body = '#';
  let empty = '.';

  for (let i = 0; i < r; i++) {
    let ans = '';
    for (let j = 0; j < c; j++) {
      if (i % 2 === 0) {
        ans += body;
      }
      else{
        ans += empty;
      }
    }

    if (i % 2 !== 0) {
      if (isStart) {
        ans = body + ans.slice(1);
      }
      else {
        ans = ans.slice(0, ans.length - 1) + body;
      }
      isStart = !isStart;
    }

    console.log(ans);
  }
});

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

rl.on('line', (d) => {
  const [r, c] = d.split(' ').map(Number);
  let isStart = false;
  let body = '#';
  let empty = '.';
  let ans;

  for (let i = 0; i < r; i++) {
    if (i % 2 === 0) {
      ans = body.repeat(c);
    }
    else {
      ans = isStart ? body + empty.repeat(c - 1) : empty.repeat(c - 1) + body;
      isStart = !isStart;
    }

    console.log(ans);
  }
});

let fs = require('fs');

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

for (let i = 0; i < txt.length; i++) {
    let info = txt[i].split(" ");
    doit(info[0] * 1, info[1] * 1);
}

function doit(n, n1) {
    let drawing = "";
    for (let i = 1; i <= n; i++) {
        if (i % 2 == 1) {
            if (i != 1) {
                drawing = drawing.concat("\n");
                drawing = drawing.concat(new Array(n1).fill("#").join(""));
            } else {
                drawing = drawing.concat(new Array(n1).fill("#").join(""));
            }
        } else {
            drawing = drawing.concat("\n");
            if (i % 4 == 2) {
                drawing = drawing.concat(new Array(n1 - 1).fill(".").join(""));
                drawing = drawing.concat("#");
            } else {
                drawing = drawing.concat("#");
                drawing = drawing.concat(new Array(n1 - 1).fill(".").join(""));
            }
        }

    }
    console.log(drawing);

}

// Sample code to perform I/O:

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

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

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

function main(input) {
    let output = nameLookUp(input);
    process.stdout.write(output);       // Writing output to STDOUT
}

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

// Write your code here
function nameLookUp(str) {

    let inputs = str.trim().split(' ');
    let completeSnake = '';
    let track = true;
    let snakeEmptyCell = '';
    let snakeCell = '';
    for (let i = 1; i <= +inputs[0]; i++) {

        if (i % 2 !== 0) {
            snakeCell = "#".repeat(+inputs[1]);
            completeSnake += snakeCell + '\n';
        } else if (track) {
            snakeEmptyCell = ".".repeat(+inputs[1] - 1) + '#';
            track = false;
            completeSnake += snakeEmptyCell + '\n';
        }
        else {
            snakeEmptyCell = "#" + '.'.repeat(+inputs[1] - 1);
            track = true;
            completeSnake += snakeEmptyCell + '\n';
        }

    }

    return completeSnake.toString();
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', _ => {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

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

function main() {
    let nm = readLine().split(' ').map(value => parseInt(value))
    let n = nm[0];
    let m = nm[1];
    let oke = 1;
    for (var i = 0; i < n; i++) {
        if (i % 2 == 0) {
            console.log('#'.repeat(m))
        } else {
            if (oke % 2 == 1) {
                console.log('.'.repeat(m - 1) + '#')
                oke++;
            } else {
                console.log('#' + '.'.repeat(m - 1))
                oke++;
            }
        }
    }
}

function answer(input){
    input = input.split(' ');
    var n = input[0];
    var m = input[1];
    var emptyLine = '';
    for(var i = 0; i < m; i++){
        emptyLine += '.';
    }
    var fullLine = emptyLine.replace('.','#');
    var snakeSideLine = emptyLine.slice(0,-1);
    var rightSnake = snakeSideLine+'#';
    var leftSnake = '#'+snakeSideLine;
    var output = [];
    var steps = [fullLine,leftSnake,fullLine,rightSnake];

    for(var i = 0; i < n; i++){
        output.push(steps[i%4]);
    }
    output.forEach(function(el){
        print(el);
    });
}

answer(readline());

///////////////////////////////////////////////////////////////////////////////
function readNumber () { return Number(readline()); }
function readNumbersArray () { return readline().split(' ').map(Number); }
function algebraicSum (startValue, finishValue, size) { return (startValue + finishValue) * size / 2; }
///////////////////////////////////////////////////////////////////////////////

var array = readNumbersArray();
var n = array[0], m = array[1];

var a = '';
for (var i = 0; i < m; i++) a += '#';

var ba = '#';
for (var i = 1; i < m; i++) ba += '-';

var ab = '';
for (var i = 1; i < m; i++) ab += '-';
ab += '#';

var result = [];
for (var i = 0; i < n; i++) result.push(a);
for (var i = 1; i < n; i += 4) result[i] = ab;
for (var i = 3; i < n; i += 4) result[i] = ba;

print(result.join('\n'));

'use strict'
String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

let array = readline().getNumArray(),
    n = array[0],
    m = array[1],
    empty = '.',
    filled = '#',
    snake = [];

for (let i = 0; i < n; i++) {
  let str = '';
  for (let j = 0; j < m; j++) {
    if (i % 2 === 0) {
      str += filled;
    } else {
      if (j === m - 1) {
        str += filled;
      } else {
        str += empty;
      }
    }
  }
  snake.push(str);
}
for (let i = 0; i < snake.length; i++){
  write(snake[i] + '\n');
};

'use strict'
String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

let array = readline().getNumArray(),
    n = array[0],
    m = array[1],
    empty = '.',
    filled = '#',
    snake = [];

for (let i = 0; i < n; i++) {
  let str = '';
  for (let j = 0; j < m; j++) {
    if (i % 2 === 0) {
      str += filled;
    } else {
      if (j === m - 1) {
        str += filled;
      } else {
        str += empty;
      }
    }
  }
  snake.push(str);
}
for (let i = 0; i < snake.length; i++){
  write(snake[i]);
};

var inputs = readline().split(" ");
var n = inputs[0]
var m = inputs[1]
var r = 1;
var str = "";
for (var i = 0; i < m; i++) {
  for (var j = 0; j < n; j++) {
      if (i%2 == 0)
          str += "#";
      else {
          if (r==1) {
              if (j!=n-1)
                  str += ".";
              else
                  str += "#";
          }
          else if (r == 0) {
              if (j!=0)
                  str += ".";
              else
                  str += "#";
          }
      }
  }
  if (i%2 != 0) {
      if (r==1) r = 0;
      else r = 1;
  }
  print(str)
}

var params = readline().split(" ").map(value => +value);
var n = params[0], m = params[1];
var full = first = last = "";

for(var i = 0; i < n; i++) {full += "#";}
first += "#";  for(var i = 0; i < n - 1; i++) {first += ".";}
for(var i = 0; i < n - 1; i++) {last += ".";} last += "#";

for(var i = 0; i < n; i++) {
	if ((i + 1) % 2 === 1)
		print(full);
	else if ((i + 1) % 4 === 0)
		print(first);
	else
		print(last);
}

const readline = require('readline');

let secondLine = false;

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

let inputs = [];

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

// Read Inputs
rl.on('close', () => {
    const line1 = inputs[0].split(' ');
    const rows = parseInt(line1[0]);
    const cols = parseInt(line1[1]);
    let snake = '';
    let turning = false;
    let opposite = false;

    for (let i = 0; i < rows; i++) {
        for (let j = 0; j < cols; j++) {

            if (!turning) {
                snake += '#';
            } else {
                if (!opposite) {
                    if (j === cols - 1)
                        snake += '#';
                    else
                        snake += '.';
                } else {
                    if (j === 0)
                        snake += '#';
                    else
                        snake += '.';
                }
            }

        }

        if ((i + 1) % 3 === 0)
            opposite = !opposite;
        turning = !turning;
        console.log(snake);
        snake = ''
    }

});

let fs = require('fs');

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

for (let i = 0; i < txt.length; i++) {
    let info = txt[i].split(" ");
    doit(info[0] * 1, info[1] * 1);
}

function doit(n, n1) {
    let drawing = "";
    for (let i = 1; i <= n; i++) {
        if (i % 2 == 1) {
            if (n != 1) {
                drawing = drawing.concat("\n");
                drawing = drawing.concat(new Array(n1).fill("#").join(""));
            } else {
                drawing = drawing.concat(new Array(n1).fill("#").join(""));
            }
        } else {
            drawing = drawing.concat("\n");
            if (i % 4 == 2) {
                drawing = drawing.concat(new Array(n1 - 1).fill(".").join(""));
                drawing = drawing.concat("#");
            } else {
                drawing = drawing.concat("#");
                drawing = drawing.concat(new Array(n1 - 1).fill(".").join(""));
            }
        }

    }
    console.log(drawing);

}


There are $$$n$$$ distinct points on a coordinate line, the coordinate of $$$i$$$-th point equals to $$$x_i$$$. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size.In other words, you have to choose the maximum possible number of points $$$x_{i_1}, x_{i_2}, \dots, x_{i_m}$$$ such that for each pair $$$x_{i_j}$$$, $$$x_{i_k}$$$ it is true that $$$|x_{i_j} - x_{i_k}| = 2^d$$$ where $$$d$$$ is some non-negative integer number (not necessarily the same for each pair of points).

The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of points. The second line contains $$$n$$$ pairwise distinct integers $$$x_1, x_2, \dots, x_n$$$ ($$$-10^9 \le x_i \le 10^9$$$) — the coordinates of points.

In the first line print $$$m$$$ — the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print $$$m$$$ integers — the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them.

NoteIn the first example the answer is $$$[7, 3, 5]$$$. Note, that $$$|7-3|=4=2^2$$$, $$$|7-5|=2=2^1$$$ and $$$|3-5|=2=2^1$$$. You can't find a subset having more points satisfying the required property.

'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString='';
let currentLine=0;
process.stdin.on('data',inputStdin=>{
    inputString+=inputStdin;
});
process.stdin.on('end',_=>{
    inputString=inputString.trim().split("\n").map(string=>{
        return string.trim();
    });
    main();
});
function readLine()
{
    return inputString[currentLine++];
}
/*function bs(A,x)
{
    let lo=0,hi=A.length-1,mi;
    while(lo<=hi)
    {
        mi=Math.floor((lo+hi)/2);
        if(A[mi]==x)
        {
            return true;
        }
        else if(A[mi]>x)
        {
            lo=mi+1;
        }
        else
        {
            hi=mi-1;
        }
    }
    return false;
}*/
function main()
{
    const n=parseInt(readLine());
    let arr=readLine().trim().split(' ').map(x=>{return +(x.trim());});
    arr.sort((a,b)=>a-b);
    //console.log(arr);
    let ans=String(arr[0]);
    let mp=new Map();
    for(let i=0;i<n;++i)
    {
        mp.set(arr[i],true);
    }
    let q,f=true;
    for(let i=0;i<n;++i)
    {
        for(let j=0;j<31;++j)
        {
            q=1<<j;
            if(mp.has(arr[i]+q))
            {
                ans=arr[i]+' '+(arr[i]+q);
                f=false;
                if(mp.has(arr[i]+q*2))
                {
                    ans=ans+' '+(arr[i]+q*2);
                    console.log(3);
                    console.log(ans);
                    return;
                }
            }
        }
    }
    if(f)
    {
        console.log(1);
    }
    else
    {
        console.log(2);
    }
    console.log(ans);
}


You are given an array $$$a$$$ of $$$n$$$ non-negative integers. In one operation you can change any number in the array to any other non-negative integer.Let's define the cost of the array as $$$\operatorname{DIFF}(a) - \operatorname{MEX}(a)$$$, where $$$\operatorname{MEX}$$$ of a set of non-negative integers is the smallest non-negative integer not present in the set, and $$$\operatorname{DIFF}$$$ is the number of different numbers in the array.For example, $$$\operatorname{MEX}(\{1, 2, 3\}) = 0$$$, $$$\operatorname{MEX}(\{0, 1, 2, 4, 5\}) = 3$$$.You should find the minimal cost of the array $$$a$$$ if you are allowed to make at most $$$k$$$ operations.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le k \le 10^5$$$) — the length of the array $$$a$$$ and the number of operations that you are allowed to make. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case output a single integer — minimal cost that it is possible to get making at most $$$k$$$ operations.

NoteIn the first test case no operations are needed to minimize the value of $$$\operatorname{DIFF} - \operatorname{MEX}$$$.In the second test case it is possible to replace $$$5$$$ by $$$1$$$. After that the array $$$a$$$ is $$$[0,\, 2,\, 4,\, 1]$$$, $$$\operatorname{DIFF} = 4$$$, $$$\operatorname{MEX} = \operatorname{MEX}(\{0, 1, 2, 4\}) = 3$$$, so the answer is $$$1$$$.In the third test case one possible array $$$a$$$ is $$$[4,\, 13,\, 0,\, 0,\, 13,\, 1,\, 2]$$$, $$$\operatorname{DIFF} = 5$$$, $$$\operatorname{MEX} = 3$$$.In the fourth test case one possible array $$$a$$$ is $$$[1,\, 2,\, 3,\, 0,\, 0,\, 0]$$$.

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

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

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

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

const calc = (t)=>{
    /* read */
    let [n, k] = ra();
    let a = ra();

    let map = new Map();

    for (let i = 0; i < n; i++) {
        let val = map.get(a[i]) || 0;
        map.set(a[i], val + 1);
    }

    let b = [];
    map.forEach((val, num) => {
        b.push([val, num]);
    });
    b.sort(([x0, y0], [x1, y1]) => x0 - x1);

    let mex;
    let holes = 0;

    for (let i = 0; i <= n; i++) {
        mex = i;
        if (map.has(i)) continue;
        holes++;
        if (holes > k) break;
    }

    let result = 0;
    let i;

    for (i = 0; i < b.length; i++) {
        let [cnt, num] = b[i];
        if (num < mex) continue;
        k -= cnt;
        if (k < 0) break;
    }

    while (i < b.length) {
        let [cnt, num] = b[i++];
        if (num < mex) continue;
        result++;
    }

    return result;
};

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

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

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

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

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

const calc = ()=>{
    /* read */
    let [n, k] = ra();
    let a = ra();

    a.sort((x, y) => x - y);

    let s = new Set(a);
    let map = new Map();
    for (let i = 0; i < n; i++) {
        let val = map.get(a[i]) || 0;
        map.set(a[i], val + 1);
    }
    let mex = 0;
    while (map.has(mex)) {
        mex++;
    }

    let result = map.size - mex;

    k = Math.min(n, k);
    // console.log('DEBUG map', map);

    for (let i = n - 1; i >= 0; i--) {
        // console.log('DEBUG k', k);
        if (k === 0) break;
        if (result === 0) return result;
        let val = map.get(a[i]);
        if (val === 1) {
            map.delete(a[i]);
        } else {
            map.set(a[i], val - 1);
        }
        let mexval = map.get(mex) || 0;
        map.set(mex, mexval + 1);

        while (map.has(mex)) {
            mex++;
        }
        // console.log('DEBUG map.size', map.size);
        // console.log('DEBUG mex', mex);

        let cost = map.size - mex;
        result = Math.min(result, cost);
        k--;
    }

    // console.log('DEBUG map', map);

    return result;
};

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

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

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

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

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

const calc = ()=>{
    /* read */
    let [n, k] = ra();
    let a = ra();

    a.sort((x, y) => x - y);

    let s = new Set(a);
    let map = new Map();
    for (let i = 0; i < n; i++) {
        let val = map.get(a[i]) || 0;
        map.set(a[i], val + 1);
    }
    let mex = 0;
    while (map.has(mex)) {
        mex++;
    }

    let result = map.size - mex;

    k = Math.min(n, k);
    // console.log('DEBUG map', map);

    for (let i = n - 1; i >= 0; i--) {
        console.log('DEBUG k', k);
        if (k === 0) break;
        if (result === 0) return result;
        let val = map.get(a[i]);
        if (val === 1) {
            map.delete(a[i]);
        } else {
            map.set(a[i], val - 1);
        }
        let mexval = map.get(mex) || 0;
        map.set(mex, mexval + 1);

        while (map.has(mex)) {
            mex++;
        }
        // console.log('DEBUG map.size', map.size);
        // console.log('DEBUG mex', mex);

        let cost = map.size - mex;
        result = Math.min(result, cost);
        k--;
    }

    // console.log('DEBUG map', map);

    return result;
};

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


You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2 (i. e. some integer x exists so that ai + aj = 2x).

The first line contains the single positive integer n (1 ≤ n ≤ 105) — the number of integers. The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Print the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2.

NoteIn the first example the following pairs of indexes include in answer: (1, 4) and (2, 4).In the second example all pairs of indexes (i, j) (where i < j) include in answer.

var deg = [];

var cur = 1;

for (var i = 0; i < 64; i++) {
    deg.push(cur);
    cur *= 2;
}

var n = readline();
var a = readline().split(' ');

a.forEach(function(element, index) {
    this[index] = Number(element);
}, a);

var s = new Map();

a.forEach((x, i) => {
    if (s[x] === undefined) {
        s[x] = [];
    }
    s[x].push(i);
});

function find(a, x) {
    var l = 0, r = a.length;
    while (r - l > 1) {
        var m = Math.round((l + r) / 2);
        if (a[m] < x) {
            l = m;
        }
        else {
            r = m;
        }
    }
    return l + 1;
}

var ans = 0;

a.forEach(function(x, num) {
    for (var i = 0; i < 33; i++) {
        var y = deg[i] - x;

        if (y < 0) {
            continue;
        }
        var b = s[y];

        if (b === undefined || b[0] >= num) {
            continue;
        }
        ans += find(b, num);
    }
});

print(ans);


There is a square field of size $$$n \times n$$$ in which two cells are marked. These cells can be in the same row or column.You are to mark two more cells so that they are the corners of a rectangle with sides parallel to the coordinate axes.For example, if $$$n=4$$$ and a rectangular field looks like this (there are asterisks in the marked cells):$$$$$$ \begin{matrix} . & . & * & . \\ . & . & . & . \\ * & . & . & . \\ . & . & . & . \\ \end{matrix} $$$$$$Then you can mark two more cells as follows$$$$$$ \begin{matrix} * & . & * & . \\ . & . & . & . \\ * & . & * & . \\ . & . & . & . \\ \end{matrix} $$$$$$If there are several possible solutions, then print any of them.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 400$$$). Then $$$t$$$ test cases follow. The first row of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 400$$$) — the number of rows and columns in the table. The following $$$n$$$ lines each contain $$$n$$$ characters '.' or '*' denoting empty and marked cells, respectively. It is guaranteed that the sums of $$$n$$$ for all test cases do not exceed $$$400$$$. It is guaranteed that there are exactly two asterisks on the field. They can be in the same row/column. It is guaranteed that the solution exists.

For each test case, output $$$n$$$ rows of $$$n$$$ characters — a field with four asterisks marked corresponding to the statements. If there multiple correct answers, print any of them.

var t = parseInt(readline());

for (var test = 0; test < t; test++) {
    var n = parseInt(readline());
    var matr = [];
    var i1, j1, i2, j2;

    var foundFirst = false;

    for (var k = 0; k < n; k++) {
        var str = readline().split('');
        matr.push(str);

        for (var m = 0; m < n; m++) {
            if (str[m] === '*') {
                if (!foundFirst) {
                    i1 = k;
                    j1 = m;
                    foundFirst = true;
                } else {
                    i2 = k;
                    j2 = m;
                }
            }
        }
    }

    if (i1 === i2) {
        if (i1 + 1 < n) {
            matr[i1 + 1][j2] = '*';
            matr[i2 + 1][j1] = '*';
        } else {
            matr[i1 - 1][j2] = '*';
            matr[i2 - 1][j1] = '*';
        }
    } else if (j1 === j2) {
        if (j1 + 1 < n) {
            matr[i1][j2 + 1] = '*';
            matr[i2][j1 + 1] = '*';
        } else {
            matr[i1][j2 - 1] = '*';
            matr[i2][j1 - 1] = '*';
        }
    } else {
        matr[i1][j2] = '*';
        matr[i2][j1] = '*';
    }

    for (var k = 0; k < n; k++) {
        print(matr[k].join(''));
    }
}

function solution() {
  var t = parseInt(readline());
  for (var i = 0; i < t; i++) {
    var n = parseInt(readline());
    var matrix = [];
    var corners = [];
    for (var j = 0; j < n; j++) {
      var row = readline().split("");
      var corner = row.indexOf("*");
      if (corner !== -1) {
        var corner2 = row.indexOf("*", corner + 1);
        if (corner2 !== -1) {
          corners.push({row:j,col:corner});
          corners.push({row:j,col:corner2});
        } else {
          corners.push({row:j,col:corner});
        }
      }

      matrix.push(row);
    }
    if (corners.length === 2) {
      if (corners[0].col === corners[1].col) {
        if (matrix[corners[0].row][corners[0].col + 1]) {
          matrix[corners[0].row][corners[0].col + 1] = "*";
          matrix[corners[1].row][corners[1].col + 1] = "*";
        } else if (matrix[corners[0].row][corners[0].col - 1]) {
          matrix[corners[0].row][corners[0].col - 1] = "*";
          matrix[corners[1].row][corners[1].col - 1] = "*";
        }
      }
      if (corners[0].row === corners[1].row) {
        if (matrix[corners[0].row + 1]) {
          matrix[corners[0].row + 1][corners[0].col] = "*";
          matrix[corners[1].row + 1][corners[1].col] = "*";
        } else if (matrix[corners[0].row - 1]) {
          matrix[corners[0].row - 1][corners[0].col] = "*";
          matrix[corners[1].row - 1][corners[1].col] = "*";
        }
      }
      if (corners[0].col !== corners[1].col && corners[0].row !== corners[1].row) {
        matrix[corners[0].row][corners[1].col] = "*";
        matrix[corners[1].row][corners[0].col] = "*";
      }
    }
    for (var k = 0; k < matrix.length; k++) {
      print(matrix[k].join(""));
    }
  }
}

solution();

"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 and then write your logic in `main`

const makeSquareArray = (squareLength) => {
  const squareString = [];

  Array.from({ length: squareLength }).forEach(() => {
    const stringArray = readline().split("");
    squareString.push(stringArray);
  });

  return squareString;
};

const getCoordinates = (squareString) => {
  const cellCoords = [];
  for (let x = 0; x < squareString.length; x++) {
    const row = squareString[x];
    for (let y = 0; y < row.length; y++) {
      if (row[y] === "*") {
        cellCoords.push({ x, y });
      }
      if (cellCoords.length === 2) {
        return cellCoords;
      }
    }
  }
};

const normalizeSet = (coordsSet) => {
  if (coordsSet.size === 1) {
    coordsSet.add(0);
  }

  if (coordsSet.size === 1) {
    coordsSet.add(1);
  }

  return coordsSet;
};

const main = () => {
  const numberOfTestCases = 1 * readline();
  // console.log("number of test cases", numberOfTestCases);

  Array.from({ length: numberOfTestCases }).forEach(() => {
    const squareLength = 1 * readline();

    let squareString = makeSquareArray(squareLength);

    const [pointOne, pointTwo] = getCoordinates(squareString);
    // console.log("cells", coords);

    let xSet = new Set();
    xSet.add(Math.min(pointOne.x, pointTwo.x));
    xSet.add(Math.max(pointOne.x, pointTwo.x));
    xSet = normalizeSet(xSet);

    let ySet = new Set();
    ySet.add(Math.min(pointOne.y, pointTwo.y));
    ySet.add(Math.max(pointOne.y, pointTwo.y));
    ySet = normalizeSet(ySet);

    for (let x of xSet) {
      for (let y of ySet) {
        squareString[x][y] = "*";
      }
    }

    // console.log(squareString);
    squareString.forEach((line) => {
      console.log(line.join(""));
    });
  });
};

"use strict";

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

let inputString = "";
let currentLine = 0;

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

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

  main();
});

function readline() {
  return inputString[currentLine++];
}
// Make a Snippet for the code above and then write your logic in `main`

const makeSquareArray = (squareLength) => {
  const squareString = [];

  Array.from({ length: squareLength }).forEach(() => {
    squareString.push(readline().split(""));
  });

  return squareString;
};

const getCoordinates = (squareString) => {
  const cells = [];
  for (let i = 0; i < squareString.length; i++) {
    const row = squareString[i];
    for (let j = 0; j < row.length; j++) {
      if (row[j] === "*") {
        cells.push([i, j]);
      }
      if (cells.length === 2) {
        return cells;
      }
    }
  }
};

const normalizeSet = (coordsSet) => {
  if (coordsSet.size === 1) {
    coordsSet.add(0);
  }

  if (coordsSet.size === 1) {
    coordsSet.add(1);
  }

  return coordsSet;
};

const main = () => {
  const numberOfTestCases = 1 * readline();
  // console.log("number of test cases", numberOfTestCases);

  Array.from({ length: numberOfTestCases }).forEach(() => {
    const squareLength = 1 * readline();

    let squareString = makeSquareArray(squareLength);

    const coords = getCoordinates(squareString);
    // console.log("cells", coords);

    let xs = new Set();
    xs.add(Math.min(coords[0][0], coords[1][0]));
    xs.add(Math.max(coords[0][0], coords[1][0]));
    xs = normalizeSet(xs);

    let ys = new Set();
    ys.add(Math.min(coords[0][1], coords[1][1]));
    ys.add(Math.max(coords[0][1], coords[1][1]));
    ys = normalizeSet(ys);

    for (let x of xs) {
      for (let y of ys) {
        squareString[x][y] = "*";
      }
    }

    // console.log(squareString);
    squareString.forEach((line) => {
      console.log(line.join(""));
    });
  });
};

//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{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
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();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = new Array(N);
		var map = new Array(N);
		var fx = -1;
		var fy = -1;
		var sx = -1;
		var sy = -1;
		for(var j = 0; j < N; j++){
			map[j] = new Array(N);
			list[j] = nextCharArray();
			for(var k = 0; k < N; k++){
				map[j][k] = new Array(2).fill(false);
				if(list[j][k] == "*"){
					if(fx == -1){
						fx = k;
						fy = j;
					}else{
						sx = k;
						sy = j;
					}
				}
			}
		}
		var isSame = false;
		for(var j = 0; j < N; j++){
			var count = 0;
			for(var k = 0; k < N; k++){
				count += (list[j][k] == "*") ? 1 : 0;
			}
			if(count == 2){
				isSame = "yoko";
			}
		}
		for(var j = 0; j < N; j++){
			var count = 0;
			for(var k = 0; k < N; k++){
				count += (list[k][j] == "*") ? 1 : 0;
			}
			if(count == 2){
				isSame = "tate";
			}
		}
		var count = 0;
		if(isSame == "yoko"){
			list[(fy + 1) % N][fx] = "*";
			list[(sy + 1) % N][sx] = "*";

		}else if(isSame == "tate"){
			list[fy][(fx + 1) % N] = "*";
			list[sy][(sx + 1) % N] = "*";
		}else{

			while(fx + count < N || fx - count >= 0 || fy + count < N || fy - count >= 0){
				if(fx + count < N){
					map[fy][fx + count][0] = true;
				}
				if(fx - count >= 0){
					map[fy][fx - count][0] = true;
				}
				if(fy + count < N){
					map[fy + count][fx][0] = true;
				}
				if(fy - count >= 0){
					map[fy - count][fx][0] = true;
				}
				count++;
			}
			count = 0;
			while(sx + count < N || sx - count >= 0 || sy + count < N || sy - count >= 0){
				if(sx + count < N){
					map[sy][sx + count][1] = true;
				}
				if(sx - count >= 0){
					map[sy][sx - count][1] = true;
				}
				if(sy + count < N){
					map[sy + count][sx][1] = true;
				}
				if(sy - count >= 0){
					map[sy - count][sx][1] = true;
				}
				count++;
			}
			for(var j = 0; j < N; j++){
				for(var k = 0; k < N; k++){
					if(map[j][k][0] && map[j][k][1]){
						list[j][k] = "*";
					}
				}
			}
		}
		var output = [];
		for(var j = 0; j < N; j++){
			output.push(myconv(list[j], 0));
		}
		myout(myconv(output, 9));
	}
}

"use strict";
exports.__esModule = true;
// hello world
process.stdin.resume();
process.stdin.setEncoding('utf-8');
var inputString = [];
var s = "";
var currentLine = 0;
process.stdin.on('data', function (inputStdin) {
    s += inputStdin;
});
process.stdin.on('end', function (_) {
    inputString = s.trim().split('\n').map(function (string) {
        return string.trim();
    });
    s = null;
    main();
});
function readline() {
    return inputString[currentLine++];
}
function readIntLine() {
    return inputString[currentLine++].split(" ").map(function (e) { return parseInt(e); });
}
var println = console.log;
// CODE
function main() {
    var t = readIntLine()[0];
    var _loop_1 = function (i) {
        //parsing
        var n = readIntLine()[0];
        var arr = [];
        for (var i_1 = 0; i_1 < n; i_1++) {
            arr.push(readline());
        }
        var a = null, b = null;
        // -> find a and b pos
        arr.forEach(function (s, y) {
            for (var i_2 = 0; i_2 < s.length; i_2++) {
                var p = s[i_2] == "*" ? i_2 : -1;
                if (p != -1) {
                    if (!a) {
                        a = { y: y, x: p };
                    }
                    else {
                        b = { y: y, x: p };
                    }
                }
            }
        });
        var c = void 0, d = void 0;
        //check special cases
        if (a.x == b.x) {
            c = a.x == 0 ? { y: a.y, x: a.x + 1 } : { y: a.y, x: a.x - 1 };
            d = b.x == 0 ? { y: b.y, x: b.x + 1 } : { y: b.y, x: b.x - 1 };
        }
        else if (a.y == b.y) {
            c = a.y == 0 ? { y: a.y + 1, x: a.x } : { y: a.y - 1, x: a.x };
            d = b.y == 0 ? { y: b.y + 1, x: b.x } : { y: b.y - 1, x: b.x };
        }
        else {
            c = { x: a.x, y: b.y };
            d = { x: b.x, y: a.y };
        }
        //include c and d in the array
        arr[c.y] = arr[c.y].slice(0, c.x) + "*" + arr[c.y].slice(c.x + 1);
        arr[d.y] = arr[d.y].slice(0, d.x) + "*" + arr[d.y].slice(d.x + 1);
        println(arr.join("\n"));
    };
    for (var i = 0; i < t; i++) {
        _loop_1(i);
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

var maxN = 21
var mod = 1000000007

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

function main() {
  const xx = readline();

  Array(Number(xx)).fill(1).map((t, i) => {
    const n = parseInt(readline());
    // var [n, p, k] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // });
    var a = new Array(n)
    for (let j = 0; j < n; j++) {
      a[j] = readline().split('').map((x, iii) => {
        return x
      })
    }
    var x1, y1
    var x2, y2

    for (let j = 0; j < n; j++) {
      for (let i = 0; i < n; i++) {
        if (a[i][j] === '*' && x1 === undefined) {
          x1 = i
          y1 = j
          continue
        }
        if (a[i][j] === '*' && x2 === undefined) {
          x2 = i
          y2 = j
        }
      }
    }
    // console.log(x1,y1,x2,y2)

    if (x1 === x2) {
      var add = x1 > 0 ? -1 : +1
      a[x1 + add][y1] = '*'
      a[x1 + add][y2] = '*'
    } else if (y1 === y2) {
      add = y1 > 0 ? -1 : +1

      a[x1][y1 + add] = '*'
      a[x2][y1 + add] = '*'

    } else {
      a[x1][y2] = '*'
      a[x2][y1] = '*'
    }

    for (let j = 0; j < n; j++) {
      console.log(a[j].join(''))

    }

  })
}

//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{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
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();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = new Array(N);
		var map = new Array(N);
		var fx = -1;
		var fy = -1;
		var sx = -1;
		var sy = -1;
		for(var j = 0; j < N; j++){
			map[j] = new Array(N);
			list[j] = nextCharArray();
			for(var k = 0; k < N; k++){
				map[j][k] = new Array(2).fill(false);
				if(list[j][k] == "*"){
					if(fx == -1){
						fx = k;
						fy = j;
					}else{
						sx = k;
						sy = j;
					}
				}
			}
		}
		var isSame = false;
		for(var j = 0; j < N; j++){
			var count = 0;
			for(var k = 0; k < N; k++){
				count += (list[j][k] == "*") ? 1 : 0;
			}
			if(count == 2){
				isSame = "yoko";
			}
		}
		for(var j = 0; j < N; j++){
			var count = 0;
			for(var k = 0; k < N; k++){
				count += (list[k][j] == "*") ? 1 : 0;
			}
			if(count == 2){
				isSame = "tate";
			}
		}
		var count = 0;
		if(isSame == "yoko"){
			for(var j = 0; j < N; j++){
				for(var k = 0; k < N; k++){
					if(list[j][k] == "*"){
						if(count == 2){
							break;
						}
						list[(k + N - 1) % N][j] = "*";
						count++;
						break;
					}
				}
			}
		}else if(isSame == "tate"){
			for(var j = 0; j < N; j++){
				for(var k = 0; k < N; k++){
					if(list[j][k] == "*"){
						if(count == 2){
							break;
						}
						list[j][(k + N - 1) % N] = "*";
						count++;
						break;
					}
				}
			}
		}else{

			while(fx + count < N || fx - count >= 0 || fy + count < N || fy - count >= 0){
				if(fx + count < N){
					map[fy][fx + count][0] = true;
				}
				if(fx - count >= 0){
					map[fy][fx - count][0] = true;
				}
				if(fy + count < N){
					map[fy + count][fx][0] = true;
				}
				if(fy - count >= 0){
					map[fy - count][fx][0] = true;
				}
				count++;
			}
			count = 0;
			while(sx + count < N || sx - count >= 0 || sy + count < N || sy - count >= 0){
				if(sx + count < N){
					map[sy][sx + count][1] = true;
				}
				if(sx - count >= 0){
					map[sy][sx - count][1] = true;
				}
				if(sy + count < N){
					map[sy + count][sx][1] = true;
				}
				if(sy - count >= 0){
					map[sy - count][sx][1] = true;
				}
				count++;
			}
			for(var j = 0; j < N; j++){
				for(var k = 0; k < N; k++){
					if(map[j][k][0] && map[j][k][1]){
						list[j][k] = "*";
					}
				}
			}
		}
		var output = [];
		for(var j = 0; j < N; j++){
			output.push(myconv(list[j], 0));
		}
		myout(myconv(output, 9));
	}
}


One evening Rainbow Dash and Fluttershy have come up with a game. Since the ponies are friends, they have decided not to compete in the game but to pursue a common goal. The game starts on a square flat grid, which initially has the outline borders built up. Rainbow Dash and Fluttershy have flat square blocks with size $$$1\times1$$$, Rainbow Dash has an infinite amount of light blue blocks, Fluttershy has an infinite amount of yellow blocks. The blocks are placed according to the following rule: each newly placed block must touch the built on the previous turns figure by a side (note that the outline borders of the grid are built initially). At each turn, one pony can place any number of blocks of her color according to the game rules.Rainbow and Fluttershy have found out that they can build patterns on the grid of the game that way. They have decided to start with something simple, so they made up their mind to place the blocks to form a chess coloring. Rainbow Dash is well-known for her speed, so she is interested in the minimum number of turns she and Fluttershy need to do to get a chess coloring, covering the whole grid with blocks. Please help her find that number!Since the ponies can play many times on different boards, Rainbow Dash asks you to find the minimum numbers of turns for several grids of the games.The chess coloring in two colors is the one in which each square is neighbor by side only with squares of different colors.

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 100$$$): the number of grids of the games.  Each of the next $$$T$$$ lines contains a single integer $$$n$$$ ($$$1 \le n \le 10^9$$$): the size of the side of the grid of the game.

For each grid of the game print the minimum number of turns required to build a chess coloring pattern out of blocks on it.

NoteFor $$$3\times3$$$ grid ponies can make two following moves:

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 num = +readLine();
    console.log(Math.floor(num / 2) + 1);
  }
}

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

//Don't have to see. end------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array(t);
  for(var i = 0; i < t; i++){
    var N = nextInt();
    output[i] = Math.floor(N / 2) + 1
  }
  myout(myconv(output, 9));
}

let inputString = '';
let currentLine = 0;

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

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

function main() {
  let t = readLine();
  while (t--) {
    const n = readLine();
    console.log(Math.floor(n / 2) + 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(){
    let t = parseInt(readline());

    for(let o = 0; o < t; o++){
        let n = parseInt(readline());

        console.log(Math.floor(n/2) + 1);
    }
}

let inputString = '';
let currentLine = 0;

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

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

function main() {
  let t = readLine();
  while (t--) {
    const n = readLine();
    console.log(n < 3 ? n : (n < 5 ? n - 1 : n - 2));
  }
}


The only difference between easy and hard versions is the maximum value of $$$n$$$.You are given a positive integer number $$$n$$$. You really love good numbers so you want to find the smallest good number greater than or equal to $$$n$$$.The positive integer is called good if it can be represented as a sum of distinct powers of $$$3$$$ (i.e. no duplicates of powers of $$$3$$$ are allowed).For example:  $$$30$$$ is a good number: $$$30 = 3^3 + 3^1$$$,  $$$1$$$ is a good number: $$$1 = 3^0$$$,  $$$12$$$ is a good number: $$$12 = 3^2 + 3^1$$$,  but $$$2$$$ is not a good number: you can't represent it as a sum of distinct powers of $$$3$$$ ($$$2 = 3^0 + 3^0$$$),  $$$19$$$ is not a good number: you can't represent it as a sum of distinct powers of $$$3$$$ (for example, the representations $$$19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0$$$ are invalid),  $$$20$$$ is also not a good number: you can't represent it as a sum of distinct powers of $$$3$$$ (for example, the representation $$$20 = 3^2 + 3^2 + 3^0 + 3^0$$$ is invalid). Note, that there exist other representations of $$$19$$$ and $$$20$$$ as sums of powers of $$$3$$$ but none of them consists of distinct powers of $$$3$$$.For the given positive integer $$$n$$$ find such smallest $$$m$$$ ($$$n \le m$$$) that $$$m$$$ is a good number.You have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Then $$$q$$$ queries follow. The only line of the query contains one integer $$$n$$$ ($$$1 \le n \le 10^4$$$).

For each query, print such smallest integer $$$m$$$ (where $$$n \le m$$$) that $$$m$$$ is a good number.

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

var gcd = (a, b) => a ? gcd(b % a, a) : b;
var lcm = (a, b) => a * b / gcd(a, b);
const getAllSubsets =
      theArray => theArray.reduce(
        (subsets, value) => subsets.concat(
         subsets.map(set => [value,...set])
        ),
        [[]]
      );

let ar = [];

for(let i=0; i<10;++i){
	let x = 3**i;
	ar.push(x);
}

let arr = getAllSubsets(ar);
// console.log(arr);
arr.splice(0,1);
let arrr =[];
let j=0;
for (let x of arr){
	arrr[j++]= x.reduce((acc,cur)=> acc+cur);
}

// console.log(arrr);

function main(){
	let q = +(readLine());

	while(q--){
		let n = +(readLine());

		let  p = arrr.filter(x=> x>=n)[0];
		console.log(p)

	}
}

'use strict'

const x = [ 1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683 ];
let p = [ 0 ];
for (let i = 0; i < x.length; i++) p = p.concat(p.map(j => j + x[i]));
let q = +readline();
while(q--) { const j = +readline(); print(p[p.findIndex(i => i >= j)]); }

'use strict'

const lst = Array.from({ length: 32 }, (_, i) => Math.pow(3,i)).reverse();

const m = lst.reduce((r, i) => r + i, 0);

for(let t = +readline(); t; t--) {
    const n = +readline();
    let x = m;
    lst.forEach(i => (x - i >= n) && (x -= i))
    print(x);
}


Sereja loves all sorts of algorithms. He has recently come up with a new algorithm, which receives a string as an input. Let's represent the input string of the algorithm as q = q1q2... qk. The algorithm consists of two steps:  Find any continuous subsequence (substring) of three characters of string q, which doesn't equal to either string "zyx", "xzy", "yxz". If q doesn't contain any such subsequence, terminate the algorithm, otherwise go to step 2.  Rearrange the letters of the found subsequence randomly and go to step 1. Sereja thinks that the algorithm works correctly on string q if there is a non-zero probability that the algorithm will be terminated. But if the algorithm anyway will work for infinitely long on a string, then we consider the algorithm to work incorrectly on this string.Sereja wants to test his algorithm. For that, he has string s = s1s2... sn, consisting of n characters. The boy conducts a series of m tests. As the i-th test, he sends substring slisli + 1... sri (1 ≤ li ≤ ri ≤ n) to the algorithm input. Unfortunately, the implementation of his algorithm works too long, so Sereja asked you to help. For each test (li, ri) determine if the algorithm works correctly on this test or not.

The first line contains non-empty string s, its length (n) doesn't exceed 105. It is guaranteed that string s only contains characters: 'x', 'y', 'z'. The second line contains integer m (1 ≤ m ≤ 105) — the number of tests. Next m lines contain the tests. The i-th line contains a pair of integers li, ri (1 ≤ li ≤ ri ≤ n).

For each test, print "YES" (without the quotes) if the algorithm works correctly on the corresponding test and "NO" (without the quotes) otherwise.

NoteIn the first example, in test one and two the algorithm will always be terminated in one step. In the fourth test you can get string "xzyx" on which the algorithm will terminate. In all other tests the algorithm doesn't work correctly.

var s = readline();
var m = parseInt(readline());
nX = [0]
nY = [0]
nZ = [0]

    if(s[0]=='x') {
        nX[nX.length-1]++;
    } else if(s[0]=='y') {
        nY[nY.length-1]++;
    } else nZ[nZ.length-1]++;
for(var i=1; i<s.length; i++) {
    nX.push(nX[nX.length-1]);
    nY.push(nY[nY.length-1]);
    nZ.push(nZ[nZ.length-1]);
    if(s[i]=='x') {
        nX[nX.length-1]++;
    } else if(s[i]=='y') {
        nY[nY.length-1]++;
    } else nZ[nZ.length-1]++;
}
for(var i=0; i<m; i++) {
    var r = readline().split(" ");
    var x = parseInt(r[0])-1;
    var y = parseInt(r[1])-1;
    var numX = nX[y], numY = nY[y], numZ = nZ[y];
    if(x) {
        numX -= nX[x-1];
        numY -= nY[x-1];
        numZ -= nZ[x-1];
    }
    if(Math.abs(numX-numZ)<=1 &&
        Math.abs(numX-numY)<=1 &&
        Math.abs(numY-numZ)<=1 ||
        y-x<2)
        print("YES");
    else print("NO");
    }


On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed.Help the child to find out, what is the minimum total energy he should spend to remove all n parts.

The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered from 1 to n.

Output the minimum total energy the child should spend to remove all n parts of the toy.

NoteOne of the optimal sequence of actions in the first sample is:  First, remove part 3, cost of the action is 20.  Then, remove part 2, cost of the action is 10.  Next, remove part 4, cost of the action is 10.  At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum.In the second sample, the child will spend 400 no matter in what order he will remove the parts.

;(function () {

	print(function (n, m) {

		var price = readline().split(' ').map(Number), sum = 0;

		for (var i = 0; i < m; ++i) {
			var s = readline().split(' ').map(function (e) { return +e - 1; });
			sum += Math.min(price[s[0]], price[s[1]]);
		}

		return sum;

	}.apply(null, readline().split(' ').map(Number)));

}.call(this));

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var data = tokenizeIntegers(readline()),
		n = data[0], m = data[1],
		costs = tokenizeIntegers(readline()),
		total = 0;
	costs.unshift(null);
	for (var i = 0; i < m; ++i) {
		data = tokenizeIntegers(readline());
		var u = data[0], v = data[1];
		if (costs[u] >= costs[v]) {
			total += costs[v];
		} else {
			total += costs[u];
		}
	}
	print(total);
}

main();

var firstLine = readline().split(" ").map(Number);
var n = firstLine[0];
var m = firstLine[1];

var secondLine = readline().split(" ").map(Number);
var energies = []
secondLine.forEach(function(a){energies.push(a)});

var total = 0

energies.unshift(null)

for(var i = 0; i < m; ++i){
	data = readline().split(" ").map(Number);
	var x = data[0]
	var y = data[1]
	if(energies[x] >= energies[y]){
		total+= energies[y]
	}
	else{
		total+= energies[x]
	}
}

print(total)