You are given an integer $$$n$$$. You have to change the minimum number of digits in it in such a way that the resulting number does not have any leading zeroes and is divisible by $$$7$$$.If there are multiple ways to do it, print any of them. If the given number is already divisible by $$$7$$$, leave it unchanged.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 990$$$) — the number of test cases. Then the test cases follow, each test case consists of one line containing one integer $$$n$$$ ($$$10 \le n \le 999$$$).

For each test case, print one integer without any leading zeroes — the result of your changes (i. e. the integer that is divisible by $$$7$$$ and can be obtained by changing the minimum possible number of digits in $$$n$$$). If there are multiple ways to apply changes, print any resulting number. If the given number is already divisible by $$$7$$$, just print it.

NoteIn the first test case of the example, $$$42$$$ is already divisible by $$$7$$$, so there's no need to change it.In the second test case of the example, there are multiple answers — $$$28$$$, $$$21$$$ or $$$63$$$.In the third test case of the example, other possible answers are $$$357$$$, $$$371$$$ and $$$378$$$. Note that you cannot print $$$077$$$ or $$$77$$$.

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

            }
                console.log(c)

        }
    }
});

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

       }else{
        while(c % 7 !== 0){
            c++
            if(c % 7 === 0){
                break;
            }
        }
               console.log(c)

       }
   }
});

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

var T = readline();
for(var q=1;q<=T;q++) {
            var y = readline();
            var n = parseInt(y);
            if(n % 7 == 0) {
                console.log(n);
                continue;
            }
            n -= n%10;
            while(n%7 !== 0) n++
            console.log(n);
}

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

'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(){
 let noOfInputs = (readline());
 while(noOfInputs--){
    let input =parseInt(readline());
    if(input < 10) console.log(7)
    else if(input%7 == 0) console.log(input)
    else{
        if(input%7 <= input%10){
            console.log(input-input%7);
        }else{
            console.log(input+(7-input%7));
        }
    }
 }
}

let input = "";
process.stdin.on("data", (chunk) => {
  input += chunk;
});
function differentDigits(a, b) {
  a = "" + a;
  b = "" + b;
  if (a.length !== b.length) {
    return false;
  }
  let count = 0;
  for (let i = 0; i < a.length; i++) {
    if (a[i] !== b[i]) {
      count++;
    }
  }
  return count;
}
process.stdin.on("end", () => {
  let lines = input.trim().split("\n");
  let t = parseInt(lines[0].trim());
  let i = 1;
  let dividends = [];
  for (let i = 0; i <= 999; i += 7) {
    dividends.push(i);
  }
  while (t--) {
    let n = parseInt(lines[i++].trim());
    let min = 5;
    let result;
    for (let i = 0; i < dividends.length; i++) {
      let x = differentDigits(n, dividends[i]);
      if (x === false) {
        continue;
      }
      if (x < min) {
        min = x;
        result = dividends[i];
      }
    }
    console.log(result);
  }
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

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

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

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

        let rem = n % 7;
        if (rem === 0) {
            output(n);
            continue;
        }

        let zeroLast = Math.floor(n / 10) * 10;

        for (let i = 0; i < 10; i++) {
            if ((zeroLast + i) % 7 === 0) {
                output(zeroLast + i);
                break;
            }
        }
    }
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		if(N % 7 == 0){
			myout(N);
			continue;
		}
		var S = [];
		while(N > 0){
			S.unshift(N % 10);
			N = Math.floor(N / 10);
		}
		var max = 4;
		var output = 0;
		for(var i = 0; i <= 999; i += 7){
			var L = [];
			var V = i;
			while(V > 0){
				L.unshift(V % 10);
				V = Math.floor(V / 10);
			}
			if(L.length != S.length){
				continue;
			}
			var c = 0;
			for(var j = 0; j < 3; j++){
				if(L[j] != S[j]){
					c++;
				}
			}
			if(max > c){
				max = c;
				output = i;
			}
		}
		myout(output);
	}
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
function readLine() {
    return inputString[currentLine++];
};
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    main();
    // cmd(not powershell): node cp.js < input.txt
});

function main() {
    let t = parseInt(readLine());
    while (t-- > 0) {
        console.log(solve());
    }
}
function solve() {
    let num = parseInt(readLine());
    if (num % 7 == 0) return num;
    let boundary1 = parseInt(num / 10) * 10;
    let boundary2 = parseInt(num / 10) * 10 + 9;
    let rem = num % 7;
    if ((num - rem) >= boundary1 && (num - rem) <= boundary2)
        return num - rem;
    return num + 7 - rem;
}

const readline = require('readline')

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

function solve(n) {
    if (n % 7) {
        if (n < 10) return 7
        const r = n % 10
        const add = 7 - n % 7
        if (r + add < 10) {
            return n + add
        } else {
            return n - n % 7
        }
    } else {
        return n
    }
}

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

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

let nl = nextLine();

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

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

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

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

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

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		let x = nl.num();

		if (x % 7 == 0) {
			ans.push(x);
		} else if (x % 10 - x % 7 > 0) {
			ans.push(x - x % 7);
		} else {
			ans.push(x + (7 -  x % 7));
		}
	}
	console.log(ans.join('\n'));
};

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

'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 = readline();
    let input = Number(readline());
    let nums = [];
    nums.push(input);

    for(let i = 2; i <= t; i++ ) {
        input = Number(readline());
        nums.push(input)
    }

    for(let num of nums) {
          if (num % 7 === 0) {
               console.log(num)
               continue;
          }

          let arrFromNum = String(num).split('');
          for (let i = 0; i < arrFromNum.length; i++) {
               let curArr = arrFromNum.concat();
               for (let j = 1; j <= 9; j++) {
                    curArr[i] = j;
                    let newNum = Number(curArr.join(''));
                    if (newNum % 7 === 0) {
                         console.log(newNum);
                         break;
                    }
               }
               break;
          }
     }
}

var t = +readline();

while(t--) {
   var n = +readline();
   if (n % 7 === 0) {
        print(n)
   } else {
        var nNew = n - n%10;
        var remainder = nNew % 7;
        print(remainder ? nNew + 7 - remainder : nNew);
   }
}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
   var n = +readline();
   if (n % 7 === 0) {
       print(n)
   } else {
  var nNew = n - n%10;
  var remainder = nNew % 7;
  print(remainder ? nNew + 7 - remainder : nNew);
   }

}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
   var n = +readline();
   if (n % 7 === 0) {
       print(n)
   } else {
  var notAtZero = n%10;
  var nNew = notAtZero ? Math.floor(n/10)*10 : n;
  var remainder = nNew % 7;
  print(remainder ? nNew + 7 - remainder : nNew);
   }

}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
   var n = +readline();
   if (n % 7 === 0) {
       print(n)
   } else {
  //var nNew = Math.floor(n/10)*10;
  var nNew = n - n%10;
  var remainder = nNew % 7;
  print(remainder ? nNew + 7 - remainder : nNew);
   }

}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
   var n = +readline();
   if (n % 7 === 0) {
       print(n)
   } else {
  var nNew = Math.floor(n/10)*10;
  var remainder = nNew % 7;
  print(remainder ? nNew + 7 - remainder : nNew);
   }

}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
   var n = parseInt(readline());
   if (n % 7 === 0) {
       print(n)
   } else {
  var nNew = Math.floor(n/10)*10;
  var remainder = nNew % 7;
  print(remainder ? nNew + 7 - remainder : nNew);
   }

}

var t = parseInt(readline());

function singleTest(n) {
  if (n % 7 === 0) return n;
  var nNew = Math.floor(n/10)*10;
  var remainder = nNew % 7;
  return remainder ? nNew + 7 - remainder : nNew;
}

for (var i = 0; i < t; i++) {
   var number = parseInt(readline());
   print(singleTest(number));
}

var t = parseInt(readline());
for (var i = 0; i < t; i++) {
  var n = parseInt(readline());
  if (n % 7 === 0) {
    print(n);
  } else {
    n = Math.floor(n / 10) * 10;
    for (var j = 0; j < 10; j++) {
      if ((n + j) % 7 === 0) {
        print(n + j);
        break;
      }
    }
  }
}

// var { readline, print, testOutput, console } = require("@ip-algorithmics/codeforces-io");

var t = parseInt(readline());
for (var i = 0; i < t; i++) {
  var n = parseInt(readline());
  if (n % 7 === 0) {
    print(n);
  } else {
    n = Math.floor(n / 10) * 10;
    for (var j = 0; j < 10; j++) {
      if ((n + j) % 7 === 0) {
        print(n + j);
        break;
      }
    }
  }
}

// testOutput();

var n = parseInt(readline())

for (var i = 0 ; i<n ; i++) {
  var num = parseInt(readline());
  if (num % 7 === 0) {
    print(num);
  }
  else {
    var minDiv = Math.floor(num/7);
    var maxDiv = Math.ceil(num/7);
    var minAns = (minDiv * 7).toString();
    var maxAns = (maxDiv * 7).toString();

    var minDiff = 0;
    for (var j = 0 ; j<minAns.length ; j++) {
      if (minAns[j] !== num.toString()[j]) {
        ++minDiff;
      }
    }

    var maxDiff = 0;
    for (var j = 0 ; j<maxAns.length ; j++) {
      if (maxAns[j] !== num.toString()[j]) {
        ++maxDiff;
      }
    }

    if (minDiff <= maxDiff && minAns.length === num.toString().length) {
      print(minAns);
    }
    else {
      print(maxAns);
    }

  }
}

var lines = parseInt(readline());

for (var i = 0; i < lines; i++) {
  var number = parseInt(readline());
  var remainder = number % 7;
  if (remainder <= number % 10) print(number - remainder);
  else print(number + (7 - remainder));
}

var n=parseInt(readline())
for(i=0;i<n;i++)
{var number=parseInt(readline());
var check=parseInt(number/7)*7
if(parseInt((number%100)/10)!==parseInt((check%100)/10))check+=7

print(check)}

