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

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

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


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

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


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

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

	}
}


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


var x = parseInt(readline());

switch (x % 3) {
    case 2:
        print(1, 2, x - 3);
        break;
    default:
        print(1, 1, x - 2);
        break;
}

var input = Number(readline());

if(input == 3) {
  print("1 1 1");
}

else if(input>3) {
  if((input-3)%3 == 0) {
    print("2 2 " +(input-4));
  }
  else {
    print("1 2 "+ (input-3));
  }
}

function func(){
	var n = parseInt(readline());
	var x = (n-2)%3?1:2;
	// console.log(1,x,n-x-1);
	print(1,x,n-x-1);
}
func();

// var n = 233;
function func(){
	var n = parseInt(readline());
	var x = Math.floor(n/3);
	var y = n%3;
	var t = x%3;
	var a,b,c;
	if(x === 1){
		if(y === 0){
			a = b = c = x;
		}else if(y === 1){
			a = b = x;
			c = x+y;
		}else {
			a = x;
			b = c = x+1;
		}
	}else {
		if(t===0){
			if(y === 1){
				a = x-1;
				b = c = x+1;
			}else{
				a = b = x-1;
				c = x+y+2;
			}
		}else if(t===1){
			if(y === 1){
				a = b = x;
				c = x+y;
			}else{
				a = x;
				b = c = x+y/2;
			}
		}else {
			if(y === 1){
				a = b = x-1;
				c = x+y+2;
			}else{
				a = b = x;
				c = x+y;
			}
		}
	}
	print(a,b,c);
	// console.log(a,b,c)
}
func();

function main(){
    var n = parseInt(readline());
    var result = "";
    var item = parseInt(n/3);
    var adjust = n % 3;

    if((item + adjust) % 3 === 0){
        if( item % 3 === 0){
            result = (item + 2) + " " + (item - 1) + " " + (item + adjust - 1)
        }else{
            result = item + " " + ( item + 3 - adjust )+ " " + (item + 2 * adjust - 3)
        }
    }else{
        if( item % 3 === 0){
            result = (item + 1) + " " + (item - 1) + " " + (item + adjust)
        }else{
            result = item + " " + item + " " + (item + adjust)
        }
    }
    print(result)
}

main()

function main() {
  const cin = new Scanner();
  let n = cin.nextInt() - 1;
  let a = 1, b = Math.trunc(n / 2), c = Math.ceil(n / 2);
  if (b % 3 === 0 || c % 3 === 0) {
    b -= 1;
    c += 1;
  }

  console.log(a, b, c);
}

/*
 *  Api Scanner
 */
class Scanner {
  constructor() {
    this.index = -1;
    this.lines = stdinInput.trim().split('\n'); // eslint-disable-line
  }

  nextLine() {
    this.index += 1;
    return this.lines[this.index].trim();
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray(fn = Number) {
    const array = this.nextLine().split(' ');
    if (fn !== String)
      array.forEach((item, index, arr) => { arr[index] = fn(item); });
    return array;
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', (input) => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

const readline = require('readline').createInterface({input: process.stdin})
const assert = require('assert')

let n, x, y, z
readline.on('line', line => {
    n = parseInt(line)
    if (n == 3) {
        [x, y, z] = [1, 1, 1]
    } else if (n % 3 == 0) {
        [x, y, z] = [1, 4, n - 5]
    } else {
        [x, y, z] = [1, 2, n - 3]
    }
    console.log(`${x} ${y} ${z}`)
})

//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↑入力 ↓出力');
	Main();
});
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 N = nextInt();
	if(N % 3 == 2){
		myout((N - 3) + " 2 1");
	}else{
		myout((N - 2) + " 1 1");
	}
}

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

rl.on('line', (d) => {
  let n = +d;
  let a = 1;
  let b = Math.floor((n - 1) / 2);
  let c = Math.ceil((n - 1) / 2);

  while (b % 3 === 0 || c % 3 === 0) {
    b--;
    c++;
  }

  console.log(a, b, c);
});

var cnt = 0;
process.stdin.addListener("data", function(d) {
	var s = d.toString().trim();
	var x = parseInt(s);
	if( x%3 === 0){
        process.stdout.write(x-2+' 1 1');
    }
	else {
        //if(x==3) process.stdout.write('1 1 1');
         process.stdout.write(x-3+' 1 2');

        }
            cnt++;
    if(cnt > 0) process.exit();
   // process.exit();
});

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

