'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 input() {
  return inputString[currentLine++];
}

function main() {
  let tc = parseInt(input());
  while(tc--){
    const [n, k] = input().split(' ').map(Number);
    const a = input().split(' ').map(Number);
    // 1
    a.sort((a, b) => {
      if(a < b) return -1;
      else return 1;
    });
    // 2
    let last = a[0];
    let cnt = 1;
    const aa = [];
    for(let i = 1; i < n; i++){
      if(last !== a[i]){
        if(cnt >= k) aa.push(last);
        cnt = 1;
        last = a[i];
      }
      else{
        cnt++;
      }
    }
    if(cnt >= k) aa.push(last);
    if(!aa.length){
      console.log(-1);
      continue;
    }
    // 3
    const aaa = [];
    last = aa[0];
    let tmp = [aa[0]];
    for(let i = 1; i < aa.length; i++){
      if(aa[i]-1 === last){
        tmp.push(aa[i]);
      }
      else{
        aaa.push(JSON.parse(JSON.stringify(tmp)));
        tmp = [aa[i]];
      }
      last = aa[i];
    }
    if(tmp.length) aaa.push(tmp);
    // 4
    const aaaa = [];
    for(let i = 0; i < aaa.length; i++){
      let s = aaa[i].length;
      let l = aaa[i][0];
      let r = aaa[i][s-1];
      aaaa.push([r-l, l, r]);
    }
    aaaa.sort((a, b) => {
      if(a[0] > b[0]) return -1;
      else return 1;
    });
    console.log(aaaa[0][1], aaaa[0][2]);
  }
}

'use strict';
// HEADER:
const print = console.log;
let IS_MULTITEST, testN;
const pcalc = testN=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    pa(res);
  } else if (Number.isFinite(res) || typeof res=='string'){
    print(res);
  }
};