var t = readline();
for(var i = 0 ; i < t ; i++){
    var n = readline();
    if(n % 7 === 0){
        print(n);
    }
    else{
        if( (parseInt(n % 10) + parseInt(7 - n % 7)) < 10 ){
            print(parseInt(n) + parseInt(7 - n % 7));
        }
        else{
            print(parseInt(n) - parseInt(n % 7));
        }
    }
}

t= parseInt(readline()) ;
while (t--) {
	n =  parseInt(readline()) ;
	if (n<10) {
	    print(7) ;
	    continue ;
	}
	if (n%7==0) {
	print(n) ;
	}else {

	n-= n%10 ;
	ans =  0;
	for (i = 0 ; i <= 9 ; i ++ )
	{
		nw = n + i ;

		if ((nw%7) == 0 ) {
		ans = nw;
		break ;
		}
	}
	print(ans) ;
	}

	}

lines = +readline();
for (var i = 0; i < lines; i++) {
  var num = +readline();
  var old = num;
  if (num % 7 !== 0) {
    var digit = num % 10;
    if (digit + (7 - (num % 7)) <= 9) num = num + (7 - (num % 7));
    else num = num - (num % 7);
  }
  print(`${num}`);
}

var t = parseInt(readline());

for(var i = 0; i< t; i++){
    var n = parseInt(readline());
    if(n % 7 === 0) {
        print(n);
    }
    else {
        n -= n % 10;
        while(n % 7 !== 0) {
            n++;
        }
        print(n)
    }
}

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

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var s = 0
    for(j = 1; j <= n; j++){
        var a = lines[j].split('')
        var b = a[a.length - 1]
        var c = lines[j] - b + 1
        if(Number(lines[j]) % 7 === 0){
            console.log(lines[j])
        }else{
            while(c % 7 !== 0){
                c++
                if(c % 7 === 0){
                    console.log(c)
                    break;
                }
            }
        }
    }
});

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

       }else{
        while(c % 7 !== 0){
            c++
            if(c % 7 === 0){
                break;
            }
        }
               console.log(c)

       }
   }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
   for(j = 1; j <= n; j++){
       var a = lines[j].split('')
       var b = a[a.length - 1]
       var c = lines[j] - b + 1
       if((lines[j] - 1) % 7 === 0 ){
           c = lines[j] - 1
       }else{
        while(c % 7 !== 0){
            c++
            if(c % 7 === 0){
                break;
            }
        }
       }
       console.log(c)
   }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
   for(j = 1; j <= n; j++){
       var a = lines[j].split('')
       var b = a[a.length - 1]
       var c = lines[j] - b + 1
       if((lines[j] - 1) % 7 === 0 ){
           console.log(lines[j] - 1)
       }else{
        while(c % 7 !== 0){
            c++
            if(c % 7 === 0){
                break;
            }
        }
       }
       console.log(c)
   }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
   for(j = 1; j <= n; j++){
       var a = lines[j].split('')
       var b = a[a.length - 1]
       var c = lines[j] - b + 1
       if((lines[j] - 1) % 7 === 0 ){
           console.log((lines[j]) - 1)
       }else{
        while(c % 7 !== 0){
            c++
            if(c % 7 === 0){
                break;
            }
        }
       }
       console.log(c)
   }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
   for(j = 1; j <= n; j++){
       var a = lines[j].split('')
       var b = a[a.length - 1]
       var c = lines[j] - b + 1
       if((lines[j] - 1) % 7 === 0 ){
           console.log((lines[j]) - 1)
       }
        while(c % 7 !== 0){
            c++
            if(c % 7 === 0){
                break;
            }
        }
       console.log(c)
   }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
   for(j = 1; j <= n; j++){
       var a = lines[j].split('')
       var b = a[a.length - 1]
       var c = lines[j]
        while(c % 7 !== 0){
            c--
            if(c % 7 === 0){
                break;
            }
        }
       console.log(c)
   }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
   for(j = 1; j <= n; j++){
       var a = lines[j].split('')
       var b = a[a.length - 1]
       var c = lines[j] - b + 1
        while(c % 7 !== 0){
            c++
            if(c % 7 === 0){
                break;
            }
        }
       console.log(c)
   }
});

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

        }else{
            console.log(n)
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    for(j = 1; j <= lines[0]; j++){
            var n = lines[j];
        if(n % 7 !== 0){
        while(n % 7 !== 0){
            n++
            if(n % 7 === 0){
                break;
            }
        }
        }else{
            console.log(n)
        }
        console.log(n)
    }
});

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

        while(n % 7 !== 0){
            n++
            if(n % 7 === 0){
                break;
            }
        }
        console.log(n)
    }
});

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

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

var T = readline();
for(var q=1;q<=T;q++) {
            var y = readline();
            var n = parseInt(y);
            if(n % 7 == 0) {
                console.log(n)
                continue;
            }
            var s = '';
            s += n;
            var de = []
            for(var i=n;i>=7;i--) {
            	if(i % 7 === 0) {
            		var r = ''
            	    r += i;
            	    if(r.length < s.length) continue;

            	    var sum = 0;

            	    for(var j=0;j<r.length;j++) {
            		    if(r[j] !== s[j]) sum++;
            	    }
            	    de[sum] = i;
            	}
            }
            var ans
            for(var i=0;i<de.length;i++) {
            	if(de[i] !== undefined) {
            		ans = de[i];
            		break;
            	}
            }
            if(ans == undefined) {
                while(n%7 !==0) n++;
                ans = n;
            }
            console.log(ans)
}

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

var T = readline();
for(var q=1;q<=T;q++) {
        var y = readline();
        var n = parseInt(y);
         var s = '';
         s += n;
         var de = []
         for(var i=n;i>=1;i--) {
            if(i % 7 === 0) {
                    		var r = ''
                    	    r += i;
                    	    if(r.length < s.length) {
                    	    	var diff = s.length-r.length;
                    	    	var gh = '';
                    	    	for(var i=1;i<=diff;i++) {
                    	    		gh += 7;
                    	    	}
                    	    	gh += r;
                    	    	var sum = 0;

                    	        for(var j=0;j<gh.length;j++) {
                    		        if(gh[j] !== s[j]) sum++;
                    	        }
                    	        de[sum] = gh;
                    	        continue;
                    	    }
                    	    var sum = 0;

                    	    for(var j=0;j<r.length;j++) {
                    		    if(r[j] !== s[j]) sum++;
                    	    }
                    	    de[sum] = i;
            }

         }
         var ans
         for(var i=0;i<de.length;i++) {
                    	if(de[i] !== undefined) {
                    		ans = de[i];
                    		break;
                    	}
         }
         console.log(ans)
}

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

var T = readline();
for(var q=1;q<=T;q++) {
            var y = readline();
            var n = parseInt(y);
            if(n % 7 == 0) {
                console.log(n)
                continue;
            }
            var s = '';
            s += n;
            var de = []
            for(var i=n;i>=7;i--) {
            	if(i % 7 === 0) {
            		var r = ''
            	    r += i;
            	    if(r.length < s.length) continue;

            	    var sum = 0;

            	    for(var j=0;j<r.length;j++) {
            		    if(r[j] !== s[j]) sum++;
            	    }
            	    de[sum] = i;
            	}
            }
            var ans
            for(var i=0;i<de.length;i++) {
            	if(de[i] !== undefined) {
            		ans = de[i];
            		break;
            	}
            }
            console.log(ans)
}

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

var T = readline();
for(var q=1;q<=T;q++) {
            var n = readline();
            n -= 0;
            if(n % 7 == 0) {
                console.log(n)
                continue;
            }
            var s = '';
            s += n;
            var de = []
            for(var i=n;i>=7;i--) {
            	if(i % 7 === 0) {
            		var r = ''
            	    r += i;
            	    if(r.length < s.length) continue;
            	    var sum = 0;

            	    for(var j=0;j<r.length;j++) {
            		    if(r[j] !== s[j]) sum++;
            	    }
            	    de[sum] = i;
            	}
            }
            var ans
            for(var i=0;i<de.length;i++) {
            	if(de[i] !== undefined) {
            		ans = de[i];
            		break;
            	}
            }
            console.log(ans)
}

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

var T = readline();
for(var q=1;q<=T;q++) {
            var n = readline();
            n -= 0;
            if(n % 7 == 0) {
                console.log(n)
                continue;
            }
            var s = '';
            s += n;
            var de = []
            for(var i=n;i>=100;i--) {
            	if(i % 7 === 0) {
            		var r = ''
            	    r += i;
            	    if(r.length < s.length) continue;
            	    var sum = 0;

            	    for(var j=0;j<r.length;j++) {
            		    if(r[j] !== s[j]) sum++;
            	    }
            	    de[sum] = i;
            	}
            }
            var ans
            for(var i=0;i<de.length;i++) {
            	if(de[i] !== undefined) {
            		ans = de[i];
            		break;
            	}
            }
            console.log(ans)
}

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

var T = readline();
for(var q=1;q<=T;q++) {
            var n = readline();
            n -= 0;
            var s = '';
            s += n;
            var de = []
            for(var i=n;i>=100;i--) {
            	if(i % 7 === 0) {
            		var r = ''
            	    r += i;
            	    if(r.length < s.length) continue;
            	    var sum = 0;

            	    for(var j=0;j<r.length;j++) {
            		    if(r[j] !== s[j]) sum++;
            	    }
            	    de[sum] = i;
            	}
            }
            var ans
            for(var i=0;i<de.length;i++) {
            	if(de[i] !== undefined) {
            		ans = de[i];
            		break;
            	}
            }
            console.log(ans)
}

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

var T = readline();
for(var q=1;q<=T;q++) {
            var n = readline();
            n -= 0;
            var s = '';
            s += n;
            var de = []
            for(var i=n;i>=7;i--) {
            	if(i % 7 === 0) {
            		var r = ''
            	    r += i;
            	    if(r.length < s.length) continue;
            	    var sum = 0;

            	    for(var j=0;j<r.length;j++) {
            		    if(r[j] !== s[j]) sum++;
            	    }
            	    de[sum] = i;
            	}
            }
            var ans
            for(var i=0;i<de.length;i++) {
            	if(de[i] !== undefined) {
            		ans = de[i];
            		break;
            	}
            }
            console.log(ans)
}

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