let l = 0;
let hand = []
rl.on('line', (input) => {
    if (l === 0) {
        rl.close();
        let n = parseInt(input)
        if((n-2)%3===0)
         console.log(1,2,n-3)
         else
         console.log(1,1,n-2)
    }
})

var a = Number(readline());
print(1);
if ((a-1)%3 === 0){
    print (1);
    print (a-2);
} else {
    print (2);
    print (a-3);
}

var a = readline();
print(1);
if ((a-1)%3 === 0){
    print (1);
    print (a-2);
} else {
    print (2);
    print (a-3);
}

	var n=parseInt(readline());
	if(n%3===0){print (n/3+" "+n/3+" "+n/3);}
	else{print (Math.floor(n/3)+" "+Math.floor(n/3)+" "+ (n-((Math.floor(n/3))*2)) );}

var input = Number(readline());

if((input%3) == 0) {
  var ans = input/3;
  if(ans%3 != 0) {
    print(ans +" "+ans+ " "+ ans);
  }
  else {
    print((ans+1) +" "+ (ans+1) +" "+(ans-2));
  }

}
else {
  var rem = input%3;
  ans = Math.floor(input/3);
  print((ans +" "+ ans +" "+ (ans+rem)));
}

// var n = 233;
function func(){
	var n = parseInt(readline());
	var x = Math.floor(n/3);
	var y = n%3;
	var t = x%3;
	var a,b,c;
	if(x === 1){
		if(y === 0){
			a = b = c = x;
		}else if(y === 1){
			a = b = x;
			c = x+y;
		}else {
			a = x;
			b = c = x+1;
		}
	}else {
		if(t===0){
			if(y === 1){
				a = x-1;
				b = c = x+1;
			}else{
				a = b = x-1;
				c = x+y+2;
			}
		}else if(t===1){
			if(y === 1){
				a = b = x;
				c = x+y;
			}else{
				a = x;
				b = c = x+1;
			}
		}else {
			if(y === 1){
				a = b = x-1;
				c = x+y+2;
			}else{
				a = b = x;
				c = x+y;
			}
		}
	}
	print(a,b,c);
	// console.log(a,b,c)
}
func();

// var n = 233;
function func(n){
	var n = parseInt(readline());
	var x = Math.floor(n/3);
	var y = n%3;
	var t = x%3;
	var a,b,c;
	if(x === 1){
		if(y === 0){
			a = b = c = x;
		}else if(y === 1){
			a = b = x;
			c = x+y;
		}else {
			a = x;
			b = c = x+1;
		}
	}else {
		if(t===0){
			if(y === 1){
				a = x-1;
				b = c = x+1;
			}else{
				a = b = x-1;
				c = x+y+2;
			}
		}else if(t===1){
			if(y === 1){
				a = b = x;
				c = x+y;
			}else{
				a = b = x;
				c = x+y;
			}
		}else {
			if(y === 1){
				a = b = x-1;
				c = x+y+2;
			}else{
				a = b = x;
				c = x+y;
			}
		}
	}
	print(a,b,c);
}
func();

function main(){
    var n = parseInt(readline());
    var result = "";
    var item = parseInt(n/3);
    var adjust = n % 3;
    if( item % 3 === 0){
        result = (item - 1) + " "+(item +1) + " " + (item + adjust)
    }else if((item + adjust) % 3 === 0){
        result = item + " " + ( item + 3 - adjust )+ " " + (item + 2 * adjust - 3)
    }else{
        result = item + " " + item + " " + (item + adjust)
    }
    print(result)
}

main()

var str = readline();
//var str = 387420489;
var num = Math.round(str / 3);
//alert(str + " " + num)
var salida;
var cantidadSumar = str - (num * 3);
//alert(cantidadSumar);

if (valido(num) == 1 && valido(num + cantidadSumar) == 1) {
//    alert("1")
    salida = num + " " + num + " " + (num + cantidadSumar);
} else if (valido(num) == -1 && cantidadSumar!=0) {
//    alert("2")
    num = num + cantidadSumar;
    cantidadSumar = str - (num * 3);
    salida = num + " " + num + " " + (num + cantidadSumar);
} else if (valido(num) == -1 && cantidadSumar == 0) {
//    alert("3")
    salida = (num+1) + " " + (num+1) + " " + (num-2);
}

function valido(num) {
    if (num % 3 == 0) {
        return -1//No es válido
    } else return 1;
}

print(salida)

var str = readline();
//var str = 1234;
var numCercano = Math.round(str / 3);
while (divisible(numCercano) == -1) {
    numCercano++;
}
var n1 = n2 = n3 = numCercano;
if (numCercano * 3 != str) {
    var numSuma = str - (n1 + n2 + n3);
    if (divisible(n1 + numSuma) == 1) {
        n1 += numSuma;
    }
}
    function divisible(num) {
        if (num % 3 == 0) {
            return -1//No es válido
        } else return 1;
    }