const main = ()=>{
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(T);
  } else
   pcalc();
};

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;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`Test #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

// SOLUTION:
IS_MULTITEST = 1;

const calc = ()=>{
  // READING:
  let [n, k] = ra();
  let A = ra();
  LT({n, k, A});
  // PROCESSING:
  A.sort((a, b)=>a-b);
  let cnt = {};
  for (let i=0; i<n; i++){
    cnt[A[i]] = (cnt[A[i]]||0)+1
  }
  L(cnt)
  let uniq = Object.keys(cnt).map(u=>+u);
  let max = -1;
  let ansL, ansR;
  let l=0, r = 0;
  while (l<uniq.length){
    r = l;
    while (r<uniq.length && cnt[uniq[r]]>=k && (r==l || uniq[r]-1==uniq[r-1])){
      r++;
    }
    if (r>l && uniq[r-1]-uniq[l]>max){
      max = uniq[r-1]-uniq[l];
      ansL = uniq[l];
      ansR = uniq[r-1];
    }
    if (l==r)
      l = r+1;
    else
      l = r;
  }
  if (max==-1)
    return -1;
  return [ansL, ansR]
};

'use strict';

var readline = require('readline');

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

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

function solve(n, k, a) {
  const map = new Map();
  for (let num of a) {
    var _map$get;
    map.set(num, ((_map$get = map.get(num)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);
  }
  let nums = [];
  for (let [num, count] of map) {
    if (count >= k) nums.push(num);
  }
  nums.sort((a, b) => a - b);
  let l = 0,
      r = -1;
  for (let i = 0; i < nums.length;) {
    let j = i;
    while (nums[j + 1] === nums[j] + 1) {
      j++;
    }
    if (nums[j] - nums[i] > r - l) {
      l = nums[i];
      r = nums[j];
    }
    i = j + 1;
  }
  if (r === -1) return -1;
  return `${l} ${r}`;
}

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

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

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var K = nextInt();
		var list = nextIntArray(N);
		var map = getCountMap(list);
		var key = Object.keys(map);
		key.sort(function(a,b){
			return a - b;
		});
		var ok = false;
		for(var i = 0; i < key.length; i++){
			if(map[key[i]] >= K){
				ok = true;
				break;
			}
		}
		if(!ok){
			myout(-1);
			continue;
		}
		var output = "";
		var size = -1;
		var L = 0;
		var R = 0;
		var lastNo = myconv(key[0], 1);
		while(L < key.length && R < key.length){
			var ok = true;
			if(L != R){
				if(lastNo + 1 != key[R]){
					ok = false;
				}
			}
			if(map[key[R]] != null && map[key[R]] >= K && ok){
				lastNo = myconv(key[R], 1);
				R++;
				continue;
			}else{

				if(R - L + 1 > size){
					size = R - L + 1;
					output = key[L] + " " + key[R - 1];
				}
				if(L == R){
					R++;
				}
				L = R;
			}
		}
		if(R - L + 1 > size){
			size = R - L + 1;
			output = key[L] + " " + key[R - 1];
		}
		myout(output);
	}
}

const readline = require('readline')

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

function solve(n, k, arr) {
    const map = arr.reduce((o, x) => {
        o[x] = (o[x] || 0) + 1
        return o
    }, {})
    let max = -1
    let p, c
    let l, r
    Object.keys(map)
        .map(Number)
        .sort((a, b) => a - b)
        .forEach(x => {
            if (map[x] >= k) {
                if (p + 1 === x) {
                    c++
                } else {
                    c = 1
                }
                p = x
                if (c > max) {
                    max = c
                    l = x - max + 1
                    r = x
                }
            } else {
                p = -1
            }
        })
    return max < 0 ? -1 : l + ' ' + r
}

//import { readline, print } from '@ip-algorithmics/codeforces-io';
var t = +readline();
while (t--) {
    var _a = readline().split(' ').map(function (v) { return +v; }), n = _a[0], k = _a[1];
    var a = readline().split(' ').map(function (v) { return +v; });
    a.sort(function (a, b) { return a - b; });
    var m = new Map();
    for (var i = 0; i < n; i++) {
        if (m.has(a[i])) {
            m.set(a[i], m.get(a[i]) + 1);
        }
        else {
            m.set(a[i], 1);
        }
    }
    var b = (Array.from(m.entries()));
    n = b.length;
    var maxL = 0, maxR = 0;
    var max = 0;
    var l = 0;
    var r = 0;
    var prev = b[0][0] - 1;
    while (l < n) {
        while (b[r][1] >= k && b[r][0] === prev + 1) {
            prev = b[r][0];
            r++;
            if (r === n)
                break;
        }
        if (r - l > max) {
            maxR = b[r - 1][0];
            maxL = b[l][0];
            max = r - l;
        }
        if (r === n)
            break;
        l = b[r][1] >= k ? r : r + 1;
        r = l;
        if (r === n)
            break;
        prev = b[r][0] - 1;
    }
    print(max ? "".concat(maxL, " ").concat(maxR) : -1);
}

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

function Main(){
    // test case in nodeJs
	var t = nextInt();
	while(hasNext()){
		solve();
	}
}

function solve() {
    const n = nextInt();
    const k = nextInt();
    const arr = nextIntArray(n);

    const map = new Map();
    let min = Infinity;
    let max = 0;

    for (let i = 0; i < arr.length; i++) {
        if (map.get(arr[i])) {
            map.set(arr[i], map.get(arr[i]) + 1)
        } else {
            map.set(arr[i], 1);
        }
        min = Math.min(min, arr[i]);
        max = Math.max(max, arr[i])
    }

    // console.log({min, max, map, k})
    let left = min, right = min;
    const ans = [0, 0];
    const keys = [...map.keys()].sort((a, b) => a - b);
    // console.log(keys)
    let index = 0;
    while (right <= max + 1) {
        // console.log({left, right}, keys[index], keys)
        if (map.get(right) >= k){
            // console.log("expand");
            index++;
            right++;
        } else {
            // console.log("sink")
            // console.log(left, right)
            let maxRange = ans[1] - ans[0] + 1;
            if (maxRange <= right -1  - left + 1) {
                ans[0] = left;
                ans[1] = right - 1;
            }
            if (map.get(keys[index]) >= k) {
                left = keys[index];
            } else {
                left = keys[++index];
            }
            right = left;
            // console.log(ans)
        }
    }

    // console.log(ans)

    if (ans[0] === 0 && ans[1] === 0) {
        myout(-1);
    } else {
        myout(`${ans[0]} ${ans[1]}`);
    }
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let [n, k] = iInpArr();
    let arr = iInpArr();
    let obj = {};
    for (let i = 0; i < n; i++) {
      if (obj[arr[i]] === undefined) obj[arr[i]] = 1;
      else obj[arr[i]]++;
    }
    let keys = Object.keys(obj);
    let res = [];
    for (let i of keys) {
      if (obj[i] >= k) res.push(parseInt(i));
    }
    if (res.length === 0) console.log(-1);
    else if (res.length === 1) console.log(res[0] + " " + res[0]);
    else {
      res.sort((a, b) => a - b);
      let j = 1,
        i = 0,
        max = 0,
        ans;
      while (j < res.length) {
        let y = res[j] - res[i] + 1;
        if (y === j - i + 1) {
          if (max <= res[j] - res[i]) {
            max = res[j] - res[i];
            ans = [res[i], res[j]];
          }
          j++;
        } else i++;
      }
      console.log(ans.join(" "));
    }
  }
};
solve();

'use strict';
const readline = require('readline');
const util = require('util');
const lineReader = readline.createInterface({
    input: process.stdin,
});
let inputPos = 0;
const inputWords = [];
lineReader.on('line', (line) => {
    inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));
});
lineReader.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(inputWords[inputPos++]));
}
function nextStr() {
    return inputWords[inputPos++];
}
function af(l) {
    return Array.from({ length: l });
}
const INIT = -1;
const INF = Infinity;
let n;
let k;
let a;
function solve() {
    let b = [];
    a.sort((x, y) => x - y);
    let last = a[0];
    let cnt = 1;
    for (let i = 1; i < n; i++) {
        if (a[i] == last) {
            cnt++;
        }
        else {
            if (cnt >= k) {
                b.push(last);
            }
            cnt = 1;
            last = a[i];
        }
    }
    if (cnt >= k) {
        b.push(last);
    }
    let m = b.length;
    if (m == 0) {
        return false;
    }
    let l = 0;
    let best = 1;
    let lo = b[0];
    let hi = b[0];
    while (l < m) {
        let r = l + 1;
        while (r < m && r - l == b[r] - b[l]) {
            if (best < r - l + 1) {
                best = r - l + 1;
                lo = b[l];
                hi = b[r];
            }
            r++;
        }
        l = r;
    }
    printf("%d %d\n", lo, hi);
    return true;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        k = nextInt();
        a = af(n);
        for (let i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        if (!solve()) {
            printf("%d\n", INIT);
        }
    }
}

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

function Main(){
    // test case in nodeJs
	var t = nextInt();
	while(hasNext()){
		solve();
	}
}

function solve() {
    const n = nextInt();
    const k = nextInt();
    const arr = nextIntArray(n);

    const map = new Map();
    let min = Infinity;
    let max = 0;

    for (let i = 0; i < arr.length; i++) {
        if (map.get(arr[i])) {
            map.set(arr[i], map.get(arr[i]) + 1)
        } else {
            map.set(arr[i], 1);
        }
        min = Math.min(min, arr[i]);
        max = Math.max(max, arr[i])
    }

    // console.log({min, max, map, k})
    let left = min, right = min;
    const ans = [0, 0];
    const keys = [...map.keys()].sort((a, b) => a - b);
    // console.log(keys)
    let index = 0;
    while (right <= max + 1) {
        if (map.get(right) >= k){
            // console.log("expand");
            index++;
            right++;
        } else {
            // console.log("sink")
            // console.log(left, right)
            let maxRange = ans[1] - ans[0] + 1;
            if (maxRange <= right -1  - left + 1) {
                ans[0] = left;
                ans[1] = right - 1;
            }
            left = keys[++index];
            right = left;
            // console.log(ans)
        }
    }

    // console.log(ans)

    if (ans[0] === 0 && ans[1] === 0) {
        myout(-1);
    } else {
        myout(`${ans[0]} ${ans[1]}`);
    }
}

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

function Main(){
    // test case in nodeJs
	var t = nextInt();
	while(hasNext()){
		solve();
	}
}

function solve() {
    const n = nextInt();
    const k = nextInt();
    const arr = nextIntArray(n);

    const map = new Map();
    let min = Infinity;
    let max = 0;

    for (let i = 0; i < arr.length; i++) {
        if (map.get(arr[i])) {
            map.set(arr[i], map.get(arr[i]) + 1)
        } else {
            map.set(arr[i], 1);
        }
        min = Math.min(min, arr[i]);
        max = Math.max(max, arr[i])
    }

    // console.log({min, max, map, k})
    let left = min, right = min;
    const ans = [0, 0];
    const keys = [...map.keys()].sort((a, b) => a - b);
    // console.log(keys)
    let index = 0;
    while (right <= max + 1) {
        if (map.get(right) >= k){
            // console.log("expand");
            index++;
            right++;
        } else {
            // console.log("sink")
            // console.log(left, right)
            let maxRange = ans[1] - ans[0] + 1;
            if (maxRange <= right -1  - left + 1) {
                ans[0] = left;
                ans[1] = right - 1;
            }
            left = keys[index++];
            right = left;
            // console.log(ans)
        }
    }

    // console.log(ans)

    if (ans[0] === 0 && ans[1] === 0) {
        myout(-1);
    } else {
        myout(`${ans[0]} ${ans[1]}`);
    }
}

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

function Main(){
    // test case in nodeJs
	var t = nextInt();
	while(hasNext()){
		solve();
	}
}

function solve() {
    const n = nextInt();
    const k = nextInt();
    const arr = nextIntArray(n);

    const map = new Map();
    let min = Infinity;
    let max = 0;

    for (let i = 0; i < arr.length; i++) {
        if (map.get(arr[i])) {
            map.set(arr[i], map.get(arr[i]) + 1)
        } else {
            map.set(arr[i], 1);
        }
        min = Math.min(min, arr[i]);
        max = Math.max(max, arr[i])
    }

    // console.log({min, max, map, k})
    let left = min, right = min;
    const ans = [0, 0];
    const keys = [...map.keys()].sort((a, b) => b - a);
    let pointer = 0;
    while (right <= max + 1) {
        if (map.get(right) >= k){
            // console.log("expand");
            pointer++;
            right++;
        } else {
            // console.log("sink")
            // console.log(left, right)
            let maxRange = ans[1] - ans[0] + 1;
            if (maxRange <= right -1  - left + 1) {
                ans[0] = left;
                ans[1] = right - 1;
            }
            left = keys[pointer++];
            right = left;
            // console.log(ans)
        }
    }

    // console.log(ans)

    if (ans[0] === 0 && ans[1] === 0) {
        myout(-1);
    } else {
        myout(`${ans[0]} ${ans[1]}`);
    }
}

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

function Main(){
    // test case in nodeJs
	var t = nextInt();
	while(hasNext()){
		solve();
	}
}

function solve() {
    const n = nextInt();
    const k = nextInt();
    const arr = nextIntArray(n);

    const map = new Map();
    let min = Infinity;
    let max = 0;

    for (let i = 0; i < arr.length; i++) {
        if (map.get(arr[i])) {
            map.set(arr[i], map.get(arr[i]) + 1)
        } else {
            map.set(arr[i], 1);
        }
        min = Math.min(min, arr[i]);
        max = Math.max(max, arr[i])
    }

    // console.log({min, max, map, k})
    let left = min, right = min;
    const ans = [0, 0];

    while (right <= max + 1) {
        if (map.get(right) >= k){
            // console.log("expand")
            right++;
        } else {
            // console.log("sink")
            // console.log(left, right)
            let maxRange = ans[1] - ans[0] + 1;
            if (maxRange < right - left) {
                ans[0] = left;
                ans[1] = right - 1;
            }
            left = right + 1;
            right++;
        }
    }

    // console.log(ans)

    if (ans[0] === 0 && ans[1] === 0) {
        myout(-1);
    } else {
        myout(`${ans[0]} ${ans[1]}`);
    }
}

const solve = (arr, n, k) => {
  let obj = {},narr = [];
  for (let i = 0; i < n; i++) {
    if (!obj[arr[i]]) {
         obj[arr[i]] = 1;
         narr.push(arr[i]);
    }
    else obj[arr[i]]++;
  }
  let max = -Infinity,l,r;
  for(let i=0;i<narr.length;i++){
       for(let j=i;j<narr.length;j++){
            if((obj[narr[i]]>=k)&&(obj[narr[j]]>=k)){
                 if(max<Math.abs(narr[i]-narr[j])){
                      max = Math.abs(narr[i]-narr[j]);
                      if(narr[i]<narr[j]) {
                           l = narr[i];
                           r = narr[j];
                      }
                      else{
                            l = narr[j];
                           r = narr[i];
                      }
                 }
            }
       }
  }
  if (max === -Infinity) return -1;
  return l+" "+r;
};
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, k] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    console.log(solve(arr,n,k));
  }
}
main();

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

function main() {
  let tc = parseInt(input());
  while(tc--){
    const [n, k] = input().split(' ').map(Number);
    const a = input().split(' ').map(Number);
    // 1
    a.sort((a, b) => {
      if(a < b) return -1;
      else return 1;
    });
    // 2
    let last = a[0];
    let cnt = 1;
    const aa = [];
    for(let i = 1; i < n; i++){
      if(last !== a[i]){
        if(cnt >= k) aa.push(last);
        cnt = 1;
        last = a[i];
      }
      else{
        cnt++;
      }
    }
    if(cnt >= k) aa.push(last);
    if(!aa.length){
      continue;
    }
    // 3
    const aaa = [];
    last = aa[0];
    let tmp = [aa[0]];
    for(let i = 1; i < aa.length; i++){
      if(aa[i]-1 === last){
        tmp.push(aa[i]);
      }
      else{
        aaa.push(JSON.parse(JSON.stringify(tmp)));
        tmp = [aa[i]];
      }
      last = aa[i];
    }
    if(tmp.length) aaa.push(tmp);
    // 4
    const aaaa = [];
    for(let i = 0; i < aaa.length; i++){
      let s = aaa[i].length;
      let l = aaa[i][0];
      let r = aaa[i][s-1];
      aaaa.push([r-l, l, r]);
    }
    aaaa.sort((a, b) => {
      if(a[0] > b[0]) return -1;
      else return 1;
    });
    console.log(aaaa[0][1], aaaa[0][2]);
  }
}

'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 input() {
  return inputString[currentLine++];
}

function main() {
  let tc = parseInt(input());
  while(tc--){
    const [n, k] = input().split(' ').map(Number);
    const a = input().split(' ').map(Number);
    // 1
    a.sort();
    // 2
    let last = a[0];
    let cnt = 1;
    const aa = [];
    for(let i = 1; i < n; i++){
      if(last !== a[i]){
        if(cnt >= k) aa.push(last);
        cnt = 1;
        last = a[i];
      }
      else{
        cnt++;
      }
    }
    if(cnt >= k) aa.push(last);
    if(!aa.length){
      console.log(-1);
      continue;
    }
    // 3
    const aaa = [];
    last = aa[0];
    let tmp = [aa[0]];
    for(let i = 1; i < aa.length; i++){
      if(aa[i]-1 === last){
        tmp.push(aa[i]);
      }
      else{
        aaa.push(JSON.parse(JSON.stringify(tmp)));
        tmp = [aa[i]];
      }
      last = aa[i];
    }
    if(tmp.length) aaa.push(tmp);
    // 4
    let aaaa = [];
    for(let i = 0; i < aaa.length; i++){
      let s = aaa[i].length;
      let l = aaa[i][0];
      let r = aaa[i][s-1];
      aaaa.push([r-l, l, r]);
    }
    aaaa.sort((a, b) => {
      if(a[0] > b[0]) return -1;
      else return 1;
    });
    console.log(aaaa[0][1], aaaa[0][2]);
  }
}

'use strict';
const readline = require('readline');
const util = require('util');
const lineReader = readline.createInterface({
    input: process.stdin,
});
let inputPos = 0;
const inputWords = [];
lineReader.on('line', (line) => {
    inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));
});
lineReader.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(inputWords[inputPos++]));
}
function nextStr() {
    return inputWords[inputPos++];
}
function af(l) {
    return Array.from({ length: l });
}
const INIT = -1;
const INF = Infinity;
let n;
let k;
let a;
function solve() {
    let b = [];
    a.sort((x, y) => x - y);
    let last = a[0];
    let cnt = 1;
    for (let i = 1; i < n; i++) {
        if (a[i] == last) {
            cnt++;
        }
        else {
            if (cnt >= k) {
                b.push(last);
            }
            cnt = 1;
            last = a[i];
        }
    }
    if (cnt >= k) {
        b.push(last);
    }
    let m = b.length;
    if (m == 0) {
        return false;
    }
    let l = 0;
    let best = 0;
    let lo = INF;
    let hi = INF;
    while (l < m) {
        let r = l + 1;
        while (r < m && r - l == b[r] - b[l]) {
            if (best < r - l) {
                best = r - l;
                lo = b[l];
                hi = b[r];
            }
            r++;
        }
        l = r;
    }
    printf("%d %d\n", lo, hi);
    return true;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        k = nextInt();
        a = af(n);
        for (let i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        if (!solve()) {
            printf("%d\n", INIT);
        }
    }
}

'use strict';
// HEADER:
const print = console.log;
let IS_MULTITEST, testN;
const pcalc = testN=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    pa(res);
  } else if (Number.isFinite(res) || typeof res=='string'){
    print(res);
  }
};

const main = ()=>{
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(T);
  } else
   pcalc();
};

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;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`Test #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