var T = readline();
for(var q=1;q<=T;q++) {
            var n = readline();
            var s = ''
            s += n;
            var de = []
            for(var i=n;i>=7;i--) {
            	if(i % 7 === 0) {
            		var r = ''
            	    r += i;
            	    if(r.length < s.length) continue;
            	    var sum = 0;

            	    for(var j=0;j<r.length;j++) {
            		    if(r[j] !== s[j]) sum++;
            	    }
            	    de[sum] = i;
            	}
            }
            var ans
            for(var i=0;i<de.length;i++) {
            	if(de[i] !== undefined) {
            		ans = de[i];
            		break;
            	}
            }
            console.log(ans)
}

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var k = lines[i];
        var ans = 0;
        for(j = 7; j <= 994; j+=7){
            if(Math.abs(k - j) < 7){
                ans = j;
                break;
            }
        }
        console.log(ans);
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    for(var j = 1; j <= n; j++){
        var k = lines[j];
        var u = k;
        var a = 0;
        var b = 0;
        while(k % 7 !== 0){
            k++;
            a++;
        }
        while(u % 7 !== 0){
            u--;
            b++;
        }
        if(k == 21){
            k += 7;
        }
        if(a > b && u != 7){
            console.log(u);
        }else{
            console.log(k);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    for(var j = 1; j <= n; j++){
        var k = Number(lines[j]);
        var u = k;
        while(k % 7 !== 0){
            k++;
        }
        if(k == 21){
            k += 7;
        }
        console.log(k);
    }
});

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

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    for(var j = 1; j <= n; j++){
        var k = lines[j];
        var u = k;
        var a = 0;
        var b = 0;
        while(k % 7 !== 0){
            k++;
            a++;
        }
        while(u % 7 !== 0){
            u--;
            b++;
        }
        if(a > b && u != 7){
            console.log(u);
        }else{
            console.log(k);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    for(var j = 1; j <= n; j++){
        var k = lines[j];
        var u = k;
        var a = 0;
        var b = 0;
        while(k % 7 !== 0){
            k++;
            a++;
        }
        while(u % 7 !== 0){
            u--;
            b++;
        }
        if(a > b){
            console.log(u);
        }else{
            console.log(k);
        }
    }
});

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

'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(){
 let noOfInputs = (readline());
 while(noOfInputs--){
    let input = readline();
    let answer = 0;
    if(parseInt(input)%7 === 0 && input[input.length-1] !== 0) answer = (input);
    else if(input[input.length-1] !== 0) answer = (Math.floor(input/7)*7)
    if(answer%10 === 0){
        answer += 7;
    }
    if((answer).toString().length < input.toString().length) answer += 7;
    console.log(parseInt(answer))
 }
}

'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(){
 let noOfInputs = (readline());
 while(noOfInputs--){
    let input = readline();
    let answer = 0;
    if(parseInt(input)%7 === 0 && input[input.length-1] !== 0) answer = (input);
    else if(input[input.length-1] !== 0) answer = (Math.floor(input/7)*7)
    if(answer%10 === 0){
        answer += 7;
    }
    if((answer).toString().length < input.toString().length) answer += 7;
    console.log(answer)
 }
}

'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(){
 let noOfInputs = (readline());
 while(noOfInputs--){
    let input = readline();
    let answer = 0;
    if(parseInt(input)%7 === 0 && input[input.length-1] !== 0) answer = (input);
    else if(input[input.length-1] !== 0) answer = (Math.floor(input/7)*7)
    if(answer%10 === 0){
        answer += 7;
    }
    console.log(answer)
 }
}

'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(){
 let noOfInputs = (readline());
 while(noOfInputs--){
    let input = readline();
    if(parseInt(input)%7 == 0 && input[input.length-1] != 0) console.log(input);
    else if(input[input.length-1] != 0) console.log(Math.floor(input/7)*7)
    else console.log(parseInt(input) + 1)
 }
}

'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(){
 let noOfInputs = (readline());
 while(noOfInputs--){
    let input = readline();
    if(parseInt(input)%7 == 0 && input[input.length-1] != 0) console.log(input);
    if(input[input.length-1] != 0) console.log(Math.floor(input/7)*7)
    else console.log(parseInt(input) + 1)
 }
}

let input = "";
process.stdin.on("data", (chunk) => {
  input += chunk;
});
function differentDigits(a, b) {
  a = "" + a;
  b = "" + b;
  if (a.length !== b.length) {
    return false;
  }
  let count = 0;
  for (let i = 0; i < a.length; i++) {
    if (a[i] !== b[i]) {
      count++;
    }
  }
  return count;
}
process.stdin.on("end", () => {
  let lines = input.trim().split("\n");
  let t = parseInt(lines[0].trim());
  let i = 1;
  let dividends = [];
  for (let i = 0; i <= 999; i += 7) {
    dividends.push(i);
  }
  while (t--) {
    let n = parseInt(lines[i++].trim());
    let min = 5;
    let result;
    for (let i = 0; i < dividends.length; i++) {
      let x = differentDigits(n, dividends[i]);
      if (!x) {
        continue;
      }
      if (x < min) {
        min = x;
        result = dividends[i];
      }
    }
    console.log(result);
  }
});

r=readline;

for(r();n=r();) {
   var n = +readline();
   if (n % 7 === 0) {
       print(n)
   } else {
  var nNew = n - n%10;
  var remainder = nNew % 7;
  print(remainder ? nNew + 7 - remainder : nNew);
   }

}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
   var n = +readline();
   if (n % 7 === 0) {
       print(n)
   } else {
  var atZero = n%10;
  var nNew = atZero ? n : Math.floor(n/10)*10;
  var remainder = nNew % 7;
  print(remainder ? nNew + 7 - remainder : nNew);
   }

}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
   var n = parseInt(readline());
   if (n % 7 === 0) print(n);
  var nNew = Math.floor(n/10)*10;
  var remainder = nNew % 7;
  print(remainder ? nNew + 7 - remainder : nNew);
}

var t = parseInt(readline());

function singleTest(n, freezeLastDigit) {
      var remainder = n % 7
      if (remainder === 0) return n;
      if (freezeLastDigit) return singleTest(n+10,true)
      var lastDigit = n % 10
      var plusDigit = 7 - remainder;
      if (lastDigit + plusDigit <= 9) return n.toString(10).slice(0,-1) + (lastDigit + plusDigit);
      return singleTest(n+10,true)
}

for (var i = 0; i < t; i++) {
   var number = parseInt(readline());
   print(singleTest(number, false))
}

var t = parseInt(readline());

function singleTest(n, freezeLastDigit) {
      var remainder = n % 7
      if (remainder === 0) return n;
      if (freezeLastDigit) return singleTest(n+10,true)
      var lastDigit = n % 10
      var plusDigit = 7 - remainder;
      if (lastDigit + plusDigit <= 9) return n.toString(10).slice(0,-1) + (lastDigit + plusDigit);
      return singleTest(n+10,true)
}

for (var i = 0; i < t; i++) {
   var n = parseInt(readline());
   print(singleTest(n, false))
}

var n = parseInt(readline())
print(n);

for (var i = 0 ; i<n ; i++) {
  var num = parseInt(readline());
  // print(num);
  if (num % 7 === 0) {
    print(num);
  }
  else {
    var minDiv = Math.floor(num/7);
    var maxDiv = Math.ceil(num/7);
    var minAns = (minDiv * 7).toString();
    var maxAns = (maxDiv * 7).toString();

    var minDiff = 0;
    for (var j = 0 ; j<minAns.length ; j++) {
      if (minAns[j] !== num.toString()[j]) {
        ++minDiff;
      }
    }

    var maxDiff = 0;
    for (var j = 0 ; j<maxAns.length ; j++) {
      if (maxAns[j] !== num.toString()[j]) {
        ++maxDiff;
      }
    }

    if (minDiff <= maxDiff && minAns.length === num.toString().length) {
      print(minAns);
    }
    else {
      print(maxAns);
    }

  }
}

var n = parseInt(readline())
// print(n);

for (var i = 0 ; i<n ; i++) {
  var num = parseInt(readline());
  // print(num);
  if (num % 7 === 0) {
    print(num);
  }
  else {
    var minDiv = Math.floor(num/7);
    var maxDiv = Math.ceil(num/7);
    var minAns = (minDiv * 7).toString();
    var maxAns = (maxDiv * 7).toString();

    var minDiff = 0;
    for (var j = 0 ; j<minAns.length ; j++) {
      if (minAns[j] !== num.toString()[j]) {
        ++minDiff;
      }
    }

    var maxDiff = 0;
    for (var j = 0 ; j<maxAns.length ; j++) {
      if (maxAns[j] !== num.toString()[j]) {
        ++maxDiff;
      }
    }

    if (minDiff <= maxDiff) {
      print(minAns);
    }
    else {
      print(maxAns);
    }

  }
}

var n = parseInt(readline())
print(n);

for (var i = 0 ; i<n ; i++) {
  var num = parseInt(readline());
  // print(num);
  if (num % 7 === 0) {
    print(num);
  }
  else {
    var minDiv = Math.floor(num/7);
    var maxDiv = Math.ceil(num/7);
    var minAns = (minDiv * 7).toString();
    var maxAns = (maxDiv * 7).toString();

    var minDiff = 0;
    for (var j = 0 ; j<minAns.length ; j++) {
      if (minAns[j] !== num.toString()[j]) {
        ++minDiff;
      }
    }

    var maxDiff = 0;
    for (var j = 0 ; j<maxAns.length ; j++) {
      if (maxAns[j] !== num.toString()[j]) {
        ++maxDiff;
      }
    }

    if (minDiff <= maxDiff) {
      print(minAns);
    }
    else {
      print(maxAns);
    }

  }
}

var n = parseInt(readline())
print(n);