print(n1 + " " + n2 + " " + n3)

var str = readline();
//var str = 233;
var numCercano = Math.round(str / 3);
while (divisible(numCercano)==-1) {
    numCercano--;
}
var n1 = n2 = n3 = numCercano;
var numSuma = str - (n1+n2+n3);
if (divisible(n1+numSuma)==1) {
    n1 += numSuma;
}

function divisible(num) {
    if (num % 3 == 0) {
        return -1//No es válido
    } else return 1;
}

print(n1 + " " + n2 + " " + n3)

var str = readline();
//var str = 233;
var num = Math.round(str / 3);
//alert(str + " " + num)
var salida;
var cantidadSumar = str - (num * 3);
//alert(cantidadSumar);

if (valido(num)==1 && valido(num+cantidadSumar)==1) {
    salida = num + " " + num + " " + (num + cantidadSumar);
} else if (valido(num) == -1) {
    num = num + cantidadSumar;
    cantidadSumar = str - (num * 3);
    salida = num + " " + num + " " + (num+cantidadSumar);
}

function valido(num) {
    if (num % 3 == 0) {
        return -1//No es válido
    } else return 1;
}

print(salida)

var str = readline();
//var str = 7;
var div = Math.floor(str / 3);
var num = div * 3;
if (str==num) {
    salida = div + " " + div + " " + div;
} else {
    if (str-num==1) {
        salida = (div+1) + " " + div + " " + div;
    } else {
        salida = (div+2) + " " + div + " " + div;
    }
}

print(salida)

var str = readline();
//var str = 10;
var num = Math.round(str / 3);
var salida;

if (valido(num)==1 && num*3==str) {//valido y suma bien
    salida = num + " " + num + " " + num;
} else if (valido(num) == -1 && num * 3 ==str) {//no es valido pero suma bien
    salida = (num+1) + " " + (num+1) + " " + (num-2);
} else if (valido(num) == -1 && num * 3 != str) {//No es valido pero no suma bien
    if ((num*3)+1==str) {
        salida = (num+1) + " " + (num) + " " + (num);
    } else if((num * 3) + 2 == str) {
        salida = (num+2) + " " + (num) + " " + (num);
    }

}

function valido(num) {
    if (num % 3 == 0) {
        return -1//No es válido
    } else return 1;
}

print(salida)

function main() {
  const cin = new Scanner();
  let n = cin.nextInt() - 1;
  let a = 1, b = Math.trunc(n / 2), c = b;
  if (b % 3 === 0) {
    b -= 1;
    c += 1;
  }

  console.log(a, b, c);
}

/*
 *  Api Scanner
 */
class Scanner {
  constructor() {
    this.index = -1;
    this.lines = stdinInput.trim().split('\n'); // eslint-disable-line
  }