// SOLUTION:
IS_MULTITEST = 1;

const calc = ()=>{
  // READING:
  let [n, k] = ra();
  let A = ra();
  LT({n, k, A});
  // PROCESSING:
  A.sort((a, b)=>a-b);
  let cnt = {};
  for (let i=0; i<n; i++){
    cnt[A[i]] = (cnt[A[i]]||0)+1
  }
  L(cnt)
  let uniq = Object.keys(cnt).map(u=>+u);
  let max = -1;
  let ansL, ansR;
  let l=0, r = 0;
  while (l<uniq.length){
    r = l;
    while (r<uniq.length && cnt[uniq[r]]>=k && (r==l || uniq[r]-1==uniq[r-1])){
      r++;
    }
    if (r>l && uniq[r-1]-uniq[l]>max){
      max = uniq[r-1]-uniq[l];
      ansL = uniq[l];
      ansR = uniq[r-1];
    }
    l = r + 1;
  }
  if (max==-1)
    return -1;
  return [ansL, ansR]
};

//import { readline, print } from '@ip-algorithmics/codeforces-io';
var t = +readline();
while (t--) {
    var _a = readline().split(' ').map(function (v) { return +v; }), n = _a[0], k = _a[1];
    var a = readline().split(' ').map(function (v) { return +v; });
    a.sort();
    var m = new Map();
    for (var i = 0; i < n; i++) {
        if (m.has(a[i])) {
            m.set(a[i], m.get(a[i]) + 1);
        }
        else {
            m.set(a[i], 1);
        }
    }
    var b = (Array.from(m.entries()));
    n = b.length;
    var maxL = 0, maxR = 0;
    var max = 0;
    var l = 0;
    var r = 0;
    var prev = b[0][0] - 1;
    while (l < n) {
        while (b[r][1] >= k && b[r][0] === prev + 1) {
            prev = b[r][0];
            r++;
            if (r === n)
                break;
        }
        if (r - l > max) {
            maxR = b[r - 1][0];
            maxL = b[l][0];
            max = r - l;
        }
        if (r === n)
            break;
        l = b[r][1] >= k ? r : r + 1;
        r = l;
        if (r === n)
            break;
        prev = b[r][0] - 1;
    }
    print(max ? "".concat(maxL, " ").concat(maxR) : -1);
}