for (var i = 0 ; i<n ; i++) {
  var num = parseInt(readline());
  // print(num);
  if (num % 7 === 0) {
    print(num);
  }
  else {
    var minDiv = Math.floor(num/7);
    var maxDiv = Math.ceil(num/7);
    var minAns = (minDiv * 7).toString();
    var maxAns = (maxDiv * 7).toString();

    var minDiff = 0;
    for (var j = 0 ; j<minAns.length ; j++) {
      if (minAns[j] !== num.toString()[j]) {
        ++minDiff;
      }
    }

    var maxDiff = 0;
    for (var j = 0 ; j<maxAns.length ; j++) {
      if (maxAns[j] !== num.toString()[j]) {
        ++maxDiff;
      }
    }

    if (minDiff <= maxDiff) {
      print(minDiv * 7);
    }
    else {
      print(maxDiv * 7);
    }

  }
}
print()

var n = parseInt(readline())
print(n);

for (var i = 0 ; i<n ; i++) {
  var num = parseInt(readline());
  // print(num);
  if (num % 7 === 0) {
    print(num);
  }
  else {
    var minDiv = Math.floor(num/7);
    var maxDiv = Math.ceil(num/7);
    print(minDiv);
    print(maxDiv);
  }
}

var n = parseInt(readline())
print(n);

for (var i = 0 ; i<n ; i++) {
  var num = parseInt(readline());
  print(num);
}

var n = parseInt(readline())
print(n);

for (var i = 0 ; i<n ; i++) {
  print(5);
}

var n = parseInt(readline())
print(n);

// for (let i = 0 ; i<n ; i++) {
//   var num = readline();
//   print(num);
// }

var numbers = readline().split(" ").map(function(x) { return parseInt(x); });
print(numbers);

var a=parseInt(readline());
for(var i=0;i<a;i++){
    var s=parseInt(readline());
    if(s%7===0){
        print(s);
    }
    else{
        var res=parseInt(s/7);
        var ans=(res+1)*7;
        print(ans);

    }
}

a=readline();
while(a-->0){
    s=readline();
    mini=100000;
    if(s%7===0){
        print(s);
    }
    else{
        res=parseInt(s/7);
        ans=(res+1)*7;
        print(s);

    }
}

var a=parseInt(readline());
for(var i=0;i<a;i++){
    var s=parseInt(readline());
    if(s%7===0){
        print(s);
    }
    else{
        var res=s/7;
        var ans=(res+1)*7;
        print(ans);

    }
}

a=readline();
while(a>0){
    s=readline();
    mini=100000;
    if(s%7===0){
        print(s);
    }
    else{
        res=s/7;
        ans=(res+1)*7;
        print(s);

    a-=1}
}

a=readline();
while(a-->0){
    s=readline();
    mini=100000;
    if(s%7===0){
        print(s);
    }
    else{
        res=s/7;
        ans=(res+1)*7;
        print(s);

    }
}

var n=parseInt(readline())
for(i=0;i<n;i++)
{var number=parseInt(readline());
var check=number%7
if(check<4)result=number-check
else{
    result=number+(7-check)
}
if(result<10)result=14
if(result>999)result=994
print(result)}

var n=parseInt(readline())
for(i=0;i<n;i++)
{var number=parseInt(readline());
var check=number%7
if(check<4)result=number-check
else{
    result=number+(7-check)
}
print(result)}

var n=parseInt(readline())
for(i=0;i<n;i++)
{var number=parseInt(readline());
var check=parseInt(number/10)*10;
var result=parseInt(number/7)*7;
if(result<10)result=14
print(result)}

var n=parseInt(readline())
for(i=0;i<n;i++)
{var number=parseInt(readline());
var check=parseInt(number/10)*10;
var result=parseInt(number/7)*7;
print(result)}

var t = readline();
for(var i = 0 ; i < t ; i++){
    var n = readline();
    if(n % 7 === 0){
        print(n);
    }
    else{
        if( (parseInt(n % 10) + parseInt(7 - n % 7)) < 10 ){
            print(parseInt(n) + parseInt(7 - n % 7));
        }
        else{
            print(parseInt(n) - parseInt(n % 10));
        }
    }
}

var t = readline();
for(var i = 0 ; i < t ; i++){
    var n = readline();
    if(n % 7 === 0){
        print(n);
    }
    else{
        while(n % 7 !== 0){
            n++;
        }
        print(n);
    }
}

t= parseInt(readline()) ;
while (t--) {
	n =  parseInt(readline()) ;
	if (n<10) {
	    print(7) ;
	    continue ;
	}
	if (n%7==0) {
	print(n) ;
	}else {
	n/=10 ;
	n*= 10 ;
	ans =  n;
	for (i = 0 ; i <= 9 ; i ++ )
	{
		nw = n + i ;
		if (nw%7 == 0 ) {
		ans = nw;
		break ;
		}
	}
	print(ans) ;
	}

	}

t= parseInt(readline()) ;
while (t--) {
	n =  parseInt(readline()) ;
	if (n%7==0) {
	print(n) ;
	}else {
	n/=10 ;
	n*= 10 ;
	ans =  0;
	for (i = 0 ; i <= 9 ; i ++ )
	{
		nw = n + i ;
		if (nw%7 == 0 ) {
		ans = nw;
		break ;
		}
	}
	print(ans) ;
	}

	}


You are given an array $$$a$$$ of $$$n$$$ integers. Find the number of pairs $$$(i, j)$$$ ($$$1 \le i < j \le n$$$) where the sum of $$$a_i + a_j$$$ is greater than or equal to $$$l$$$ and less than or equal to $$$r$$$ (that is, $$$l \le a_i + a_j \le r$$$).For example, if $$$n = 3$$$, $$$a = [5, 1, 2]$$$, $$$l = 4$$$ and $$$r = 7$$$, then two pairs are suitable:   $$$i=1$$$ and $$$j=2$$$ ($$$4 \le 5 + 1 \le 7$$$);  $$$i=1$$$ and $$$j=3$$$ ($$$4 \le 5 + 2 \le 7$$$).

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. The first line of each test case contains three integers $$$n, l, r$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le l \le r \le 10^9$$$) — the length of the array and the limits on the sum in the pair. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ overall test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output a single integer — the number of index pairs $$$(i, j)$$$ ($$$i < j$$$), such that $$$l \le a_i + a_j \le r$$$.

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

let t = +readline();

while(t--){
    let [n, l, r] = readline().split(' ').map(x=>+x);
    let arr = readline().split(' ').map(x=>+x);
    console.log(`${solve(arr,n,l,r)}`);
}

function solve(nums, n, l, r){
    let minIdx, maxIdx, sum, mid, left, right;
    let result = 0;
    nums.sort((a, b)=> a-b);

    for(let i = n-1; i >= 0; i--){
        left = -1;
        right = i;
        while((right-left)>1){
            mid = Math.floor((right + left)/2);
            sum = nums[mid] + nums[i];
            if(sum >= l && sum <= r) right = mid;
            else if(sum < l) left = mid;
            else if(sum > r) right = mid;
        }
        if(right !== i){
            minIdx = right;
            left = -1;
            right = i;
            while((right-left)>1){
                mid = Math.floor((right+left)/2);
                sum = nums[mid] + nums[i];
                if(sum >= l && sum <= r) left = mid;
                else if(sum > r) right = mid;
                else  if(sum < l) left = mid;
            }
            maxIdx = left;
            result += maxIdx - minIdx +1;
        }
    }

    return result;
}

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

let t = +readline()
while(t--){
    let [n,l,r] = readline().split(' ').map(x=>+x);
    let arr = readline().split(' ').map(x=>+x);
    console.log(`${solve(arr,n,l,r)}`);
}
function solve(nums, n, l, r){
    let result = 0;
    let mid, min, max,sum, left, right;
    nums.sort((a,b)=>a-b);
    for(let i = n-1; i >= 0; i--){
        left = -1;
        right = i;

        while((right - left)>1){
            mid = Math.floor((left+right)/2);
            sum = nums[mid] + nums[i];
            if(sum >= l && sum <= r) right = mid;
            else if(sum < l) left = mid;
            else if(sum > r) right = mid;
        }
        if(right !== i){
            minIdx = right;
            left = -1;
            right = i;
            while((right-left)>1){
                mid = Math.floor((left+right)/2);
                sum = nums[mid] + nums[i];
                if(sum >= l && sum <= r) left = mid;
                else if(sum < l) left = mid;
                else if(sum > r) right = mid;
            }
            maxIdx = left;
            result += maxIdx - minIdx +1;
        }
    }
    return result;
}

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

let currentline = 0;
function readline(){
    return input[currentline++];
}

let t = +readline();

while(t--){
    let [n, l, r] = readline().split(' ').map(x => +x);
    let arr = readline().split(' ').map(x => +x);
    console.log(`${solve(arr, n, l, r)}`)
}

function solve(nums, n, l, r){
    let i, j, mid, result=0, temp, ll, rr, lll;
    nums.sort((a,b)=>a-b);
    for(i = n-1; i >= 0; i--){
        rr = i;
        ll = -1;

        while((rr-ll)>1){
            mid = Math.floor((ll+rr)/2);
            temp = nums[mid] + nums[i];
            if(temp >= l && temp <= r) rr = mid;
            else if(temp > r) rr = mid;
            else if(temp < l) ll = mid;
        }
        if(rr !== i){
            lll = rr;
            rr = i;
            ll = -1;
            while((rr-ll)>1){
                mid = Math.floor((ll+rr)/2);
                temp = nums[mid] + nums[i];
                if(temp >= l && temp <= r) ll = mid;
                else if(temp > r) rr = mid;
                else if(temp < l) ll = mid;
            }

            result += ll - lll+1;
        }
    }

    return result;
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));
// a sample creepy solution
function main () {
	let T = rn();
	while (T--) {
		const [n, l, r] = rna();
		const a = rna();

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

		function countBelow (cutoff) {
			let tot = 0;
			for (let i = 0, j = n-1; i < n-1; i++) {
				while (i < j && a[i] + a[j] > cutoff)
					j--;
				tot += Math.max(0, j - i);
			}
			return tot;
		}

		console.log(countBelow(r) - countBelow(l-1));
	}
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		const [n, l, r] = rna();
		const a = rna();

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

		function lowerBound (l, r, x) {
			while (l < r) {
				mid = l + r >> 1;
				if (a[mid] >= x)
					r = mid;
				else
					l = mid + 1;
			}
			return a[l] >= x ? l : 0;
		}

		function upperBound (l, r, x) {
			while (l < r) {
				mid = l + r + 1 >> 1;
				if (a[mid] <= x)
					l = mid;
				else
					r = mid-1;
			}
			return a[l] <= x ? l : 0;
		}

		let ans = 0;
		for  (let i = 0; i < n-1; i++) {
			const ub = upperBound(i+1, n-1, r - a[i]);
			const lb = lowerBound(i+1, n-1, l - a[i]);
			if (ub && lb)
				ans += ub - lb + 1;
		}

		console.log(ans);
	}
}