  nextLine() {
    this.index += 1;
    return this.lines[this.index].trim();
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray(fn = Number) {
    const array = this.nextLine().split(' ');
    if (fn !== String)
      array.forEach((item, index, arr) => { arr[index] = fn(item); });
    return array;
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', (input) => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

function main() {
  const cin = new Scanner();
  let n = cin.nextInt() - 1;
  let a = 1, b = Math.trunc(n / 2), c = Math.ceil(n / 2);
  if (b % 3 === 0) {
    b -= 1;
    c += 1;
  }

  console.log(a, b, c);
}

/*
 *  Api Scanner
 */
class Scanner {
  constructor() {
    this.index = -1;
    this.lines = stdinInput.trim().split('\n'); // eslint-disable-line
  }

  nextLine() {
    this.index += 1;
    return this.lines[this.index].trim();
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray(fn = Number) {
    const array = this.nextLine().split(' ');
    if (fn !== String)
      array.forEach((item, index, arr) => { arr[index] = fn(item); });
    return array;
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', (input) => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

//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↑入力 ↓出力');
	Main();
});
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 N = nextInt();
	var single = Math.floor(N / 3);
	var second = single + (N % 3);
	myout(single + " " + single + " " + second);
}

var cnt = 0;
process.stdin.addListener("data", function(d) {
	var s = d.toString().trim();
	var x = parseInt(s);
	if( x%2 == 0){
        process.stdout.write(x-2+' 1 1');
    }
	else {
        process.stdout.write(x-3+' 1 2');

        }
            cnt++;
    if(cnt > 0) process.exit();
   // process.exit();
});

var cnt = 0;
process.stdin.addListener("data", function(d) {
	var s = d.toString().trim();
	var x = parseInt(s);
	if( x%2 === 0){
        process.stdout.write(x-2+' 1 1');
    }
	else {
        if(x==3) process.stdout.write('1 1 1');
        else process.stdout.write(x-3+' 1 2');

        }
            cnt++;
    if(cnt > 0) process.exit();
   // process.exit();
});

var cnt = 0;
process.stdin.addListener("data", function(d) {
	var s = d.toString().trim();
	var x = parseInt(s);
	if( x%3 == 0){
        process.stdout.write(x-2+' 1 1');
    }
	else {
        //if(x==3) process.stdout.write('1 1 1');
         process.stdout.write(x-2+' 1 1');

        }
            cnt++;
    if(cnt > 0) process.exit();
   // process.exit();
});


var app = {
    changedHandleCount : 0,
    oldNewHandleMap : {},
    result : [],
    main : function()    {
        this.initialize();
        this.readValues();
        this.sovleResult();
        this.printResult();
    },
    initialize : function()    {
        app.result = [];
        app.oldNewHandleMap = {};
    },
    readValues : function()    {
        app.changedHandleCount = parseInt(readline());
    },
    sovleResult : function()    {
        for(var index = 0; index < app.changedHandleCount; index++)    {
            var oldAndNewHanlde = readline().split(/\s/),
                oldHandle = oldAndNewHanlde[0],
                newHandle = oldAndNewHanlde[1];

            if(app.oldNewHandleMap[oldHandle])  {
                var tempSavedHandle = app.oldNewHandleMap[oldHandle];
                delete app.oldNewHandleMap[oldHandle];
                app.oldNewHandleMap[newHandle] = tempSavedHandle;
            } else  {
                app.oldNewHandleMap[newHandle] = oldHandle;
            }
        }
    },
    printResult : function()    {
        var newHandleList = Object.keys(app.oldNewHandleMap);

        print(newHandleList.length);

        newHandleList.forEach(function(newHandle)    {
            print(app.oldNewHandleMap[newHandle] + ' ' + newHandle);
        });
        // print(this.result);
    }
};

app.main();

var n = readline().trim();

var id = 0;
var olduser = new Array();
var newuser = new Array();
var users = new Array();

for (var i = 0; i < n; i++) {
    var line = readline().split(' ');
    if (users[line[0]] === undefined) {
        users[line[0]] = id;
        olduser[id] = line[0];
        id++;
    }
    var tempid = users[line[0]];
    line[0] = undefined;
    users[line[1]] = tempid;
    newuser[tempid] = line[1];
}
print(id);
for (var i = 0; i < id; i++) {
    print(olduser[i] + ' ' + newuser[i]);
}

var n = +readline();

var users = {};
var seen = {};

var lookup = {};

for(var i = 0; i < n; i++) {
    var req = readline().split(" ");
    var prev = req[0];
    var next = req[1];

    if(!(prev in seen)) {
        users[prev] = next;
        lookup[next] = prev;
    } else {
        var user = lookup[prev];
        users[user] = next;
        lookup[next] = user;
    }
    seen[prev] = true;
    seen[next] = true;
}

print(Object.keys(users).length);
for(var k in users) {
    print(k+" "+users[k]);
}

var n = parseInt(readline());

var map = new Map();

while (n-->0) {
  var line = readline().split(' ');
  if (map.has(line[0])) {
    var old = map.get(line[0]);
    map.set(line[1], old);
    map.delete(line[0]);
  } else {
    map.set(line[1], line[0]);
  }
}

write(map.size+'\n');

map.forEach((value, key) => {
    write(value + ' ' + key + '\n');
  },
  map);

var n = parseInt(readline());

var map = new Map();

while (n-- > 0) {
    var line = readline().split(" ");
    var old_handle = line[0];
    var new_handle = line[1];

    if (map.has(old_handle)) {
        map.set(new_handle, map.get(old_handle));
        map.delete(old_handle);
    } else {
        map.set(new_handle, old_handle);
    }
}

write(map.size + "\n");

map.forEach((v, k) => {
    write(v + " " + k + "\n");
}, map);

"use strict";

var _slicedToArray = (function() {
  function sliceIterator(arr, i) {
    var _arr = [];
    var _n = true;
    var _d = false;
    var _e = undefined;
    try {
      for (
        var _i = arr[Symbol.iterator](), _s;
        !(_n = (_s = _i.next()).done);
        _n = true
      ) {
        _arr.push(_s.value);
        if (i && _arr.length === i) break;
      }
    } catch (err) {
      _d = true;
      _e = err;
    } finally {
      try {
        if (!_n && _i["return"]) _i["return"]();
      } finally {
        if (_d) throw _e;
      }
    }
    return _arr;
  }
  return function(arr, i) {
    if (Array.isArray(arr)) {
      return arr;
    } else if (Symbol.iterator in Object(arr)) {
      return sliceIterator(arr, i);
    } else {
      throw new TypeError(
        "Invalid attempt to destructure non-iterable instance"
      );
    }
  };
})();

var compose = function compose() {
  for (
    var _len = arguments.length, functions = Array(_len), _key = 0;
    _key < _len;
    _key++
  ) {
    functions[_key] = arguments[_key];
  }

  return function() {
    for (
      var _len2 = arguments.length, args = Array(_len2), _key2 = 0;
      _key2 < _len2;
      _key2++
    ) {
      args[_key2] = arguments[_key2];
    }

    return functions.reduce(function(currArgs, func) {
      return func(currArgs);
    }, args);
  };
};

var lineToStringArray = function lineToStringArray(str) {
  return str.split(" ");
};
var lineToNumberArray = function lineToNumberArray(str) {
  return lineToStringArray(str).map(function(num) {
    return parseInt(num, 10);
  });
};

var readNumbersLine = compose(
  readline,
  lineToNumberArray
);
var readStringsLine = compose(
  readline,
  lineToStringArray
);

var _readNumbersLine = readNumbersLine(),
  _readNumbersLine2 = _slicedToArray(_readNumbersLine, 1),
  n = _readNumbersLine2[0];

var map = Object.create(null);
var oldNames = [];

for (var i = 0; i < n; i++) {
  var _readStringsLine = readStringsLine(),
    _readStringsLine2 = _slicedToArray(_readStringsLine, 2),
    oldName = _readStringsLine2[0],
    newName = _readStringsLine2[1];

  map[oldName] = newName;
  oldNames.push(oldName);
}

var res = [];

var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;

try {
  for (
    var _iterator = oldNames[Symbol.iterator](), _step;
    !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
    _iteratorNormalCompletion = true
  ) {
    var _oldName = _step.value;

    var _newName = map[_oldName];
    delete map[_oldName];
    while (map[_newName]) {
      var _oldName3 = _newName;
      _newName = map[_newName];
      delete map[_oldName3];
    }
    if (_newName) res.push([_oldName, _newName]);
  }
} catch (err) {
  _didIteratorError = true;
  _iteratorError = err;
} finally {
  try {
    if (!_iteratorNormalCompletion && _iterator.return) {
      _iterator.return();
    }
  } finally {
    if (_didIteratorError) {
      throw _iteratorError;
    }
  }
}

print(res.length);

var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;

try {
  for (
    var _iterator2 = res[Symbol.iterator](), _step2;
    !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done);
    _iteratorNormalCompletion2 = true
  ) {
    var _ref = _step2.value;

    var _ref2 = _slicedToArray(_ref, 2);

    var _oldName2 = _ref2[0];
    var _newName2 = _ref2[1];

    print(_oldName2, _newName2);
  }
} catch (err) {
  _didIteratorError2 = true;
  _iteratorError2 = err;
} finally {
  try {
    if (!_iteratorNormalCompletion2 && _iterator2.return) {
      _iterator2.return();
    }
  } finally {
    if (_didIteratorError2) {
      throw _iteratorError2;
    }
  }
}

var n = +readline();

var users = {};
var seen = {};

var lookup = {};

for(var i = 0; i < n; i++) {
    var req = readline().split(" ");
    var prev = req[0];
    var next = req[1];

    if(!(prev in seen)) {
        users[prev] = next;
        lookup[next] = prev;
    } else {
        var user = lookup[prev];
        users[user] = next;
        lookup[next] = user;
    }
    seen[prev] = true;
}

print(Object.keys(users).length);
for(var k in users) {
    print(k+" "+users[k]);
}

"use strict";

var _slicedToArray = (function() {
  function sliceIterator(arr, i) {
    var _arr = [];
    var _n = true;
    var _d = false;
    var _e = undefined;
    try {
      for (
        var _i = arr[Symbol.iterator](), _s;
        !(_n = (_s = _i.next()).done);
        _n = true
      ) {
        _arr.push(_s.value);
        if (i && _arr.length === i) break;
      }
    } catch (err) {
      _d = true;
      _e = err;
    } finally {
      try {
        if (!_n && _i["return"]) _i["return"]();
      } finally {
        if (_d) throw _e;
      }
    }
    return _arr;
  }
  return function(arr, i) {
    if (Array.isArray(arr)) {
      return arr;
    } else if (Symbol.iterator in Object(arr)) {
      return sliceIterator(arr, i);
    } else {
      throw new TypeError(
        "Invalid attempt to destructure non-iterable instance"
      );
    }
  };
})();

var compose = function compose() {
  for (
    var _len = arguments.length, functions = Array(_len), _key = 0;
    _key < _len;
    _key++
  ) {
    functions[_key] = arguments[_key];
  }

  return function() {
    for (
      var _len2 = arguments.length, args = Array(_len2), _key2 = 0;
      _key2 < _len2;
      _key2++
    ) {
      args[_key2] = arguments[_key2];
    }

    return functions.reduce(function(currArgs, func) {
      return func(currArgs);
    }, args);
  };
};

var lineToNumberArray = function lineToNumberArray(str) {
  return str.split(" ").map(function(num) {
    return parseInt(num, 10);
  });
};

var readNumbersLine = compose(
  readline,
  lineToNumberArray
);

var _readNumbersLine = readNumbersLine(),
  _readNumbersLine2 = _slicedToArray(_readNumbersLine, 3),
  n = _readNumbersLine2[0],
  t = _readNumbersLine2[1],
  c = _readNumbersLine2[2];

var arr = readNumbersLine();
var lastTOver = -1;
var res = 0;

var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;

try {
  for (
    var _iterator = arr.entries()[Symbol.iterator](), _step;
    !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
    _iteratorNormalCompletion = true
  ) {
    var _ref = _step.value;

    var _ref2 = _slicedToArray(_ref, 2);

    var key = _ref2[0];
    var value = _ref2[1];

    if (value > t) lastTOver = key;
    if (key - lastTOver >= c) res++;
  }
} catch (err) {
  _didIteratorError = true;
  _iteratorError = err;
} finally {
  try {
    if (!_iteratorNormalCompletion && _iterator.return) {
      _iterator.return();
    }
  } finally {
    if (_didIteratorError) {
      throw _iteratorError;
    }
  }
}

print(res);


(function () {
    var line = readline();
    var lines = [line.split(' ')];
    while (line) {
        line = readline();
        if (line) {
            lines.push(line.split(' '));
        }
    }

    var items = lines[1];
    var time = 0;

    function pos(item) {
        return items.indexOf(item);
    }

    for (var i = 2, k = lines.length; i < k; i++) {
        lines[i].forEach(function (item) {
            var itemPos = pos(item);
            items.splice(itemPos, 1);
            items.unshift(item);
            time += itemPos + 1;
        });
    }

    print(time)
})();

(function () {
    var line = readline();
    var lines = [line.split(' ')];
    while (line) {
        line = readline();
        if (line) {
            lines.push(line.split(' '));
        }
    }

    var items = lines[1];
    var time = 0;

    print(items);

    function pos(item) {
        return items.indexOf(item);
    }

    for (var i = 2, k = lines.length; i < k; i++) {
        lines[i].forEach(function (item) {
            var itemPos = pos(item);
            items.splice(itemPos, 1);
            items.unshift(item);
            time += itemPos + 1;
        });
    }

    print(time)
})();


const solve = (n,arr,q)=>{
     let query = [];
     query.push(arr);
     for(let i=1;i<=n;i++){
          let t = query[i-1],obj = {};
          for(let i=0;i<n;i++){
               if(obj[t[i]]) obj[t[i]]++;
               else obj[t[i]] = 1;
          }
          let newA= [];
          for(let i=0;i<n;i++) newA.push(obj[t[i]]);
          query.push(newA);
     }
     for(let i=0;i<q.length;i++){
          if(q[i][1]>=n) console.log(query[n][q[i][0]-1]);
          else console.log(query[q[i][1]][q[i][0]-1]);
     }
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       let arr =  readline().trim().split(" ").map(cur=>parseInt(cur));
       let qn = parseInt(readline());
       let q = [];
       for(let i=0;i<qn;i++){
            q.push(readline().trim().split(" ").map(cur=>parseInt(cur)));
       }
       solve(n,arr,q);
  }
}
main();

"use strict";

//..................................import for reading input...................................//
  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.split("\n");
    main();
  });
  function readline() {
    return inputString[currentLine++];
  }