function getInt(num){
        return parseInt(num, 10)
    }

var line = readline().split(' ').map(getInt);

getXY.apply(undefined, line)

function getXY(zerous, ones, k){

    if(k === 0){
        print('YES');
        var rest = getRest(zerous, ones).join('');

        print(rest);
        print(rest);
        return;
    }
    if(zerous === 0 || ones === 0){
        print('NO')
        return;
    }

    if(zerous + ones - 2 < k){
        print('NO')
        return;
    }

    if(ones === 1){
        print('NO')
        return;
    }

    getPatt(zerous, ones, k)

}

function addChars(arr, ch, n){
    for(var i = 0; i < n; i++){
        arr.push(ch);
    }
}

function getEndPatt(zerous, ones, k){
    var pattX = [];
    var pattY = [];
    var z = zerous;
    var o = ones;
    var newK = k;

    var zs = Math.min(k, zerous);

    //pattX.push(1);
    addChars(pattX, 0, zs)

    addChars(pattY, 0, zs-1)
    pattY.push(1);

    //o--;
    z = z - zs;
    newK = newK - zs;
    return [pattX, pattY, z, o, newK]
}
function getPatt(zerous, ones, k){

    var x = [1];
    var y = [1];
    ones--;

    var pattEnd = getEndPatt(zerous, ones, k);

    zerous = pattEnd[2];
    ones = pattEnd[3];
    k = pattEnd[4];

    var pattSt = getStartPatt(zerous, ones, k);

    zerous = pattSt[2];
    ones = pattSt[3];
    k = pattSt[4];

    var rest = getRest(zerous, ones);

    x = x.concat(pattSt[0]);
    y = y.concat(pattSt[1]);
    x = x.concat(pattEnd[0]);
    y = y.concat(pattEnd[1]);
    x = x.concat(rest);
    y = y.concat(rest);

    print('YES');

    print(x.join(''))

    print(y.join(''))

}
function getStartPatt(zerous, ones, k){
    var pattX = [];
    var pattY = [];
    var z = zerous;
    var o = ones;
    var newK = k;

    pattX.push(1);
    pattY.push(0);
    o--;

    var os = Math.min(k, o);

    addChars(pattX, 1, os);
    addChars(pattY, 1, os);

    o = o - os;

    newK = k - os;

    return [pattX, pattY, z, o, newK]
}

function getRest(zerous, ones){
    var rest = [];
    addChars(rest, 1, ones)
    addChars(rest, 0, zerous)
    return rest;
}

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var [a, b, k] = lines[0].trim().split(' ').map(Number)
    console.log(solve(a, b, k));
});

function solve(a, b, k) {
    if (k === 0) {
        const s = Array(b).fill(1).join('') + Array(a).fill(0).join('')
        return ['Yes', s, s].join('\n')
    }
    if (a < 1 || b < 2 || a + b < k + 2) return 'No'

    // 1, ?, i, k - 1, j
    const x = []
    const y = []
    const j = a + b - 1
    const i = j - k
    let zero = a - 1 // reserved for i and j
    let one = b - 1
    for (let p = 0; p < a + b; p++) {
        if (!p) {
            x[p] = y[p] = 1
            one--
        } else if (p === i) {
            x[p] = 1
            y[p] = 0
        } else if (p === j) {
            x[p] = 0
            y[p] = 1
        } else {
            if (zero) {
                x[p] = y[p] = 0
                zero--
            } else {
                x[p] = y[p] = 1
                one--
            }
        }
    }
    return ['Yes', x.join(''), y.join('')].join('\n')
}

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var [a, b, k] = lines[0].trim().split(' ').map(Number)
    console.log(solve(a, b, k));
});