var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

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

function div(a, b) {
   return Math.floor(a / b);
}

// Индекс первого в отсотрированном arr на промежутке [l, r), который строго больше value
function bins(arr, value, l, r) {
   if (arr[l] > value) {
      return l;
   }
   if (arr[r - 1] <= value) {
      return r;
   }
   while (r - l > 1) {
      var m = ((r + l) >> 1) - ((r + l + 1) & 1);
      if (arr[m] <= value) {
         l = m + 1;
         continue;
      }
      r = m + 1;
   }
   return l;
}

function solve() {
   var nlr = readArray(Number);
   var n = nlr[0];
   var l = nlr[1];
   var r = nlr[2];
   var arr = readArray(Number);
   arr.sort(sortF);
   var ans = 0;
   for (var i = 1; i < n; i++) {
      var li = bins(arr, l - arr[i] - 1, 0, i);
      var ri = bins(arr, r - arr[i], 0, i);
      ans += ri - li;
   }
   write(ans);
}

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

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

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

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

   var inTextName;
   var outTextName;

   var needWriteFile = false;

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

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

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

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

function main(){
	var nlr, n, l, r, arr;
	var sum, result;
	var i, j, k;

	var numberOfLines = parseInt(readline(), 10);

	for (i = 0; i < numberOfLines; i++) {
		nlr = readNumArray();
		n = nlr[0];
		l = nlr[1];
		r = nlr[2];

		arr = readNumArray();

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

		result = 0;

		for (j = 1; j < n; j++) {
			var ll = l - arr[j];
			var rr = r - arr[j];
			var lb = lowBound(arr, ll, 0, j-1);
			var ub = upperBound(arr, rr, 0, j-1);

			if(lb!=-1 && ub!=-1)
			{
				result = Math.max(ub - lb + 1, 0) + result;
			}

		}

		print(result);
	}
}

function lowBound(arr, x, i, j) {
	var l = i;
	var r = j;
	var lb = -1;

	var m;

	while(l <= r){
		m = Math.ceil((l + r) / 2);
		if(arr[m] >= x) {
			lb = m;
			r = m - 1;
		} else {
			l = m + 1;
		}
	}
	return lb;

}

function upperBound(arr, x, i, j) {
	var l = i;
	var r = j;
	var ans = -1;

	var m;

	while(l <= r){
		m = Math.ceil((l + r) / 2);
		if(arr[m] <= x) {
			ans = m;
			l = m + 1;
		} else {
			r = m - 1;
		}
	}
	return ans;

}

main();

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

function main(){
    var nlr, n, l, r, arr;
    var sum, result;
    var i, j, k;

    var numberOfLines = parseInt(readline(), 10);

    for (i = 0; i < numberOfLines; i++) {
        nlr = readNumArray();
        n = nlr[0];
        l = nlr[1];
        r = nlr[2];

        arr = readNumArray();

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

        result = 0;

        for(j = 1; j < arr.length; j +=1){
            var lb = l - arr[j];
            var ub = r - arr[j];

            var lower = lowerbound(arr, lb, -1, j);
            var upper = upperbound(arr, ub, -1, j);

            if(lower !== -1 && upper !== -1){
                result = Math.max(upper - lower + 1, 0) + result;
            }
        }
        print(result);

    }
}

const lowerbound = (arr, x, i, j) => {
    var f = i;
    var l = j;
    var lb = -1;

    while(l - f > 1){
        mid = Math.ceil((l + f) / 2);
        if(arr[mid] >= x){
            lb = mid;
            l = mid
        }else{
            f = mid;
        }

    }
    return lb;
};

const upperbound = (arr, x, i, j) => {
    var f = i;
    var l = j;
    var ub = -1;

    while(l - f > 1){
        mid = Math.ceil((l + f) / 2);
        if(arr[mid] <= x){
            ub = mid;
            f = mid
        }else{
            l = mid;
        }

    }
    return ub;

};

main();

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

let currentline = 0;
function readline(){
    return input[currentline++];
}

let t = +readline();

while(t--){
    let [n, l, r] = readline().split(' ').map(x => +x);
    let arr = readline().split(' ').map(x => +x);
    console.log(`${solve(arr, n, l, r)}`)
}

function solve(nums, n, l, r){
    let result = 0;
    nums.sort((a,b)=>a-b);
    let end = n-1;
    let start = 0;
    let maxIdx;
    let minIdx;

    while(nums[end] > r && end >= 0) end--;
    for(let i = end; i >= 0; i--){
        let max = r-nums[i];
        let min = nums[i]-l;
        let left = 0;
        let right = i-1
        if(min < 0 && nums[i] < max){
            if(min + nums[i-1] < 0 || nums[i] + nums[i-1]< max)break;
            result++;
            continue;
        };
        // console.log({min},{max},{right})
        if(nums[right] <=  max){
            maxIdx = right;
        }else{
        //look for max
            while(left < right){
                let mid = Math.floor((left+right)/2)
                if(nums[mid] <= max && nums[mid+1] <= max) left = mid+1;
                else right = mid-1
            }
            maxIdx = left;
        }
        left = 0;
        right = end-1
        if(nums[left] >= min){
            minIdx = left;
        }else{
            while(left < right){
                let mid = Math.floor((left+right)/2)
                if(nums[mid] >= min && nums[mid-1] >= min) right = mid-1;
                else left = mid+1;
            }
            minIdx = right;
        }
        // console.log({minIdx},{maxIdx})
        result += maxIdx-minIdx+1;
    }

    return result;
}

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

function main(){
	var nlr, n, l, r, arr;
	var sum, result;
	var i, j, k;

	var numberOfLines = parseInt(readline(), 10);

	for (i = 0; i < numberOfLines; i++) {
		nlr = readNumArray();
		n = nlr[0];
		l = nlr[1];
		r = nlr[2];

		arr = readNumArray();

		arr.sort();

		result = 0;

		for (j = 0; j < n -1; j++) {
			if(arr[j] > r) {
				break;
			}

			for (k = j + 1; k < n; k++){
				sum = arr[j] + arr[k];

				if (l <= sum && sum <= r) {
					result++;
				}
			}
		}
		print(result);
	}
}

main();

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

function main(){
	var nlr, n, l, r, arr;
	var sum, result;
	var i, j, k;

	var numberOfLines = parseInt(readline(), 10);

	for (i = 0; i < numberOfLines; i++) {
		nlr = readNumArray();
		n = nlr[0];
		l = nlr[1];
		r = nlr[2];

		arr = readNumArray();

		arr.sort();

		result = 0;

		for (j = 0; j < n -1; j++) {
			if(arr[j] > r) {
				break;
			}

			for (k = j + 1; k < n; k++){
				sum = arr[j] + arr[k];

				if (sum > r) {
					break;
				} else if (l <= sum && sum <= r) {
					result++;
				}
			}
		}
		print(result);
	}
}

main();

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

function main(){
	var nlr, n, l, r, arr;
	var sum, result;
	var i, j, k;

	var numberOfLines = parseInt(readline(), 10);

	for (i = 0; i < numberOfLines; i++) {
		nlr = readNumArray();
		n = nlr[0];
		l = nlr[1];
		r = nlr[2];

		arr = readNumArray();

		arr.sort();

		result = 0;

		for (j = 0; j < n -1; j++) {
			if(arr[j] >= r) {
				break;
			}

			for (k = j + 1; k < n; k++){
				sum = arr[j] + arr[k];

				if (sum > r) {
					break;
				} else if (l <= sum && sum <= r) {
					result++;
				}
			}
		}
		print(result);
	}
}

main();

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

function main(){
	var nlr, n, l, r, arr;
	var sum, result;
	var i, j, k;

	var numberOfLines = parseInt(readline(), 10);

	for (i = 0; i < numberOfLines; i++) {
		nlr = readNumArray();
		n = nlr[0];
		l = nlr[1];
		r = nlr[2];

		arr = readNumArray();

		arr.sort();

		result = 0;

		for (j = 0; j < n -1; j++) {
			if(arr[j] >= r) {
				break;
			}

			if(arr[j+1] >= r){
				continue;
			}

			for (k = j + 1; k < n; k++){

				sum = arr[j] + arr[k];

				if(l <= sum && sum <= r) {
					result++;
				}
			}
		}
		print(result);
	}
}

main();

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

function main(){
	var nlr, n, l, r, arr;
	var sum, result;
	var i, j, k;

	var numberOfLines = parseInt(readline(), 10);

	for (i = 0; i < numberOfLines; i++) {
		nlr = readNumArray();
		n = nlr[0];
		l = nlr[1];
		r = nlr[2];

		arr = readNumArray();

		arr.sort();

		result = 0;

		for (j = 0; j < n -1; j++) {
			if(arr[j] >= r) {
				break;
			}

			for (k = j + 1; k < n; k++){

				sum = arr[j] + arr[k];
				if(sum > r) {
					break;
				}

				if(l <= sum && sum <= r) {
					result++;
				}
			}
		}
		print(result);
	}
}

main();

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