//............................................................................................//

function main() {
  let t = +(readline());
  while (t--) {
    solution();
  }
}

function solution() {
  let n = +(readline());
  let divineArray = readline().split(' ').map((item) => +item);
  let derivativeArray = transformArray(n, divineArray);

  let allPossibleTransformations = [];
  let stopAt = 0;
  allPossibleTransformations[stopAt++] = divineArray;

  while( divineArray.join(' ') !== derivativeArray.join(' ') ) {
    divineArray = derivativeArray;
    allPossibleTransformations[stopAt++] = divineArray;
    derivativeArray = transformArray(n, divineArray);
  }

  let q = +(readline());
  while (q--) {
    let [x, k] = readline().split(' ').map((item) => +item);
    k = (k > stopAt-1) ? stopAt-1 : k;
    console.log(allPossibleTransformations[k][x-1]);
  }
}

function transformArray(n, divineArray) {
  let counterArray = new Array(n+1).fill(0);
  let newArray = [];
    for (let i = 0; i < n; i++) {
    counterArray[divineArray[i]]++;
  }
  for (let i = 0; i < n; i++) {
    newArray[i] = counterArray[divineArray[i]];
  }

  return newArray;
}

//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 list = nextIntArray(N);
		var map = {};
		map[0] = makeClone(list);
		var max = 0;
		for(var i = 0; i < N; i++){
			var isChange = false;
			var count = getCountMap(list);
			for(var j = 0; j < N; j++){
				if(list[j] != count[list[j]]){
					isChange = true;
				}
				list[j] = count[list[j]];
			}
			map[i + 1] = makeClone(list);
			max++;
			if(!isChange){
				break;
			}
		}
		var Q = nextInt();
		for(var i = 0; i < Q; i++){
			var x = nextInt() - 1;
			var k = Math.min(nextInt(), max);
			myout(map[k][x]);
		}
	}
}