function solve(a, b, k) {
    if (a < 1 || b < 2 || a + b < k + 2) return 'No'

    // 1, ?, i, k - 1, j
    const x = []
    const y = []
    const j = a + b - 1
    const i = j - k
    let zero = a - 1 // reserved for i and j
    let one = b - 1
    for (let p = 0; p < a + b; p++) {
        if (!p) {
            x[p] = y[p] = 1
            one--
        } else if (p === i) {
            x[p] = 1
            y[p] = 0
        } else if (p === j) {
            x[p] = 0
            y[p] = 1
        } else {
            if (zero) {
                x[p] = y[p] = 0
                zero--
            } else {
                x[p] = y[p] = 1
                one--
            }
        }
    }
    return ['Yes', x.join(''), y.join('')].join('\n')
}

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var [a, b, k] = lines[0].trim().split(' ').map(Number)
    console.log(solve(a, b, k));
});

function solve(a, b, k) {
    if (a < 1 || b < 2 || a + b < k + 2) return 'No'

    // 1, ?, i, k - 1, j
    const x = []
    const y = []
    const j = a + b - 1
    const i = j - k
    let zero = a - 1 // reserved for i and j
    let one = b - 1
    for (let p = 0; p < a + b; p++) {
        if (!p) {
            x[p] = y[p] = 1
            zero--
            one--
        } else if (p === i) {
            x[p] = 1
            y[p] = 0
        } else if (p === j) {
            x[p] = 0
            y[p] = 1
        } else {
            if (zero) {
                x[p] = y[p] = 0
                zero--
            } else {
                x[p] = y[p] = 1
                one--
            }
        }
    }
    return ['Yes', x.join(''), y.join('')].join('\n')
}

function getInt(num){
        return parseInt(num, 10)
    }

var line = readline().split(' ').map(getInt);

getXY.apply(undefined, line)

function getXY(zerous, ones, k){

    if(k === 0){
        print('YES');
        var rest = getRest(zerous, ones).join('');

        print(rest);
        print(rest);
        return;
    }

    if(zerous + ones - 2 < k){
        print('NO')
        return;
    }

    if(ones === 1){
        print('NO')
        return;
    }

    getPatt(zerous, ones, k)

}

function addChars(arr, ch, n){
    for(var i = 0; i < n; i++){
        arr.push(ch);
    }
}

function getEndPatt(zerous, ones, k){
    var pattX = [];
    var pattY = [];
    var z = zerous;
    var o = ones;
    var newK = k;

    var zs = Math.min(k, zerous);

    //pattX.push(1);
    addChars(pattX, 0, zs)

    addChars(pattY, 0, zs-1)
    pattY.push(1);

    //o--;
    z = z - zs;
    newK = newK - zs;
    return [pattX, pattY, z, o, newK]
}
function getPatt(zerous, ones, k){

    var x = [1];
    var y = [1];
    ones--;

    var pattEnd = getEndPatt(zerous, ones, k);

    zerous = pattEnd[2];
    ones = pattEnd[3];
    k = pattEnd[4];

    var pattSt = getStartPatt(zerous, ones, k);

    zerous = pattSt[2];
    ones = pattSt[3];
    k = pattSt[4];

    var rest = getRest(zerous, ones);

    x = x.concat(pattSt[0]);
    y = y.concat(pattSt[1]);
    x = x.concat(pattEnd[0]);
    y = y.concat(pattEnd[1]);
    x = x.concat(rest);
    y = y.concat(rest);

    print('YES');

    print(x.join(''))

    print(y.join(''))

}
function getStartPatt(zerous, ones, k){
    var pattX = [];
    var pattY = [];
    var z = zerous;
    var o = ones;
    var newK = k;

    pattX.push(1);
    pattY.push(0);
    o--;

    var os = Math.min(k, o);

    addChars(pattX, 1, os);
    addChars(pattY, 1, os);

    o = o - os;

    newK = k - os;

    return [pattX, pattY, z, o, newK]
}

function getRest(zerous, ones){
    var rest = [];
    addChars(rest, 1, ones)
    addChars(rest, 0, zerous)
    return rest;
}

function getInt(num){
        return parseInt(num, 10)
    }

var line = readline().split(' ').map(getInt);

getXY.apply(undefined, line)

function getXY(zerous, ones, k){

    if(k === 0){
        print('YES');
        var rest = getRest(zerous, ones).join('');

        print(rest);
        print(rest);
        return;
    }

    if(zerous + ones - 2 < k){
        print('NO')
        return;
    }

    if(ones === 1){
        print('NO')
        return;
    }

    getPatt(zerous, ones, k)

}

function addChars(arr, ch, n){
    for(var i = 0; i < n; i++){
        arr.push(ch);
    }
}

function getEndPatt(zerous, ones, k){
    var pattX = [];
    var pattY = [];
    var z = zerous;
    var o = ones;
    var newK = k;

    var zs = Math.min(k, zerous);

    addChars(pattX, 0, zs)

    addChars(pattY, 0, zs-1)
    pattY.push(1);

    o--;
    z = z - zs;
    newK = newK - zs;
    return [pattX, pattY, z, o, newK]
}
function getPatt(zerous, ones, k){

    var x = [1];
    var y = [1];
    ones--;
    var pattSt = getStartPatt(zerous, ones, k);
    x = x.concat(pattSt[0]);
    y = y.concat(pattSt[1]);

    zerous = pattSt[2];
    ones = pattSt[3];
    k = pattSt[4];

    var pattEnd = getEndPatt(zerous, ones, k);
    x = x.concat(pattEnd[0]);
    y = y.concat(pattEnd[1]);

    zerous = pattEnd[2];
    ones = pattEnd[3];
    k = pattEnd[4];

    var rest = getRest(zerous, ones);
    x = x.concat(rest);
    y = y.concat(rest);

    print('YES');

    print(x.join(''))

    print(y.join(''))

}
function getStartPatt(zerous, ones, k){
    var pattX = [];
    var pattY = [];
    var z = zerous;
    var o = ones;
    var newK = k;

    pattX.push(1);
    pattY.push(0);
    o--;

    var os = Math.min(k, o);

    addChars(pattX, 1, os);
    addChars(pattY, 1, os);

    o = o - os;

    newK = k - os;

    return [pattX, pattY, z, o, newK]
}

function getRest(zerous, ones){
    var rest = [];
    addChars(rest, 1, ones)
    addChars(rest, 0, zerous)
    return rest;
}

function getInt(num){
        return parseInt(num, 10)
    }

var line = readline().split(' ').map(getInt);

getXY.apply(undefined, line)

function getXY(zerous, ones, k){

    if(k === 0){
        print('YES');
        var rest = getRest(zerous, ones).join('');

        print(rest);
        print(rest);
        return;
    }

    if(zerous + ones - 2 < k){
        print('NO')
        return;
    }

    if(ones === 1){
        print('NO')
        return;
    }

    getPatt(zerous, ones, k)

}

function addChars(arr, ch, n){
    for(var i = 0; i < n; i++){
        arr.push(ch);
    }
}