function main(){
	var nlr, n, l, r, arr;
	var sum, result;
	var i, j, k;

	var numberOfLines = parseInt(readline(), 10);

	for (i = 0; i < numberOfLines; i++) {
		nlr = readNumArray();
		n = nlr[0];
		l = nlr[1];
		r = nlr[2];

		arr = readNumArray();

		arr.sort();

		result = 0;

		for (j = 0; j < n -1; j++) {
			if(arr[j] >= r) {
				break;
			}

			if(arr[j+1] >= r){
				break;
			}

			for (k = j + 1; k < n; k++){

				sum = arr[j] + arr[k];
				if(sum > r) {
					break;
				}

				if(l <= sum && sum <= r) {
					result++;
				}
			}
		}
		print(result);
	}
}

main();


Luyi has n circles on the plane. The i-th circle is centered at (xi, yi). At the time zero circles start to grow simultaneously. In other words, the radius of each circle at time t (t > 0) is equal to t. The circles are drawn as black discs on an infinite white plane. So at each moment the plane consists of several black and white regions. Note that the circles may overlap while growing.  We define a hole as a closed, connected white region. For instance, the figure contains two holes shown by red border. During growing some holes may be created and it is easy to see that each created hole will disappear eventually. Luyi asks you to find moment of time such that the last hole disappears. In other words, you should find the first moment such that no hole can be seen after that.

The first line of the input contains integer n (1 ≤ n ≤ 100). Each of the next n lines contains two integers xi and yi ( - 104 ≤ xi, yi ≤ 104), indicating the location of i-th circle. It's guaranteed that no two circles are centered at the same point.