"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var t = +inputs[0];
    for (let i = 0; i < t; i++) {
        var n = +inputs[i * 3 + 1];
        var a = inputs[i * 3 + 2].split(' ').map(v => +v);
        var b = inputs[i * 3 + 3].split(' ').map(v => +v);
        var c = a.map((v, i) => b[i] ? -1e9 : v).sort((a, b) => b - a);
        var d = a.map((v, i) => b[i] ? v : c.shift());
        console.log(d.join(' '));
    }
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}

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

  while (t--) {
    const len = +readLine();
    let arr = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    let indicator = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    let store = [];

    for (let i = 0; i < len; i++) {
      if (indicator[i] === 0) {
        store.push(arr[i]);
        arr[i] = Infinity;
      }
    }

    store.sort((a, b) => b - a);

    for (let i = 0, j = 0; i < len; i++) {
      if (arr[i] === Infinity) {
        arr[i] = store[j];
        j++;
      }
    }

    console.log(arr.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++];
}

function main() {
  const t = parseInt(readline());
  for (var i=0; i<t; i++) {
    const n = parseInt(readline());
    const a = readline().split(" ").map(x => parseInt(x));
    const locked = readline().split(" ").map(x => parseInt(x));

    const arr = a.filter((_, index) => locked[index]==0);
    arr.sort((a,b)=>b-a);

    let pos=0;
    const result = a.map((v, index)=> {
      if (locked[index]==1) return v;
      return arr[pos++];
    });

    console.log(result.join(" "));
  }
}