function getEndPatt(zerous, ones, k){
    var pattX = [];
    var pattY = [];
    var z = zerous;
    var o = ones;
    var newK = k;

    var zs = Math.min(k, zerous);

    addChars(pattX, 0, zs)

    addChars(pattY, 0, zs-1)
    pattY.push(1);

    o--;
    z = z - zs;
    newK = newK - zs;
    return [pattX, pattY, z, o, newK]
}
function getPatt(zerous, ones, k){

    var x = [1];
    var y = [1];
    ones--;
    var pattSt = getStartPatt(zerous, ones, k);
    x = x.concat(pattSt[0]);
    y = y.concat(pattSt[1]);

    zerous = pattSt[2];
    ones = pattSt[3];
    k = pattSt[4];

    var pattEnd = getEndPatt(zerous, ones, k);
    x = x.concat(pattEnd[0]);
    y = y.concat(pattEnd[1]);

    zerous = pattEnd[2];
    ones = pattEnd[3];
    k = pattEnd[4];

    var rest = getRest(zerous, ones);
    x = x.concat(rest);
    y = y.concat(rest);

    print('YES');

    print(x.join(''))

    print(y.join(''))

}
function getStartPatt(zerous, ones, k){
    var pattX = [];
    var pattY = [];
    var z = zerous;
    var o = ones;
    var newK = k;

    pattX.push(1);
    pattY.push(0);
    o--;

    var os = Math.min(k, o);

    addChars(pattX, 1, os);
    addChars(pattY, 1, os);

    o = o - os;

    newK = k - os;

    return [pattX, pattY, z, o, newK]
}

function getRest(zerous, ones){
    var rest = [];
    addChars(rest, 0, zerous)
    addChars(rest, 1, ones)
    return rest;
}

function getInt(num){
        return parseInt(num, 10)
    }

var line = readline().split(' ').map(getInt);

getXY.apply(undefined, line)

function getXY(zerous, ones, k){
    var x;
    var y;
    if(zerous < k){
        print('NO')
        return;
    }
    if(k === 0){
        print('YES');
        x = [];
        addChars(x, 1, ones)
        addChars(x, 0, zerous)

        print(x.join(''));
        print(x.join(''));
        return;
    }

    if(ones === 1){
        print('NO')
        return;
    }
    var zCount = 0;
    var oCount = 1;

     x = [1];
     y = [1];
     x.push(1);
     addChars(x, 0, k)

     addChars(y, 0, k)
     y.push(1);

     zCount+=k;
     oCount+=1;

     if(zCount > zerous || oCount > ones){
        print('NO')
        return;
     }

    addChars(x, 1, ones - oCount)
    addChars(x, 0, zerous - zCount)

    addChars(y, 1, ones - oCount)
    addChars(y, 0, zerous - zCount)

    print('YES');
    print(x.join(''));
    print(y.join(''));

}

function addChars(arr, ch, n){
    for(var i = 0; i < n; i++){
        arr.push(ch);
    }
}


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

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

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    var T = parseInt(readline());
    while (T--) {
        var n = 9
        while (n--) {
            var input1 = readline()
            print(input1.replace("1", "2"))
        }
    }
}

var t = parseInt(readline());

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

function setCharAt(str,index,chr) {
    if(index > str.length-1) return str;
    return str.substr(0,index) + chr + str.substr(index+1);
}

var ch = 'a';
var acode = ch.charCodeAt(0);

for (var tt = 0; tt < t; tt++) {
    var a = [];
    for (var i = 0; i < 9; i++) {
        a.push(readline());
    }

    a[0] = setCharAt(a[0], 0, a[0][1]);
    a[3] = setCharAt(a[3], 1, a[3][2]);
    a[6] = setCharAt(a[6], 2, a[6][3]);

    a[1] = setCharAt(a[1], 3, a[1][4]);
    a[4] = setCharAt(a[4], 4, a[4][5]);
    a[7] = setCharAt(a[7], 5, a[7][6]);

    a[2] = setCharAt(a[2], 6, a[2][7]);
    a[5] = setCharAt(a[5], 7, a[5][8]);
    a[8] = setCharAt(a[8], 8, a[8][0]);

    for (var i = 0; i < 9; i++) {
        write(a[i]+'\n');
    }
    // write(res+'\n');
}

var t = +readline();
while (t--) {
    var s = "";
    for (var i = 0; i < 9; i++) {
        print(readline().replace('1','2'));
    }
}

var t = readline();

while (t--) {
  var sud = new Array(9);

  for (var i = 0; i < 9; i++) {
    sud[i] = readline().split('').map(function (val) {
      return parseInt(val);
    });
  }

  var j = 0;

  for (var _i = 0; _i < 9; _i++) {
    sud[_i][j] = sud[_i][j] % 9 + 1;
    if (j + 3 >= 9) j++;
    j = (j + 3) % 9;
  }

  sud.forEach(function (val) {
    print(val.join(''));
  });
}

var T = parseInt(readline());
while (T--) {

    var input1 = readline().split("").map((x) => parseInt(x));
    var input2 = readline().split("").map((x) => parseInt(x));
    var input3 = readline().split("").map((x) => parseInt(x));
    var input4 = readline().split("").map((x) => parseInt(x));
    var input5 = readline().split("").map((x) => parseInt(x));
    var input6 = readline().split("").map((x) => parseInt(x));
    var input7 = readline().split("").map((x) => parseInt(x));
    var input8 = readline().split("").map((x) => parseInt(x));
    var input9 = readline().split("").map((x) => parseInt(x));

    input1[0] = input1[1];
    input2[3] = input2[4];
    input3[6] = input3[7];

    input4[1] = input4[2];
    input5[4] = input5[5];
    input6[7] = input6[8];

    input7[2] = input7[1];
    input8[5] = input8[4];
    input9[8] = input9[7];

    print(input1.join(""));
    print(input2.join(""));
    print(input3.join(""));
    print(input4.join(""));
    print(input5.join(""));
    print(input6.join(""));
    print(input7.join(""));
    print(input8.join(""));
    print(input9.join(""));
}

var T = parseInt(readline());

for (var p = 0; p < T; p++) {
    for (var q = 0; q < 9; q++) {
        var str = readline();
        print(str.replace("1", "2"));
    }
}

var T = parseInt(readline());
while (T--) {
  var input1 = readline()
    .split("")
    .map((x) => parseInt(x));
  var input2 = readline()
    .split("")
    .map((x) => parseInt(x));
  var input3 = readline()
    .split("")
    .map((x) => parseInt(x));
  var input4 = readline()
    .split("")
    .map((x) => parseInt(x));
  var input5 = readline()
    .split("")
    .map((x) => parseInt(x));
  var input6 = readline()
    .split("")
    .map((x) => parseInt(x));
  var input7 = readline()
    .split("")
    .map((x) => parseInt(x));
  var input8 = readline()
    .split("")
    .map((x) => parseInt(x));
  var input9 = readline()
    .split("")
    .map((x) => parseInt(x));
  input1[0] = input1[1];
  input2[3] = input2[4];
  input3[6] = input3[7];

  input4[1] = input4[2];
  input5[4] = input5[5];
  input6[7] = input6[8];

  input7[2] = input7[1];
  input8[5] = input8[4];
 input9[8] = input9[7];

  print(input1.join(""));
  print(input2.join(""));
  print(input3.join(""));
  print(input4.join(""));
  print(input5.join(""));
  print(input6.join(""));
  print(input7.join(""));
  print(input8.join(""));
  print(input9.join(""));
}