Print the moment where the last hole disappears. If there exists no moment in which we can find holes print -1. The answer will be considered correct if the absolute or relative error does not exceed 10 - 4.

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

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

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(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

/*/====================
var fs = require('fs');

fs.readFile('input.txt', 'utf8', function(err, arr) {
    main(arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, '')))
})
//====================*/

function main(input) {
    G=new Object()
    n=+input[0]
    X=[]
    Y=[]
    for (i=1;i<=n;i++){
        a=input[i].split(' ')
        x=+a[0]
        y=+a[1]
        if (G[x]===undefined)
            G[x]=new Object
        G[x][y]=i-1
        X.push(x)
        Y.push(y)
    }

    ans=-1

    function C(a,b,c){
        ya=Y[a]
        xa=X[a]
        yb=Y[b]
        xb=X[b]
        yc=Y[c]
        xc=X[c]
        x0=-0.5*(ya*(xb*xb+yb*yb-xc*xc-yc*yc)+yb*(xc*xc+yc*yc-xa*xa-ya*ya)+yc*(xa*xa+ya*ya-xb*xb-yb*yb))/(xa*(yb-yc)+xb*(yc-ya)+xc*(ya-yb))
        y0=+0.5*(xa*(xb*xb+yb*yb-xc*xc-yc*yc)+xb*(xc*xc+yc*yc-xa*xa-ya*ya)+xc*(xa*xa+ya*ya-xb*xb-yb*yb))/(xa*(yb-yc)+xb*(yc-ya)+xc*(ya-yb))
        return {x:x0,y:y0}
    }

    function O(a,b,c){
        x1=X[b]-X[a]
        y1=Y[b]-Y[a]
        x2=X[c]-X[a]
        y2=Y[c]-Y[a]
        return x1*x2+y1*y2>0
    }

    function R(a,b,c){
        x1=X[b]-X[a]
        y1=Y[b]-Y[a]
        x2=X[c]-X[a]
        y2=Y[c]-Y[a]
        return x1*x2+y1*y2==0
    }

    function hypot(a,b){
        return Math.sqrt(a*a+b*b)
    }
    function hypot2(a,b){
        return (a*a+b*b)
    }

    function doR(a,b,c){
        dx=X[b]-X[a]
        dy=Y[b]-Y[a]
        x2=X[c]+dx
        y2=Y[c]+dy
        if (G[x2]!=undefined)
            if (G[x2][y2]!=undefined){
                x0=(X[a]+x2)/2.0
                y0=(Y[a]+y2)/2.0
                d=hypot(X[b]-X[c],Y[b]-Y[c])/2
                for (z=0;z<n;z++)
                {
                    if (z!=a&&z!=b&&z!=c&&z!=G[x2][y2])
                    {
                        if (hypot(x0-X[z],y0-Y[z])<d){
                            d=-2
                        }
                    }
                }
                if (d>ans)
                   ans=d
            }
    }

    for (i=0;i<n;i++){
        for (j=i+1;j<n;j++){
            for (k=j+1;k<n;k++){

                if (O(i,j,k)&&O(j,i,k)&&O(k,i,j))
                {
                    pt=C(i,j,k)
                    d=hypot(pt.x-X[i],pt.y-Y[i])
                    for (z=0;z<n;z++)
                    {
                        if (z!=i&&z!=j&&z!=k)
                        {
                            if (hypot(pt.x-X[z],pt.y-Y[z])<d){
                                d=-2
                            }
                        }
                    }
                    if (d>ans)
                        ans=d
                }
                if (R(i,j,k)&&hypot(X[j]-X[i],Y[j]-Y[i])==hypot(X[k]-X[i],Y[k]-Y[i])){
                    doR(i,j,k)
                }
                if (R(j,i,k)&&hypot(X[i]-X[j],Y[i]-Y[j])==hypot(X[k]-X[j],Y[k]-Y[j])){
                    doR(j,i,k)
                }
                if (R(k,i,j)&&hypot(X[j]-X[k],Y[j]-Y[k])==hypot(X[i]-X[k],Y[i]-Y[k])){
                    doR(k,i,j)
                }
            }
        }
    }
    wr(ans)

}

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

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

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(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

/*/====================
var fs = require('fs');

fs.readFile('input.txt', 'utf8', function(err, arr) {
    main(arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, '')))
})
//====================*/

function main(input) {
    G=new Object()
    n=+input[0]
    X=[]
    Y=[]
    for (i=1;i<=n;i++){
        a=input[i].split(' ')
        x=+a[0]
        y=+a[1]
        if (G[x]===undefined)
            G[x]=new Object
        G[x][y]=i-1
        X.push(x)
        Y.push(y)
    }

    ans=-1

    function C(a,b,c){
        ya=Y[a]
        xa=X[a]
        yb=Y[b]
        xb=X[b]
        yc=Y[c]
        xc=X[c]
        x0=-0.5*(ya*(xb*xb+yb*yb-xc*xc-yc*yc)+yb*(xc*xc+yc*yc-xa*xa-ya*ya)+yc*(xa*xa+ya*ya-xb*xb-yb*yb))/(xa*(yb-yc)+xb*(yc-ya)+xc*(ya-yb))
        y0=+0.5*(xa*(xb*xb+yb*yb-xc*xc-yc*yc)+xb*(xc*xc+yc*yc-xa*xa-ya*ya)+xc*(xa*xa+ya*ya-xb*xb-yb*yb))/(xa*(yb-yc)+xb*(yc-ya)+xc*(ya-yb))
        return {x:x0,y:y0}
    }

    function O(a,b,c){
        x1=X[b]-X[a]
        y1=Y[b]-Y[a]
        x2=X[c]-X[a]
        y2=Y[c]-Y[a]
        return x1*x2+y1*y2>0
    }

    function R(a,b,c){
        x1=X[b]-X[a]
        y1=Y[b]-Y[a]
        x2=X[c]-X[a]
        y2=Y[c]-Y[a]
        return x1*x2+y1*y2==0
    }

    function hypot(a,b){
        return Math.sqrt(a*a+b*b)
    }
    function hypot2(a,b){
        return (a*a+b*b)
    }

    function doR(a,b,c){
        dx=X[b]-X[a]
        dy=Y[b]-Y[a]
        x2=X[c]+dx
        y2=Y[c]+dy
        if (G[x2]!=undefined)
            if (G[x2][y2]!=undefined){
                x0=(X[a]+x2)/2.0
                y0=(Y[a]+y2)/2.0
                d=hypot(X[b]-X[c],Y[b]-Y[c])/2
                for (z=0;z<n;z++)
                {
                    if (z!=a&&z!=b&&z!=c&&z!=G[x2][y2])
                    {
                        wr(i,j,k,G[x2][y2],z)
                        if (hypot(x0-X[z],y0-Y[z])<d){
                            d=-2
                        }
                    }
                }
                if (d>ans)
                   ans=d
            }
    }

    for (i=0;i<n;i++){
        for (j=i+1;j<n;j++){
            for (k=j+1;k<n;k++){

                if (O(i,j,k)&&O(j,i,k)&&O(k,i,j))
                {
                    pt=C(i,j,k)
                    d=hypot(pt.x-X[i],pt.y-Y[i])
                    for (z=0;z<n;z++)
                    {
                        if (z!=i&&z!=j&&z!=k)
                        {
                            if (hypot(pt.x-X[z],pt.y-Y[z])<d){
                                d=-2
                            }
                        }
                    }
                    if (d>ans)
                        ans=d
                }
                if (R(i,j,k)&&hypot(X[j]-X[i],Y[j]-Y[i])==hypot(X[k]-X[i],Y[k]-Y[i])){
                    doR(i,j,k)
                }
                if (R(j,i,k)&&hypot(X[i]-X[j],Y[i]-Y[j])==hypot(X[k]-X[j],Y[k]-Y[j])){
                    doR(j,i,k)
                }
                if (R(k,i,j)&&hypot(X[j]-X[k],Y[j]-Y[k])==hypot(X[i]-X[k],Y[i]-Y[k])){
                    doR(k,i,j)
                }
            }
        }
    }
    wr(ans)

}


Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are n forms of worms. Worms of these forms have lengths a1, a2, ..., an. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of lengths of the other two forms. Help him to do this.

The first line contains integer n (3 ≤ n ≤ 100) — amount of worm's forms. The second line contains n space-separated integers ai (1 ≤ ai ≤ 1000) — lengths of worms of each form.

Output 3 distinct integers i j k (1 ≤ i, j, k ≤ n) — such indexes of worm's forms that ai = aj + ak. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that aj = ak.

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 n = parseInt(readline());
	var worms = tokenizeIntegers(readline());

	var wormHash = {};
	for (var i = 0; i < n; ++i) {
		wormHash[worms[i]] = i;
	}

	for (var i = 0; i < n; ++i) {
		for (var j = i+1; j < n; ++j) {
			var k = wormHash[worms[i]+worms[j]];
			if (k != undefined) {
				print([k+1, i+1, j+1].join(" "));
				return;
			}
		}
	}

	print(-1);
}

main();

'use strict'

let N = +readline()
let lll = readline().split(' ').map(v => parseInt(v))

let res = (function () {
  for (let i = 0; i < N - 1; i++) {
    for (let j = i + 1; j < N; j++) {
      let k = lll.indexOf(lll[i] + lll[j])
      if (~k) return [i, j, k]
    }
  }
})()

print (res ? ++res[2] + ' ' + ++res[1] + ' ' + ++res[0] : -1)

const readline = require('readline');

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

var ans = "-1", n = -1;

rl.on('line', (input) => {
    if (n == -1)
        n = parseInt(input);
    else {

        let cont = input.split(' ').map(item => parseInt(item));

        for (let i = 0; i < n; i++) {
            for (let j = 0; j < n; j++) {
                if (i == j)
                    continue;
                for (let k = 0; k < n; k++) {
                    if (k == i || k == j)
                        continue;
                    if (cont[i] == cont[j] + cont[k]) {
                        ans = (i + 1) + " " + (j + 1) + " " + (k + 1);
                        break;
                    }

                }
                if (ans != "-1")
                    break;
            }
            if (ans != "-1")
                break;

        }
        console.log(ans);
        rl.close();
    }

});

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var ans = "-1";
var indicator = 0, N;
var needBreak = false;
rl.on('line', (input) => {

    if (indicator == 0) {
        N = parseInt(input);
        indicator++;
    }
    else {
        var cont = input.split(' ').map(item => parseInt(item));
        for (let i = 0; i < N; i++) {
            for (let j = 0; j < N; j++) {
                if (j == i)
                    continue;
                for (let k = 0; k < N; k++) {
                    if (k == i || k == j)
                        continue;
                    if (cont[i] == cont[j] + cont[k]) {
                        //console.log("cont[%d]=%d  cont[%d]=%d cont[%d]=%d",i,cont[i],j,cont[j],k,cont[k]);
                        ans = (i + 1).toString() + " " + (j + 1).toString() + " " + (k + 1).toString();
                        needBreak = true;
                        break;
                    }
                }
                if (needBreak)
                    break;
            }
            if (needBreak)
                break;
        }
        console.log(ans);
        rl.close();
    }

});

process.stdin.setEncoding('ASCII');
let string = '';
process.stdin.on('data', (data) => string += data);

const main = ( input ) => {
    let n = Number(input[0]);
    let arr = input[1].split(' ').map(Number);

    let freq = {};
    for (let i = 0; i < arr.length; ++i) freq[arr[i]] = i + 1;

    for (let i = 0; i < arr.length; ++i) {
        for (let j = 0; j < arr.length; ++j) {
            if (i == j) continue;

            let val = arr[i] + arr[j];
            if ( freq[val] !== undefined ) {
                console.log(freq[val], i + 1, j + 1);
                return;
            }
        }
    }

    console.log(-1);
}

process.stdin.on('end', () => main(string.trim().split('\n')));

'use strict'

let N = +readline()
let lll = readline().split(' ').map(v => parseInt(v)).sort((a, b) => a - b)

let res = (function () {
  for (let i = 0; i < N - 1; i++) {
    for (let j = i + 1; j < N; j++) {
      let k = lll.indexOf(lll[i] + lll[j])
      if (~k) return [i, j, k]
    }
  }
})()

print (res ? ++res[2] + ' ' + ++res[1] + ' ' + ++ res[0] : -1)


There are $$$n$$$ friends who want to give gifts for the New Year to each other. Each friend should give exactly one gift and receive exactly one gift. The friend cannot give the gift to himself.For each friend the value $$$f_i$$$ is known: it is either $$$f_i = 0$$$ if the $$$i$$$-th friend doesn't know whom he wants to give the gift to or $$$1 \le f_i \le n$$$ if the $$$i$$$-th friend wants to give the gift to the friend $$$f_i$$$.You want to fill in the unknown values ($$$f_i = 0$$$) in such a way that each friend gives exactly one gift and receives exactly one gift and there is no friend who gives the gift to himself. It is guaranteed that the initial information isn't contradictory.If there are several answers, you can print any.

The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of friends. The second line of the input contains $$$n$$$ integers $$$f_1, f_2, \dots, f_n$$$ ($$$0 \le f_i \le n$$$, $$$f_i \ne i$$$, all $$$f_i \ne 0$$$ are distinct), where $$$f_i$$$ is the either $$$f_i = 0$$$ if the $$$i$$$-th friend doesn't know whom he wants to give the gift to or $$$1 \le f_i \le n$$$ if the $$$i$$$-th friend wants to give the gift to the friend $$$f_i$$$. It is also guaranteed that there is at least two values $$$f_i = 0$$$.

Print $$$n$$$ integers $$$nf_1, nf_2, \dots, nf_n$$$, where $$$nf_i$$$ should be equal to $$$f_i$$$ if $$$f_i \ne 0$$$ or the number of friend whom the $$$i$$$-th friend wants to give the gift to. All values $$$nf_i$$$ should be distinct, $$$nf_i$$$ cannot be equal to $$$i$$$. Each friend gives exactly one gift and receives exactly one gift and there is no friend who gives the gift to himself. If there are several answers, you can print any.

'use strict'

const problem = (n, f) => {
    let t = new Set(f);
    const g = Array.from({ length: n }, (_, i) => i + 1).filter(i => !t.has(i));
    for (let i = 0, j, prev; i < n; i++) {
        if (f[i]) continue;
        j = g.pop();
        if (j === (i + 1)) {
            if (prev === undefined) { g.push(j); j = g.shift(); }
            else { const t = f[prev]; f[prev] = j; j = t; };
        }

        f[i] = j;
        prev = i;
    }
    return f;
}

print(problem(+readline(), readline().split(' ').map(Number)).join(' '));

'use strict'

const problem = (n, f) => {
    f = f.map(i => i - 1);
    const F = new Set(f);
    const g = [ ...Array(n).keys() ].filter(i => !F.has(i));
    let prev;
    for (let i = 0; i < n; i++) {
        if (f[i] !== -1) continue;
        let j = g.pop();
        if (j === i) {
            if (prev === undefined) { g.push(j); j = g[0]; }
            else { const t = f[prev]; f[prev] = j; j = t };
        }

        f[i] = j;
        prev = i;
    }
    return f.map(i => i + 1).join(' ');
}

print(problem(+readline(), readline().split(' ').map(Number)));

"use strict";

let friendsNumber = +readline(); //!
let wishString = readline(); //!
let arrayOfWishNumbers = wishString.split(" ").map(function(item) {
	return +item;
});

let sortedWish = [];
let zeroIndexes = [];
let zeroValues = [];

for (let i = 0; i < arrayOfWishNumbers.length; i++) {
	if (arrayOfWishNumbers[i] === 0) {
		zeroIndexes.push(i);
	}
	sortedWish[i] = 0;
}

for (let i = 0; i < sortedWish.length; i++) {
	if (arrayOfWishNumbers[i] !== 0) {
		sortedWish[arrayOfWishNumbers[i] - 1] = arrayOfWishNumbers[i];
	}
}

for (let i = 0; i < sortedWish.length; i++) {
	if (sortedWish[i] === 0) {
		zeroValues.push(i + 1);
	}
}

let goodSortedZeroValues = [];
//

// zeroValues = zeroValues.reverse();
// if (zeroValues.length % 2 == 1) {
// 	let tempValue = zeroValues[Math.floor(zeroValues.length / 2)];
// 	zeroValues[Math.floor(zeroValues.length / 2)] = zeroValues[Math.floor(zeroValues.length / 2) + 1];
// 	zeroValues[Math.floor(zeroValues.length / 2) + 1] = tempValue;
// }

// let badSortedValues = [];

// for (let i = 0; i < zeroValues.length; i++) {
// 	if (zeroValues[i] = zeroIndexes[i] + 1) {
// 		badSortedValues.push(zeroValues[i]);
// 	}
// }

// for (let i = 0; i < badSortedValues.length; i++) {
// 	for (let j = 0; j < zeroValues.length; j++) {
// 		if (zeroValues[j] === badSortedValues[i]) {
// 			let tempValue = zeroValues[j];
// 			for (let k = 0; k < zeroValues.length; k++) {
// 				if (zeroValues[k] !== 0;)
// 			}
// 		}
// 	}
// }

for (let i = 0; i < zeroValues.length; i++) {
	if (zeroValues[i] === zeroIndexes[i] + 1) {
		for (let j = 0; j < zeroValues.length; j++) {
			let tempValue = zeroValues[i];
			if (zeroValues[i] !== zeroValues[j]) {
				zeroValues[i] = zeroValues[j];
				zeroValues[j] = tempValue;
				break;
			}
		}
	}
}

//
if (zeroValues.length === zeroIndexes.length) {

	for (let i = 0; i < zeroIndexes.length; i++) {
		arrayOfWishNumbers[zeroIndexes[i]] = zeroValues[i];
	}
}

let result = arrayOfWishNumbers.join(" ");

print(result);

'use strict'

const problem = (n, f) => {
    f = f.map(i => i - 1);
    const g = [ ...Array(n).keys() ].filter(i => !f.includes(i)); // без подарка
    let prev;
    for (let i = 0; i < n; i++) {
        if (f[i] !== -1) continue;
        let j = g.pop();
        if (j === i) {
            if (prev === undefined) { g.push(j); j = g[0]; }
            else { const t = f[prev]; f[prev] = j; j = t };
        }

        f[i] = j;
        prev = i;
    }
    return f.map(i => i + 1);
}

print(problem(+readline(), readline().split(' ').map(Number)));

"use strict";

let friendsNumber = +readline(); //!
let wishString = readline(); //!
let arrayOfWishNumbers = wishString.split(" ").map(function(item) {
	return +item;
});

let sortedWish = [];
let zeroIndexes = [];
let zeroValues = [];

for (let i = 0; i < arrayOfWishNumbers.length; i++) {
	if (arrayOfWishNumbers[i] === 0) {
		zeroIndexes.push(i);
	}
	sortedWish[i] = 0;
}

for (let i = 0; i < sortedWish.length; i++) {
	if (arrayOfWishNumbers[i] !== 0) {
		sortedWish[arrayOfWishNumbers[i] - 1] = arrayOfWishNumbers[i];
	}
}

for (let i = 0; i < sortedWish.length; i++) {
	if (sortedWish[i] === 0) {
		zeroValues.push(i + 1);
	}
}

let goodSortedZeroValues = [];
//

zeroValues = zeroValues.reverse();
if (zeroValues.length % 2 == 1) {
	let tempValue = zeroValues[Math.floor(zeroValues.length / 2)];
	zeroValues[Math.floor(zeroValues.length / 2)] = zeroValues[Math.floor(zeroValues.length / 2) + 1];
	zeroValues[Math.floor(zeroValues.length / 2) + 1] = tempValue;
}

//
if (zeroValues.length === zeroIndexes.length) {

	for (let i = 0; i < zeroIndexes.length; i++) {
		arrayOfWishNumbers[zeroIndexes[i]] = zeroValues[i];
	}
}

let result = arrayOfWishNumbers.join(" ");

print(result);


This is the easy version of the problem. The difference in the constraints between both versions is colored below in red. You can make hacks only if all versions of the problem are solved.Marin and Gojou are playing hide-and-seek with an array.Gojou initially performs the following steps:   First, Gojou chooses $$$2$$$ integers $$$l$$$ and $$$r$$$ such that $$$l \leq r$$$.  Then, Gojou makes an array $$$a$$$ of length $$$r-l+1$$$ which is a permutation of the array $$$[l,l+1,\ldots,r]$$$.  Finally, Gojou chooses a secret integer $$$x$$$ and sets $$$a_i$$$ to $$$a_i \oplus x$$$ for all $$$i$$$ (where $$$\oplus$$$ denotes the bitwise XOR operation). Marin is then given the values of $$$l,r$$$ and the final array $$$a$$$. She needs to find the secret integer $$$x$$$ to win. Can you help her?Note that there may be multiple possible $$$x$$$ that Gojou could have chosen. Marin can find any possible $$$x$$$ that could have resulted in the final value of $$$a$$$.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of test cases. In the first line of each test case contains two integers $$$l$$$ and $$$r$$$ ($$$ \color{red}{\boldsymbol{0} \boldsymbol{=} \boldsymbol{l}} \le r < 2^{17}$$$). The second line contains $$$r - l + 1$$$ integers of $$$a_1,a_2,\ldots,a_{r-l+1}$$$ ($$$0 \le a_i < 2^{17}$$$). It is guaranteed that $$$a$$$ can be generated using the steps performed by Gojou. It is guaranteed that the sum of $$$r - l + 1$$$ over all test cases does not exceed $$$2^{17}$$$.

For each test case print an integer $$$x$$$. If there are multiple answers, print any.

NoteIn the first test case, the original array is $$$[3, 2, 1, 0]$$$. In the second test case, the original array is $$$[0, 3, 2, 1]$$$.In the third test case, the original array is $$$[2, 1, 0]$$$.

var stdin_input = "";
var stdin_input_itr;
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { stdin_input_itr = stdin_input.split('\n').values(); main(); });