function solv() {

    var x = parseInt(readline())

    var s = readline().split(' ').map(x => parseInt(x))
    var z = readline().split(' ').map(x => parseInt(x))

    var v = []
    for (var n = 0; n < x; n++) {
        if (z[n] == 0) v.push(s[n])
    }
    v.sort((a, b) => { return b - a })
    var id = 0;
    var res = ''
    for (var n = 0; n < x; n++) {
        if (z[n] == 0) s[n] = v[id++];
        res += s[n] + ' ';
    }
    print(res)
}

var tc = 1;
tc = parseInt(readline());
while (tc--) solv()


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]);
	};
	return tokens;
}

function main() {
	var camelNum = parseInt(readline());
	var spitFrom = {};

	for (var i = 0; i < camelNum; ++i) {
		var info = tokenizeIntegers(readline());
		var camelPos = info[0], spitDistance = info[1];
		var target = camelPos + spitDistance;
		if (spitFrom[camelPos] == target) {
			print("YES");
			return;
		}
		spitFrom[target] = camelPos;
	}
	print("NO");
}

main();

'use strict'

let N = +readline()
let res = 'NO'
let lll

;(function () {
  let ss = []
  while (lll = readline()) {
    lll = lll.split(' ').map(v => parseInt(v))
    let vn = lll[0]
    let vs = lll[1]
    if (!ss[vn]) ss[vn] = []
    let vt = vn + vs
    if (ss[vt] && ~ss[vt].indexOf(vn)) return res = 'YES'
    ss[vn].push(vt)
  }
})()
print(res)