// const bg = require('big-integer')
process.stdin.resume()
process.stdin.setEncoding('utf-8')

let input = ''
let ptr = 0
process.stdin.on('data', (i) => {
  input += i
})

process.stdin.on('end', () => {
  input = input.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main()
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt() {
  return parseInt(input[ptr++])
}

function readString() {
  return input[ptr++]
}

function readStrings() {
  return input[ptr++].split(' ')
}

function readInts() {
  return input[ptr++].split(' ').map(a => parseInt(a))
}

function main() {
  let t = readInt()
  while(t--) {
    const sudo = new Array(9)
    for(let i = 0; i < 9; i++) {
      sudo[i] = readString().split('')
    }
    sudo[0][0] = sudo[0][1]
    sudo[1][3] = sudo[1][4]
    sudo[2][6] = sudo[2][7]
    sudo[3][1] = sudo[3][2]
    sudo[4][4] = sudo[4][5]
    sudo[5][7] = sudo[5][8]
    sudo[6][2] = sudo[6][0]
    sudo[7][5] = sudo[7][3]
    sudo[8][8] = sudo[8][6]
    for(let i = 0; i < 9; i++) {
      wr(sudo[i].join(''))
    }
  }
}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
    for (var j = 0; j < 9; j++) {
        print(readline().replace('1','2'));
    }
}

var inputs = readline();

for(var k=0;k<inputs;k++) {
    for(var i=0;i<9;i++) {
        var team = readline().split("").map(x => parseInt(x));

        team.splice(team.indexOf(1) , 1, 2);
        print(team.join(""));
    }
}

//DISABLE THIS LINE END ENABLE NEXT
//const rl =  require('readline').createInterface({input: require('fs').createReadStream('input.txt')});
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
const print = console.log
const write = (...args) => {
    process.stdout.write(args.join(' ') );
}
const lines = []
rl.on('line', line => {
    lines.push(line);
});
rl.on('close', main)

let rli = 0;
function readline() {
    return lines[rli++];
}

function main() {
	var y = +readline()
	while(y > 0) {
		var input = [];
		var r = 9;
		var c = 0;
		while(c < r) {
			var row = readline().split('');
			input.push(row);
			c++;
		}
		for(var i = 0; i < r; i++) {
			for(var j = 0; j < 9; j++) {
				if (input[i][j] == '1') {
					input[i][j] = '2';
				}
			}
		}
		for(var i = 0; i < r; i++) {
			if (i < 8 || y > 1) {
				write(input[i].join('') + '\n');
			} else {
				write(input[i].join(''));
			}
		}
		y--;
	}
}

const processData = (input) => {
    let exp = /\s+/;
    let arr = input.split(exp);
    arr = arr.slice(1);
    arr.forEach(element => {
        console.log(element.replace('1', '2'));
    });
}

//console.log(processData("1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563"));

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
    processData(_input);
});

const processData = (lines) => {
  const num = +lines[0]
  for (let i=0; i<num; i++) {
    const sudoku = []
    for (let j=0; j<9; j++){
      sudoku.push(lines[i*9+j+1].split('').map(x => +x))
    }
    for (let n=0; n<9; n++) {
      const pos = [n, (n*3)%9 + Math.floor(n/3)]
      sudoku[pos[0]][pos[1]] = sudoku[pos[0]][pos[1]] === 1 ? 2 : 1
    }
    for (const s of sudoku) {
      console.log(s.join(''))
    }
  }
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  const {EOL} = require('os')
  const lines = i.split(EOL) /*your input text, split by lines*/
  processData(lines)
})

const init = () => {
  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();
  });

  global.readline = () => {
    return inputString[currentLine++];
  };
};

if (typeof readline === 'undefined') {
  init();
}

const print = (...args) => {
  console.log(...args);
};

const main = () => {
  let t = Number(readline());
  while (t--) {
    const a = Array.from(new Array(9), () => readline().split('').map(x => parseInt(x)));
    const toChange = [
      [0, 0],
      [1, 3],
      [2, 6],
      [3, 1],
      [4, 4],
      [5, 7],
      [6, 2],
      [7, 5],
      [8, 8]];
    const current = toChange.map(([x, y]) => a[x][y]);
    toChange.forEach(([i, j]) => {
      a[i][j] = a[i][(j + 1) % 3 + 3 * Math.floor(j / 3)]
    });
    print(a.map(x => x.join('')).join('\n'))
  }
};

'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() {
  const t = parseInt(readLine());
  for (let i = 0; i < t; i++) {
    // let n = parseInt(readLine());
    let a = new Array(9);
    for (let i = 0; i < 9; i++)
      a[i] = readLine();
    let res = new Array(9).fill('');
    for(let i = 0; i < 9; i++) {
      for (let j = 0; j < 9; j++) {
        if (a[i][j] === '1') res[i] += '2';
        else res[i] += a[i][j];
      }
    }
    for (let i = 0; i < 9; i++) console.log(res[i]);
  }
  //process.stdout.write("hello: ");
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    let n = parseInt(readline(), 10);

    for (var j = 0; j < n; j++) {
        for (var i = 0; i < 9; i++) {
            console.log(readline().replace(/8/g, '3'));
        }
    }

}

function tpp(x) {
    return (x ==='9') ? '1' : x + 1;
}

var t = +readline();
while (t--) {
    var s = "";
    for (var i = 0; i < 9; i++) {
        s = readline();
        s.replace('1','2');
        print(s);
    }
}

var t = readline();

while (t--) {
  var sud = new Array(9);

  for (var i = 0; i < 9; i++) {
    sud[i] = readline().split('').map(function (val) {
      return parseInt(val);
    });
  }

  for (var _i = 0; _i < 9; _i++) {
    sud[_i][_i] = sud[_i][_i] % 9 + 1;
  }

  sud.forEach(function (val) {
    print(val.join(''));
  });
}

var t = parseInt(readline());

function mapper(num) {
    return +num;
}

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

    for (var j = 0; j < 9; j++) {
        var row = readline().split('');
        if (row[j] === '1') {
            row[j] = '9';
        } else {
            row[j] = '1';
        }
        print(row.join(''));
    }
}

var inputs = readline();

for(var k=0;k<inputs;k++) {
    for(var i=0;i<9;i++) {
        var team = readline().split("").map(x => parseInt(x));

        if(team[i] === 9) {
            team[i] = team[i] - 1;
        } else {
            team[i] = team[i] + 1;

        }
        print(team.join(""));
    }
}

var inputs = readline();