const rl = () => stdin_input_itr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function main () {
	let T = rn();
	while (T--) {
		const [_, n] = rna();
		const a = rna();

		function cntZeros(a, bit) {
			let cnt = 0;
			for (let i = 0; i <= n; i++) {
				cnt += (a[i] & 1 << bit) == 0;
			}
			return cnt;
		}

		let ans = 0;
		for (let bit = 0; bit <= 16; bit++) {
			if (cntZeros(a, bit) < (n+1)/2) {
				ans += 1 << bit;
			}
		}

		console.log(ans);
	}
}

var stdin_input = "";
var stdin_input_itr;
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { stdin_input_itr = stdin_input.split('\n').values(); main(); });

const rl = () => stdin_input_itr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function main () {
	let T = rn();
	while (T--) {
		const [_, n] = rna();
		const a = rna();

		const b = [];
		for (let i = 0; i <= n; i++) {
			b[i] = i;
		}

		function cntZeros(a, bit) {
			let cnt = 0;
			for (let i = 0; i <= n; i++) {
				cnt += (a[i] & 1 << bit) == 0;
			}
			return cnt;
		}

		let ans = 0;
		for (let bit = 0; bit <= 16; bit++) {
			if (cntZeros(a, bit) != cntZeros(b, bit)) {
				ans += 1 << bit;
			}
		}

		console.log(ans);
	}
}

var stdin_input = "";
var stdin_input_itr;
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { stdin_input_itr = stdin_input.split('\n').values(); main(); });

const rl = () => stdin_input_itr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function main () {
	let T = rn();
	while (T--) {
		const [_, n] = rna();
		const a = rna();

		const b = [];
		for (let i = 0; i <= n; i++) {
			b[i] = i;
		}

		function getZeros(a, pos) {
			let zeros = 0;
			for (let i = 0; i <= n; i++) {
				zeros += (a[i] & 1 << pos) == 0;
			}
			return zeros;
		}

		let ans = 0;
		for (let bit = 0; bit <= 16; bit++) {
			if (getZeros(a, bit) != getZeros(b, bit)) {
				ans += 2**bit;
			}
		}

		console.log(ans);
	}
}

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 [left, right] = lines[l++].trim().split(' ').map(Number)
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(left, right, arr)
    }
    console.log(output.join('\n'))
// })()
})

// check(0, 9, 33)

function solve(left, right, arr) {
    const counts = Array(18).fill(0)
    for (let i = 0; i < counts.length; i++) {
        for (let j = 0; j < arr.length; j++) {
            if (arr[j] & (1 << i)) {
                counts[i]++
            }
        }
    }
    const expect = helper(right)
    let ans = 0
    for (let i = 0; i < counts.length; i++) {
        if (counts[i] !== expect[i]) {
            ans |= 1 << i
        }
    }
    // console.log(counts, expect)
    // console.log('-')
    return ans
}
function check(left, right, x) {
    const map = {}
    const arr = []
    for (let i = left; i <= right; i++) {
        const y = i ^ x
        map[y] = (map[y] || []) + 1
        arr.push(y)
    }

    const ans = solve(left, right, arr)
    const map2 = {}
    for (let i = left; i <= right; i++) {
        const y = i ^ ans
        map2[y] = (map2[y] || []) + 1
    }
console.log(ans, map, map2)
    for (let k in map) {
        if (map[k] !== map2[k]) throw 'sb'
    }
}
function helper(x) {
    const log = Math.floor(Math.log2(x))
    const base = Math.pow(2, log)
    // [base, x]
    let counts = Array(18).fill(0)
    if (x > base) {
        counts = helper(x - base)
        counts[log] = x - base + 1
    } else if (x === base) {
        counts[log] = 1
    }
    // [0, base)
    for (let i = 0; i < log; i++) {
        counts[i] += base / 2
    }
// console.log(x, counts)
    return counts
}

'use strict';

var fs = require('fs');

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

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

function solve(l, r, data) {
  let count0 = new Array(32).fill(0),
      count1 = new Array(32).fill(0);

  for (let i = 0; i <= r; i++) {
    let cur = data[i];

    for (let j = 0; j < 32; j++) {
      if (cur & 1 << j) count1[j] = count1[j] + 1;else count0[j] = count0[j] + 1;
    }
  }

  let res = 0;

  for (let i = 0; i < 32; i++) {
    if (count0[i] < count1[i]) res |= 1 << i;
  }

  return res;
}

// const inputs = fs.readFileSync(path.join(__dirname, './codeforces.test.txt'), 'utf-8').split('\n')

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split('\n');
void function main() {
  let t = Number(inputs[0]),
      __ = 1,
      res = [];

  for (let _ = 0; _ < t; _++) {
    const [l, r] = inputs[__++].split(' ').map(Number);
    let data = inputs[__++].trim().split(' ').map(Number);
    res.push(solve(l, r, data));
  }

  console.log(res.join('\n'));
}();

var stdin_input = "";
var stdin_input_itr;
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { stdin_input_itr = stdin_input.split('\n').values(); main(); });

const rl = () => stdin_input_itr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function main () {
	let T = rn();
	while (T--) {
		const [_, n] = rna();
		const a = rna();

		const b = [];
		for (let i = 0; i < n; i++) {
			b[i] = i;
		}

		function getZeros(a, pos) {
			let zeros = 0;
			for (let i = 0; i < n; i++) {
				zeros += (a[i] & 1 << pos) == 0;
			}
			return zeros;
		}

		let ans = 0;
		for (let bit = 0; bit <= 16; bit++) {
			if (getZeros(a, bit) != getZeros(b, bit)) {
				ans += 2**bit;
			}
		}

		console.log(ans);
	}
}

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 [left, right] = lines[l++].trim().split(' ').map(Number)
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(left, right, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(left, right, arr) {
    const counts = Array(18).fill(0)
    for (let i = 0; i < counts.length; i++) {
        for (let j = 0; j < arr.length; j++) {
            if (arr[j] & (1 << i)) {
                counts[i]++
            }
        }
    }
    const expect = helper(right)
    let ans = 0
    for (let i = 0; i < counts.length; i++) {
        if (counts[i] !== expect[i]) {
            ans |= 1 << i
        }
    }
    // console.log(counts, expect)
    // console.log('-')
    return ans
}
function helper(x) {
    const log = Math.floor(Math.log2(x))
    const base = Math.pow(2, log)
    // [base, x]
    let counts = Array(18).fill(0)
    if (x > base) {
        counts = helper(x - base + 1)
        counts[log] = x - base + 1
    } else if (x === base) {
        counts[log] = 1
    }
    // [0, base)
    for (let i = 0; i < log; i++) {
        counts[i] += base / (1 << (i + 1))
    }
// console.log(x, counts)
    return counts
}