const readline = require('readline');

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

var dict = {}, n = -1;

rl.on('line', (input) => {
    if (n == -1)
        n = parseInt(input);
    else {
        let temp = input.split(' ').map(item=>parseInt(item));
        let pos = temp[0], spit = temp[1];
        dict[pos] = spit;
    }

  }).on('close', function() {
    let ans = "NO";

    for (var current in dict){
        let secondCamel = parseInt(dict[current]) + parseInt(current);
        if (secondCamel in dict && secondCamel + dict[secondCamel] == current) {
            ans = "YES";
            break;
        }
      }

      /*
      for (const [key, value] of Object.entries(dict)) {
        let secondCamel = dict[key] + value;
        if (secondCamel in dict && secondCamel + dict[secondCamel] == key) {
            ans = "YES";
            break;
        }
      }*/
      console.log(ans);
  });

  /*
    5
    2 -10
    3 10
    0 5
    5 -5
    10 1

  */

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

for (var i = 0; i < n; i++) {
	var input = readline().split(' ').map(function(a){return parseFloat(a)});
	var position = input[0];
	var plevok_position = input[0] + input[1];
	verbluds[position] = plevok_position;
}

function is_odin_v_odnogo(arr) {
	for (var a in arr) {
		if (a == arr[arr[a]]) {
			return 'YES';
		}
	}
	return 'NO';
}

print(is_odin_v_odnogo(verbluds));

const readline = require('readline');

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

var n = -1;
var location = [];
var spit = [];

rl.on('line', function (input) {
    // myArr = input.split(' ').map(item => {return parseInt(item);});
    if (n == -1)
        n = parseInt(input);
    else {

        if (location.length < n - 1) {
            //location.push(parseInt(input));
            var temp = input.split(' ').map(item=> {return parseInt(item);});
            location.push(temp[0]);
            spit.push(temp[1]);
        }
        else {

            var temp = input.split(' ').map(item=> {return parseInt(item);});
            location.push(temp[0]);
            spit.push(temp[1]);
        //****************************************** DO IT HERE*/
            var ans= "NO";
            for (let i = 0; i < n; i++) {
                var indexOfSecondCam = location.indexOf(location[i] + spit[i]);
                if (indexOfSecondCam != -1 && location[indexOfSecondCam] + spit[indexOfSecondCam]==location[i]) {
                    ans = "YES";
                    break;
                }

            }
            console.log(ans);

            rl.close();
            /*************************************** */
        }

    }

})

const readline = require('readline');

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

//var dict = {}, n = -1;
var myMap = new Map(), n = -1;

rl.on('line', (input) => {
    if (n == -1)
        n = parseInt(input);
    else {
        let temp = input.split(' ').map(item=>parseInt(item));

        let pos = temp[0], spit = temp[1];
       // dict[pos] = spit;

       myMap.set(pos, spit) ;
    }

  }).on('close', function() {
    let ans = "NO";
    /*
    for (var current in dict){
        let secondCamel = parseInt(dict[current]) + parseInt(current);
        if (secondCamel in dict && secondCamel + dict[secondCamel] == current) {
            ans = "YES";
            break;
        }
      }
      */
      /*
      for (const [key, value] of Object.entries(dict)) {
        let secondCamel = dict[key] + value;
        if (secondCamel in dict && secondCamel + dict[secondCamel] == key) {
            ans = "YES";
            break;
        }
      }*/

      for(let [key, value] of myMap){
         let secondCamel = key + value;
         if (myMap.has(secondCamel) && myMap.get(secondCamel) + secondCamel == key) {
             ans = "YES";
             break;
         }
      }
      console.log(ans);
  });

  /*
    5
    2 -10
    3 10
    0 5
    5 -5
    10 1

  */

const readline = require('readline');

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

var dict = {}, n = -1;

rl.on('line', (input) => {
    if (n == -1)
        n = parseInt(input);
    else {
        let temp = input.split(' ');
        let pos = temp[0], spit = temp[1];
        dict[pos] = spit;
    }

  }).on('close', function() {
    let ans = "NO";

    for (var current in dict){
        let secondCamel = parseInt(dict[current]) + parseInt(current);
        if (secondCamel in dict && secondCamel + dict[secondCamel] == current) {
            ans = "YES";
            break;
        }
      }

      console.log(ans);
  });