for(var k=0;k<inputs;k++) {
    for(var i=0;i<9;i++) {
        var team = readline().split("").map(x => parseInt(x));
        if(i === 8) {
            team[i-1] = team[i];
        } else {
            team[i+1] = team[i];
        }
        print(team.join(""));
    }
}

// const bg = require('big-integer')
process.stdin.resume()
process.stdin.setEncoding('utf-8')

let input = ''
let ptr = 0
process.stdin.on('data', (i) => {
  input += i
})

process.stdin.on('end', () => {
  input = input.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main()
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt() {
  return parseInt(input[ptr++])
}

function readString() {
  return input[ptr++]
}

function readStrings() {
  return input[ptr++].split(' ')
}

function readInts() {
  return input[ptr++].split(' ').map(a => parseInt(a))
}

function main() {
  let t = readInt()
  while(t--) {
    const sudo = new Array(9)
    for(let i = 0; i < 9; i++) {
      sudo[i] = readString().split('')
    }
    sudo[0][0] = sudo[0][1]
    sudo[1][3] = sudo[1][4]
    sudo[2][6] = sudo[2][7]
    sudo[3][1] = sudo[3][2]
    sudo[4][4] = sudo[4][5]
    sudo[5][7] = sudo[5][8]
    sudo[6][2] = sudo[6][0]
    sudo[7][5] = sudo[7][3]
    sudo[8][8] = sudo[8][6]
    for(let i = 0; i < 9; i++) {
      wr(sudo[i].join(' '))
    }
  }
}

const processData = (input) => {
    let exp = /\s+/;
    let arr = input.split(exp);
    arr = arr.slice(1);
    arr.array.forEach(element => {
        console.log(element.replace('1','2'));
    });
}

const processData = (input) => {
    let exp = /\s+/;
    let arr = input.split(exp);
    arr = arr.slice(1);
    arr.forEach(element => {
        console.log(element.replace('1','2'));
    });
}

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

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

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    var T = parseInt(readline());
    while (T--) {
        var n = 9
        while (n--) {
            var input1 = readline().split('').map(x => parseInt(x));
            var index = input1.indexOf(1)
            input1[index] = 2
            print(input1.join(''))
        }

    }

}

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

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

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    var T = parseInt(readline());
    while (T--) {
        var input1 = readline().split('').map(x => parseInt(x));
        var input2 = readline().split('').map(x => parseInt(x));
        var input3 = readline().split('').map(x => parseInt(x));
        var input4 = readline().split('').map(x => parseInt(x));
        var input5 = readline().split('').map(x => parseInt(x));
        var input6 = readline().split('').map(x => parseInt(x));
        var input7 = readline().split('').map(x => parseInt(x));
        var input8 = readline().split('').map(x => parseInt(x));
        var input9 = readline().split('').map(x => parseInt(x));
        input1[0] = input1[1]
        input2[3] = input2[4]
        input3[6] = input3[7]

        input4[1] = input4[2]
        input5[4] = input5[5]
        input6[7] = input6[8]

        input7[2] = input7[1]
        input8[5] = input8[4]
        input9[8] = input9[7]
        print(input1.join())
        print(input2.join())
        print(input3.join())
        print(input4.join())
        print(input5.join())
        print(input6.join())
        print(input7.join())
        print(input8.join())
        print(input9.join())

    }

}

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

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

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    var T = parseInt(readline());
    while (T--) {
        var input1 = readline().split('').map(x => parseInt(x));
        var input2 = readline().split('').map(x => parseInt(x));
        var input3 = readline().split('').map(x => parseInt(x));
        var input4 = readline().split('').map(x => parseInt(x));
        var input5 = readline().split('').map(x => parseInt(x));
        var input6 = readline().split('').map(x => parseInt(x));
        var input7 = readline().split('').map(x => parseInt(x));
        var input8 = readline().split('').map(x => parseInt(x));
        var input9 = readline().split('').map(x => parseInt(x));
        input1[1]=input1[0]
        input2[4]=input2[3]
        input3[7]=input3[6]

        input4[1]=input4[0]
        input5[4]=input5[3]
        input6[7]=input6[6]

        input7[1]=input7[0]
        input8[4]=input8[3]
        input9[7]=input9[6]
        print(input1)
        print(input2)
        print(input3)
        print(input4)
        print(input5)
        print(input6)
        print(input7)
        print(input8)
        print(input9)

    }

}

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

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

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    var T = parseInt(readline());
    while (T--) {
        var input1 = readline().split('').map(x => parseInt(x));
        var input2 = readline().split('').map(x => parseInt(x));
        var input3 = readline().split('').map(x => parseInt(x));
        var input4 = readline().split('').map(x => parseInt(x));
        var input5 = readline().split('').map(x => parseInt(x));
        var input6 = readline().split('').map(x => parseInt(x));
        var input7 = readline().split('').map(x => parseInt(x));
        var input8 = readline().split('').map(x => parseInt(x));
        var input9 = readline().split('').map(x => parseInt(x));
        input1[0] = input1[1]
        input2[3] = input2[4]
        input3[6] = input3[7]

        input4[1] = input4[2]
        input5[4] = input5[5]
        input6[7] = input6[8]

        input7[2] = input7[1]
        input8[5] = input8[4]
        input9[8] = input9[7]
        print(input1.join(''))
        print(input2.join(''))
        print(input3.join(''))
        print(input4.join(''))
        print(input5.join(''))
        print(input6.join(''))
        print(input7.join(''))
        print(input8.join(''))
        print(input9.join(''))

    }

}

const init = () => {
  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();
  });

  global.readline = () => {
    return inputString[currentLine++];
  };
};

if (typeof readline === 'undefined') {
  init();
}

const print = (...args) => {
  console.log(...args);
};

const main = () => {
  let t = Number(readline());
  while (t--) {
    const a = Array.from(new Array(9), () => readline().split('').map(x => parseInt(x)));
    const toChange = [
      [0, 0],
      [1, 3],
      [2, 6],
      [3, 1],
      [4, 4],
      [5, 7],
      [6, 2],
      [7, 5],
      [8, 8]];
    const current = toChange.map(([x, y]) => a[x][y]);
    toChange.forEach(([i, j]) => {
      a[i][j] = a[(i + 1) % 9][(j + 1) % 9]
    });
    print(a.map(x => x.join('')).join('\n'))
  }
};

'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() {
  const t = parseInt(readLine());
  for (let i = 0; i < t; i++) {
    // let n = parseInt(readLine());
    let a = new Array(9);
    for (let i = 0; i < 9; i++)
      a[i] = readLine();
    let res = new Array(9).fill('');
    for(let i = 0; i < 9; i++) {
      for (let j = 0; j < 9; j++) {
        if (i === j) {
          let char = parseInt(a[i][j]) + 1;
          if (char === 10) char = 1;
          res[i] += char;
        }
        res[i] += a[i][j];
      }
    }
    for (let i = 0; i < 9; i++) console.log(res[i]);
  }
  //process.stdout.write("hello: ");
}