Given an array $$$a$$$ of length $$$n$$$, you can do at most $$$k$$$ operations of the following type on it:  choose $$$2$$$ different elements in the array, add $$$1$$$ to the first, and subtract $$$1$$$ from the second. However, all the elements of $$$a$$$ have to remain non-negative after this operation. What is lexicographically the smallest array you can obtain?An array $$$x$$$ is lexicographically smaller than an array $$$y$$$ if there exists an index $$$i$$$ such that $$$x_i<y_i$$$, and $$$x_j=y_j$$$ for all $$$1 \le j < i$$$. Less formally, at the first index $$$i$$$ in which they differ, $$$x_i<y_i$$$.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 20$$$) – the number of test cases you need to solve. The first line of each test case contains $$$2$$$ integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 100$$$, $$$1 \le k \le 10000$$$) — the number of elements in the array and the maximum number of operations you can make. The second line contains $$$n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_{n}$$$ ($$$0 \le a_i \le 100$$$) — the elements of the array $$$a$$$.

For each test case, print the lexicographically smallest array you can obtain after at most $$$k$$$ operations.

NoteIn the second test case, we start by subtracting $$$1$$$ from the first element and adding $$$1$$$ to the second. Then, we can't get any lexicographically smaller arrays, because we can't make any of the elements negative.

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);

  let idx = 0;
  idx++;

  for (let j = idx; j < lines.length; j = j + 2) {
    let line1 = lines[j];
    let line2 = lines[j + 1];

    if (!line1) return;

    let [len, ops] = line1.split(" ").map(Number);
    let input = line2.split(" ").map(Number);
    console.log(solve(len, ops, input).join(" "));
  }
});

function solve(length, ops, input) {
    let leftPointer = 0;
    let rightPointer = length - 1;

    while (true) {
      if (ops === 0) return input;
      if (leftPointer === rightPointer) return input;

      let leftNum = input[leftPointer];
      let rightNum = input[rightPointer];

      if (leftNum === 0) {
        leftPointer++;
        continue;
      }

      input[leftPointer] = leftNum - 1;
      input[rightPointer] = rightNum + 1;
      ops--;
    }
  }

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);

  let idx = 0;
  idx++;

  for (let j = idx; j < lines.length; j = j + 2) {
    let line1 = lines[j];
    let line2 = lines[j + 1];

    if (!line1) return;

    let [len, ops] = line1.split(" ").map(Number);
    let input = line2.split(" ").map(Number);
    console.log(solve(len, ops, input).join(" "));
  }
});

function solve(length, ops, input) {
  let leftPointer = 0;
  let rightPointer = length - 1;

  while (true) {
    if (ops === 0) return input;
    if (leftPointer === rightPointer) return input;

    let leftNum = input[leftPointer];
    let rightNum = input[rightPointer];

    if (leftNum >= 1) {
      input[leftPointer] = leftNum - 1;
      input[rightPointer] = rightNum + 1;
      ops--;
    } else {
      leftPointer++;
    }
  }
}

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL).filter((l) => l.length);

  let idx = 0;
  idx++;

  for (let j = idx; j < lines.length; j = j + 2) {
    let line1 = lines[j];
    let line2 = lines[j + 1];

    if (!line1) return;

    let [len, ops] = line1.split(" ").map((x) => parseInt(x, 10));
    let input = line2.split(" ").map((x) => parseInt(x, 10));
    console.log(solve(len, ops, input).join(" "));
  }
});

function solve(length, ops, input) {
  let leftPointer = 0;
  let rightPointer = length - 1;

  while (true) {
    if (ops === 0 || leftPointer === rightPointer) break;
    if (input[leftPointer] >= 1) {
      input[leftPointer] -= 1;
      input[rightPointer] += 1;
      ops--;
    } else {
      leftPointer++;
    }
  }

  return input;
}

const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
let input = [];
rl.on('line', line => {
    input.push(line);
})
rl.on('close', line => {
    var t = Number(input[0]);
    var a = 1;
    for (var b = 0; b < t; b++) {
        var [n, k] = input[a].split(" ").map((i) => {
            return Number(i);
        });
        a++;
        var arr = input[a].split(" ").map((i) => {
            return Number(i);
        });
        a++;
        var last = arr.length - 1;
        for (var i = 0; i <= arr.length - 2; i++) {
            if (k - arr[i] >= 0) {
                var temp = arr[i];
                arr[i] = 0;
                arr[last] += temp;
                k -= temp;
            } else {
                arr[i] -= k;
                arr[last] += k;
                k = 0;
                break;
            }
        }
        console.log(arr.join(" "));
    }
});

'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

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

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

    let testCases = parseInt(readLine());

    while(testCases--){
        let [n, k] = get_ints();
        const a = get_ints();
        let idx = 0;
        while(k--){
            if(idx === a.length - 1) break;
            while(a[idx] === 0)
            {
                idx++;
                if(idx === a.length - 1) break;
            }
            if(idx === a.length - 1) break;
            a[idx]--;
            a[a.length - 1]++;
        }
        console.log(a.join(' '));
    }
});

function get_ints() {
    return readLine().split(' ').map(Number);
}

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

function print(c){
    return console.log(c)
}

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

//Don't have to see. end------------------------------------------

function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var K = nextInt();
		var list = nextIntArray(N);
		for(var j = 0; j < N - 1; j++){
			if(list[j] > 0){
				if(list[j] > K){
					list[j] -= K;
					list[N - 1] += K;
					break;
				}else{
					K -= list[j];
					list[N - 1] += list[j];
					list[j] = 0;
				}
			}
		}

		myout(myconv(list, 8));
	}
}

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 n = readline();
    for(let i = 0; i < n; i ++){
        let [m,k] = readline().split(' ').map(Number);
        const array = readline().split(' ').map(Number);
        while( k > 0){
            for(let j = 0; j < m - 1; j++){
                if(array[j] > 0){
                    array[j]--;
                    array[m - 1]++;
                    break;
                }
            }
            k--;
        }
        console.log(array.join(' '));
    }
}

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
//////////// LIBS
const io = new IO();
function solve(n, k, tab) {
    let idx = 0;
    while (k && idx < tab.length - 1) {
        if (tab[idx] > 0) {
            tab[idx]--;
            tab[n - 1]++;
            k--;
        }
        else {
            idx++;
        }
    }
    tab.forEach((a) => {
        io.write(a);
    });
    io.writeLine(' ');
}
function main() {
    try {
        let t = io.nextNum();
        while (t--) {
            let n = io.nextNum();
            let k = io.nextNum();
            let tab = io.nextNumArray(n);
            solve(n, k, tab);
        }
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

var maxN = 2 * 1e5 + 10
var mod = 1e9 + 7

function main() {
  const xx = readline();
  Array(Number(xx)).fill(1).map((t, i) => {
    // var n = parseInt(readline());
    var [n, k] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    })
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var kk = k
    for (let j = 0; j < n - 1; j++) {
      if (a[j] > 0 && k > 0) {
        var res = Math.min(a[j], k)
        a[j] = a[j] - (res)
        k = k - (res)
      }
    }
    a[n - 1] = a[n - 1] + (kk - k)

    console.log(a.join(' '))

  })
}

let input = ''
process.stdin.on('data', data => input += data)
process.stdin.on('end', () => main(input))

function main(input) {
    let lines = input.trim().split('\n');
    let T = +lines[0];
    for(let i = 1; i < lines.length; i += 2) {
        let [n, k] = lines[i].split(' ').map(v => +v);
        const arr = lines[i + 1].split(' ').map(v => +v);
    	solve(arr, n, k);
    }
}

function solve(arr, n, k) {
	for (let j=0; j<arr.length-1; j++) {
		if (arr[j] <= k) {
			k -= arr[j];
			arr[arr.length-1] += arr[j];
			arr[j] = 0;
		}

		if (arr[j] > k) {
			arr[j] -= k;
			arr[arr.length-1] += k;
			break;
		}

		if (k === 0)
			break;
	}
	console.log(arr.join(' '))
}

///////////////////////////////// pre-define /////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const err = console.error;
// ****************************** Math *******************************************
const mi = Math.min;
const mx = Math.max;
const mxbi = (...args) => args.reduce((m, e) => e > m ? e : m);
const mibi = (...args) => args.reduce((m, e) => e < m ? e : m);
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const sqbi = (v) => {
    if (v < 0n) throw 'square root of negative numbers is not supported';
    if (v < 2n) return v;
    const dfs = (n, x0) => {
        let x1 = ((n / x0) + x0) >> 1n;
        if (x0 === x1 || x0 === (x1 - 1n)) return x0;
        return dfs(n, x1);
    }
    return dfs(v, 1n); // has >> 0
};
const lge = Math.log;
const lg10 = Math.log10;
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const powmod = (a, b, mod) => {
    let r = 1n;
    while (b > 0n) {
        if (b % 2n == 1) r = r * a % mod;
        b >>= 1n;
        a = a * a % mod;
    }
    return r; // return BigInt
};
const combination = (m, n) => {
    return factorial(m, n) / factorial(n, n); // return BigInt
};
const factorial = (m, n) => {
    let num = 1n;
    let cnt = 0;
    for (let i = BigInt(m); i > 0; i--) {
        if (cnt == n) break;
        num *= i;
        cnt++;
    }
    return num;
};
const bitCount = (n) => {
    n = n - ((n >> 1) & 0x55555555);
    n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
    return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
};
// ****************************** Array / String *******************************************
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sum = (a) => a.reduce(((x, y) => x + y), 0);
const arrayEqual = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const sortPart = (a, k) => { // sort only first kth elements
    let l = a.slice(0, k);
    l.sort((x, y) => x - y);
    let r = a.slice(k);
    return l.concat(r);
};
const counter = (a_or_s) => {
    let map = new Map();
    for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1);
    return map;
};
const isPalindrome = (s) => {
    let n = s.length;
    let i = 0;
    let j = n - 1;
    while (i < j) {
        if (s[i++] != s[j--]) return false;
    }
    return true;
};
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
/**
 * 04/21/20 morning
 * https://codeforces.com/contest/1516/problem/0
 */

// evening
const solve = (n, k, a) => {
    let res = [...a];
    for (let i = 0; i < n - 1; i++) {
        let tmp = mi(a[i], k);
        res[i] -= tmp;
        res[n - 1] += tmp;
        k -= tmp;
    }
    pr(res.join(" "));
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i][1], input[i + 1]);
            i += 2;
        }
    });
};

main()

let input = '';
process.stdin.on('data', str => input += str)
process.stdin.on('end', () => {
	const lines = input.trim().split('\n').slice(1);

	for (let i=0; i<lines.length; i+=2) {
		let [_, k] = lines[i].split(' ').map(v => +v);
		const arr = lines[i+1].split(' ').map(v => +v);

		for (let j=0; j<arr.length-1; j++) {
			if (arr[j] <= k) {
				k -= arr[j];
				arr[arr.length-1] += arr[j];
				arr[j] = 0;
			}

			if (arr[j] > k) {
				arr[j] -= k;
				arr[arr.length-1] += k;
				break;
			}

			if (k === 0)
				break;
		}

		console.log(arr.join(' '))
	}
})

var T = parseInt(readline());

for (t = 0; t < T; t++) {
	var nk = readline().split(" ").map(x => parseInt(x));
	var a = readline().split(" ").map(x => parseInt(x));
	var n = nk[0];
	var k = nk[1];

	var cur = 0;
	for (i = 0; i < k; ++i) {
		while (a[cur] == 0 && cur < n - 1) cur += 1;
		a[cur] -= 1;
		a[n - 1] += 1;
	}
	var ans = "";
	for (i = 0; i < n; ++i) {
		ans += a[i].toString() + " ";
	}
	print(ans);
}

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL).filter(l => l.length);

  let idx = 0;
  idx++;

  for (let j = idx; j < lines.length; j = j + 2) {
    let line1 = lines[j];
    let line2 = lines[j + 1];

    if (!line1) return;

    let [len, ops] = line1.split(" ").map((x => parseInt(x, 10)));
    let input = line2.split(" ").map(x => parseInt(x, 10));
    console.log(solve(len, ops, input).join(" "));
  }
});

function solve(length, ops, input) {
  let leftPointer = 0;
  let rightPointer = length - 1;

  while (true) {
    if (ops === 0) return input;

    let leftNum = input[leftPointer];

    if (leftNum === 0) {
      leftPointer++;
      continue;
    }

    if (leftPointer === rightPointer) return input;

    input[leftPointer]--
    input[rightPointer]++
    ops--;
  }
}

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);

  let idx = 0;
  idx++;

  for (let j = idx; j < lines.length; j = j + 2) {
    let line1 = lines[j];
    let line2 = lines[j + 1];

    if (!line1) return;

    let [len, ops] = line1.split(" ").map(Number);
    let input = line2.split(" ").map(Number);
    console.log(solve(len, ops, input).join(" "));
  }
});

function solve(length, ops, input) {
  if (length === 100 && ops === 4740) {
    console.log({ length, ops, input });
  }
  let leftPointer = 0;
  let rightPointer = length - 1;

  while (true) {
    if (ops === 0) return input;

    let leftNum = input[leftPointer];
    let rightNum = input[rightPointer];

    if (leftNum === 0) {
      leftPointer++;
      continue;
    }

    if (leftPointer === rightPointer) return input;

    input[leftPointer] = leftNum - 1;
    input[rightPointer] = rightNum + 1;
    ops--;
  }
}

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);

  let idx = 0;
  idx++;

  for (let j = idx; j < lines.length; j = j + 2) {
    let line1 = lines[j];
    let line2 = lines[j + 1];

    if (!line1) return;

    let [len, ops] = line1.split(" ").map(Number);
    let input = line2.split(" ").map(Number);
    console.log(solve(len, ops, input).join(" "));
  }
});

function solve(length, ops, input) {
  console.log({length, ops, input})
  let leftPointer = 0;
  let rightPointer = length - 1;

  while (true) {
    if (ops === 0) return input;

    let leftNum = input[leftPointer];
    let rightNum = input[rightPointer];

    if (leftNum === 0) {
      leftPointer++;
      continue;
    }

    if (leftPointer === rightPointer) return input;

    input[leftPointer] = leftNum - 1;
    input[rightPointer] = rightNum + 1;
    ops--;
  }
}

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);

  if (lines.length > 30) console.log(lines)

  let idx = 0;
  idx++;

  for (let j = idx; j < lines.length; j = j + 2) {
    let line1 = lines[j];
    let line2 = lines[j + 1];

    if (!line1) return;

    let [len, ops] = line1.split(" ").map(Number);
    let input = line2.split(" ").map(Number);
    console.log(solve(len, ops, input).join(" "));
  }
});

function solve(length, ops, input) {
  let leftPointer = 0;
  let rightPointer = length - 1;

  while (true) {
    if (ops === 0) return input;

    let leftNum = input[leftPointer];
    let rightNum = input[rightPointer];

    if (leftNum === 0) {
      leftPointer++;
      continue;
    }

    if (leftPointer === rightPointer) return input;

    input[leftPointer] = leftNum - 1;
    input[rightPointer] = rightNum + 1;
    ops--;
  }
}

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);

  let idx = 0;
  idx++;

  for (let j = idx; j < lines.length; j = j + 2) {
    let line1 = lines[j];
    let line2 = lines[j + 1];

    if (!line1) return;

    let [len, ops] = line1.split(" ").map(Number);
    let input = line2.split(" ").map(Number);
    console.log(solve(len, ops, input).join(" "));
  }
});

function solve(length, ops, input) {
  let leftPointer = 0;
  let rightPointer = length - 1;

  while (true) {
    if (ops === 0) return input;

    let leftNum = input[leftPointer];
    let rightNum = input[rightPointer];

    if (leftNum === 0) {
      leftPointer++;
      continue;
    }

    if (leftPointer === rightPointer) return input;

    input[leftPointer] = leftNum - 1;
    input[rightPointer] = rightNum + 1;
    ops--;
  }
}

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);

  let idx = 0;
  idx++;

  for (let j = idx; j < lines.length; j = j + 2) {
    let line1 = lines[j];
    let line2 = lines[j + 1];

    if (!line1) return;

    let [len, ops] = line1.split(" ").map(Number);
    let input = line2.split(" ").map(Number);
    console.log(solve(len, ops, input).join(" "));
  }
});

function solve(length, ops, input) {
  let leftPointer = 0;
  let rightPointer = length - 1;

  while (true) {
    if (ops === 0) return input;

    let leftNum = input[leftPointer];
    let rightNum = input[rightPointer];

    if (leftNum === 0) {
      leftPointer++;
      continue;
    }
    if (rightNum === 9) {
      rightPointer--;
      continue
    }

    if (leftPointer === rightPointer) return input;

    input[leftPointer] = leftNum - 1;
    input[rightPointer] = rightNum + 1;
    ops--;
  }
}

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const lines = i.split(EOL);

  let idx = 0;
  idx++;

  for (let j = idx; j < lines.length; j = j + 2) {
    let line1 = lines[j];
    let line2 = lines[j + 1];

    if (!line1) return;

    let [len, ops] = line1.split(" ").map(Number);
    let input = line2.split(" ").map(Number);
    console.log(solve(len, ops, input).join(" "));
  }
});

function solve(length, ops, input) {
  let leftPointer = 0;
  let rightPointer = length - 1;

  while (true) {
    if (ops === 0) return input;

    let leftNum = input[leftPointer];
    let rightNum = input[rightPointer];

    if (leftNum === 0) leftPointer++;
    if (rightNum === 9) rightPointer--;

    if (leftPointer === rightPointer) return input;

    input[leftPointer] = leftNum - 1;
    input[rightPointer] = rightNum + 1;
    ops--;
  }
}

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  try {
    const { EOL } = require("os");
    const lines = i.split(EOL);

    let idx = 0;
    idx++;

    for (let j = idx; j < lines.length; j = j + 2) {
      let line1 = lines[j];
      let line2 = lines[j + 1];

      let [len, ops] = line1.split(" ").map(Number);
      let input = line2.split(" ").map(Number);
      console.log(solve(len, ops, input).join(" "));
    }
  } catch (e) {
    console.log(e)
  }
});

function solve(length, ops, input) {
  let leftPointer = 0;
  let rightPointer = length - 1;

  while (true) {
    if (ops === 0) return input;

    let leftNum = input[leftPointer];
    let rightNum = input[rightPointer];

    if (leftNum === 0) leftPointer++;
    if (rightNum === 9) rightPointer--;

    if (leftPointer === rightPointer) return input;

    input[leftPointer] = leftNum - 1;
    input[rightPointer] = rightNum + 1;
    ops--;
  }
}

const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
let input = [];
rl.on('line', line => {
    input.push(line);
})
rl.on('close', line => {
    var t = Number(input[0]);
    var a = 1;
    for (var b = 0; b < t; b++) {
        var [n, k] = input[a].split(" ").map((i) => {
            return Number(i);
        });
        a++;
        var arr = input[a].split(" ").map((i) => {
            return Number(i);
        });
        a++;
        var last = arr.length - 1;
        for (var i = 0; i <= arr.length - 2; i++) {
            if (k - arr[i] >= 0) {
                arr[last] += arr[i];
                arr[i] = 0;
                k -= arr[i];
            } else {
                arr[i] -= k;
                arr[last] += k;
                k = 0;
                break;
            }
        }
        console.log(arr.join(" "));
    }
});

'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

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

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

    let testCases = parseInt(readLine());

    while(testCases--){
        let [n, k] = get_ints();
        const a = get_ints();
        let idx = 0;
        while(k--){
            if(idx === a.length - 1) break;
            while(a[idx] === 0)
            {
                idx++;
            }
            a[idx]--;
            a[a.length - 1]++;
        }
        console.log(a.join(' '));
    }
});

function get_ints() {
    return readLine().split(' ').map(Number);
}

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

function print(c){
    return console.log(c)
}

'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

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

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

    let testCases = parseInt(readLine());

    while(testCases--){
        let [n, k] = get_ints();
        const a = get_ints();
        let idx = 0;
        while(k--){
            if(idx === a.length - 1) break;
            if(a[idx] === 0)
            {
                while(a[idx] === 0)
                {
                    idx++;
                }
                a[idx]--;
                a[a.length - 1]++;
            }
            else
            {
                a[idx]--;
                a[a.length - 1]++;
            }
        }
        console.log(a.join(' '));
    }
});

function get_ints() {
    return readLine().split(' ').map(Number);
}

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

function print(c){
    return console.log(c)
}

'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

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

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

    let testCases = parseInt(readLine());

    while(testCases--){
        let [n, k] = get_ints();
        const a = get_ints();
        let idx = 0;
        while(k--){
            if(idx === a.length - 1) break;
            if(a[idx] === 0) idx++;
            else{
                a[idx]--;
                a[a.length - 1]++;
            }
        }
        console.log(a.join(' '));
    }
});

function get_ints() {
    return readLine().split(' ').map(Number);
}

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

function print(c){
    return console.log(c)
}

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 n = readline();
    for(let i = 0; i < n; i ++){
        let [m,k] = readline().split(' ').map(Number);
        const array = readline().split(' ').map(Number);
        while( k > 0){
            for(let j = 0; j < m; j++){
                if(j+1 >= m){
                    k = 0;
                    break;
                } else if(array[j] > 0){
                    array[j]--;
                    array[j+1]++;
                    break;
                }
            }
            k--;
        }
        console.log(array.join(' '));
    }
}

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
//////////// LIBS
const io = new IO();
function solve(n, k, tab) {
    let idx = 0;
    while (k-- && idx < tab.length - 1) {
        if (tab[idx] > 0) {
            tab[idx]--;
            tab[n - 1]++;
        }
        else {
            idx++;
        }
    }
    tab.forEach((a) => {
        io.write(a);
    });
    io.writeLine(' ');
}
function main() {
    try {
        let t = io.nextNum();
        while (t--) {
            let n = io.nextNum();
            let k = io.nextNum();
            let tab = io.nextNumArray(n);
            solve(n, k, tab);
        }
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

var maxN = 2 * 1e5 + 10
var mod = 1e9 + 7

function main() {
  const xx = readline();
  Array(Number(xx)).fill(1).map((t, i) => {
    // var n = parseInt(readline());
    var [n, k] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    })
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var kk = k
    for (let j = 0; j < n - 1; j++) {
      if (a[j] > 0 && k > 0) {
        var res = Math.min(a[j] - 1, k)
        a[j] = a[j] - (res)
        k = k - (res)
      }
    }
    a[n - 1] = a[n - 1] + (kk - k)

    console.log(a.join(' '))

  })
}


You are given the array of integer numbers a0, a1, ..., an - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array.

The first line contains integer n (1 ≤ n ≤ 2·105) — length of the array a. The second line contains integer elements of the array separated by single spaces ( - 109 ≤ ai ≤ 109).

Print the sequence d0, d1, ..., dn - 1, where di is the difference of indices between i and nearest j such that aj = 0. It is possible that i = j.

var listLength = Number(readline());
var list = readline().split(' ');

var dist = listLength;
var distances = [];
for (var i = 0; i < listLength; i++)
    distances[i] = 0;

for (var i = 0; i < listLength; i++){
    if (list[i] == '0'){
        dist = 0;
        var j = i;
        while (distances[j] >= dist && j >= 0){
            distances[j] = dist++;
            j--;
        }
        dist = 0;
    }
    else {
        dist++;
        distances[i] = dist;
    }
}

print(distances.join(" "));

  var n = parseInt(readline());
  var a = readline().split(' ').map(x => parseInt(x));

  var d = Infinity;
  var ld = [];
  var rd = [];
  for(var i = 0; i < n; i += 1) {
    if(a[i] === 0) {
      d = 0;
    }
    ld[i] = d;
    d += 1;
  }
  d = Infinity;
  for(var i = n - 1; i >= 0; i -= 1) {
    if(a[i] === 0) {
      d = 0;
    }
    rd[i] = d;
    d += 1;
  }
  var res = [];
  for(var i = 0; i < n; i += 1) {
    res[i] = Math.min(ld[i], rd[i]);
  }
  print(res.join(' '));

var length = readline();
var array = readline().split(" ");
var lastzero = -1;
var output = [];
for (var i = 0; i < array.length; i++) {
	array[i] = parseInt(array[i])
	if (array[i] == 0) {
		lastzero = i;
		output[i] = 0
	} else {
		if (lastzero != -1) {
			output[i] = i - lastzero;
		}
	}
};
lastzero = -1;
for (var i = array.length - 1; i >= 0; i--) {
	if (array[i] == 0) {
		lastzero = i;
	} else {
		if (lastzero != -1)
		    if(!output[i]) {
			    output[i] = lastzero - i;
		    }
		    else {
		        output[i] = Math.min(output[i], lastzero - i);
		    }
	}
};
print(JSON.stringify(output).replace(/[\[\]]/g, "").replace(/\,/g, " "));

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

const input = [];
readline.on('line', line => { input.push(line); });

readline.on('close', () => {
    const arr = input[1].split(' ').map(Number);
    const zeroes = [];
    let lastZero = -1, currZero = -1;
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] === 0) {
            zeroes[i] = 0;
            [lastZero, currZero] = [currZero, i];
            for (let j = i; j > lastZero; j--) {
                if ((currZero - j < zeroes[j]) || lastZero === -1) zeroes[j] = currZero - j;
            }
        } else {
            zeroes[i] = i - currZero;
        }
    }
    console.log(zeroes.join(' '));
});

  var n = parseInt(readline());
  var a = readline().split(' ').map(x => parseInt(x));

  var d = 0;
  var ld = [];
  var rd = [];
  for(var i = 0; i < n; i += 1) {
    if(a[i] === 0) {
      d = 0;
    }
    ld[i] = d;
    d += 1;
  }
  d = 0;
  for(var i = n - 1; i >= 0; i -= 1) {
    if(a[i] === 0) {
      d = 0;
    }
    rd[i] = d;
    d += 1;
  }
  var res = [];
  res[0] = rd[0];
  res[n - 1] = ld[n - 1];
  for(var i = 1; i < n - 1; i += 1) {
    res[i] = Math.min(ld[i], rd[i]);
  }
  print(res.join(' '));

  var n = parseInt(readline());
  var a = readline().split(' ').map(x => parseInt(x));

  var d = 0;
  var ld = [];
  var rd = [];
  for(var i = 0; i < n; i += 1) {
    if(a[i] === 0) {
      d = 0;
    }
    ld[i] = d;
    d += 1;
  }
  for(var i = n - 1; i >= 0; i -= 1) {
    if(a[i] === 0) {
      d = 0;
    }
    rd[i] = d;
    d += 1;
  }
  var res = [];
  res[0] = rd[0];
  res[n - 1] = ld[n - 1];
  for(var i = 1; i < n - 1; i += 1) {
    res[i] = Math.min(ld[i], rd[i]);
  }
  print(res.join(' '));

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

const input = [];
readline.on('line', line => { input.push(line); });

readline.on('close', () => {
    const arr = input[1].split(' ').map(Number);
    const zeroes = [];
    let lastZero = -1, currZero = -2;
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] === 0) {
            zeroes[i] = 0;
            [lastZero, currZero] = [currZero, i];
            for (let j = i; j > lastZero; j--) {
                if (currZero - j < zeroes[j]) zeroes[j] = currZero - j;
            }
        } else {
            zeroes[i] = i - currZero;
        }
    }
    console.log(zeroes.join(' '));
});

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

const input = [];
readline.on('line', line => { input.push(line); });

readline.on('close', () => {
    const arr = input[1].split(' ').map(Number);
    const zeroes = [];
    let lastZero = -1, currZero = -1;
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] === 0) {
            zeroes[i] = 0;
            [lastZero, currZero] = [currZero, i];
            for (let j = i; j > (lastZero > 0 ? lastZero : 0); j--) {
                if ((currZero - j < zeroes[j]) || lastZero === -1) zeroes[j] = currZero - j;
            }
        } else {
            zeroes[i] = i - currZero;
        }
    }
    console.log(zeroes.join(' '));
});


Given an array $$$a$$$ of positive integers with length $$$n$$$, determine if there exist three distinct indices $$$i$$$, $$$j$$$, $$$k$$$ such that $$$a_i + a_j + a_k$$$ ends in the digit $$$3$$$.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$3 \leq n \leq 2 \cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array. The sum of $$$n$$$ across all test cases does not exceed $$$2 \cdot 10^5$$$.

Output $$$t$$$ lines, each of which contains the answer to the corresponding test case. Output "YES" if there exist three distinct indices $$$i$$$, $$$j$$$, $$$k$$$ satisfying the constraints in the statement, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

NoteIn the first test case, you can select $$$i=1$$$, $$$j=4$$$, $$$k=3$$$. Then $$$a_1 + a_4 + a_3 = 20 + 84 + 19 = 123$$$, which ends in the digit $$$3$$$.In the second test case, you can select $$$i=1$$$, $$$j=2$$$, $$$k=3$$$. Then $$$a_1 + a_2 + a_3 = 1 + 11 + 1 = 13$$$, which ends in the digit $$$3$$$.In the third test case, it can be proven that no such $$$i$$$, $$$j$$$, $$$k$$$ exist. Note that $$$i=4$$$, $$$j=4$$$, $$$k=4$$$ is not a valid solution, since although $$$a_4 + a_4 + a_4 = 1111 + 1111 + 1111 = 3333$$$, which ends in the digit $$$3$$$, the indices need to be distinct.In the fourth test case, it can be proven that no such $$$i$$$, $$$j$$$, $$$k$$$ exist.In the fifth test case, you can select $$$i=4$$$, $$$j=3$$$, $$$k=1$$$. Then $$$a_4 + a_3 + a_1 = 4 + 8 + 1 = 13$$$, which ends in the digit $$$3$$$.In the sixth test case, you can select $$$i=1$$$, $$$j=2$$$, $$$k=6$$$. Then $$$a_1 + a_2 + a_6 = 16 + 38 + 99 = 153$$$, which ends in the digit $$$3$$$.

class Scaner {
    data = [];
    constructor() {
        process.stdin.setEncoding('utf-8');
        process.stdin.on('data', _data => {
            let lasttext = this.data.pop();
            if (lasttext == undefined)
                lasttext = ""
            _data = lasttext + _data;
            const l = _data.split('\n');
            this.data = this.data.concat(l.slice(0, -1).map(string => string.trim()), l[l.length - 1]);
        });
    }
    read = async () => {
        process.stdin.resume();
        while (this.data.length < 2) {
            await delay(0);
        }
        process.stdin.pause();
        let res = this.data.shift();
        if (res == "")
            return await read();
        return res;
    };
}
const delay = (ms=0) => new Promise(resolve => setTimeout(resolve, ms));
const print = (text) => process.stdout.write("" + text);
const scaner = new Scaner()
const read = scaner.read;
//----------------------------------------------------------------
//-----------------------the-code---------------------------------
//----------------------------------------------------------------
function solve(count=[]){
        for(let i in count){
            if(count[i]>0)
                count[i]--;
            else
                continue;
            for(let j in count){
                if(count[j]>0)
                    count[j]--;
                else
                    continue;
                {
                    let k=(23-i-j )%10;
                    if(count[k]>0){
                        return true;
                    }
                }
                count[j]++;
            }
            count[i]++;
        }
    return false;
}
(async () => {
    let t = parseInt(await read());
    while (t--) {
        let count= new Array(10).fill(0);
        _=await read();
        let a =(await read()).split(' ').map(x=>Number(x[x.length-1]));
        a.forEach(e => count[e]++);
        if(solve(count))
            console.log("YES");
        else
            console.log("NO");
    }
})().then(() => { }
)

'use strict';

function solve(n, a) {
  const map = new Map();
  for (let num of a) {
    var _map$get;
    const last = num % 10;
    map.set(last, ((_map$get = map.get(last)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);
  }
  for (let i = 0; i <= 9; i++) {
    for (let j = 0; j <= 9; j++) {
      for (let k = 0; k <= 9; k++) {
        if ((i + k + j) % 10 === 3) {
          if (i === j) {
            if (j === k) {
              var _map$get2;
              if (((_map$get2 = map.get(i)) !== null && _map$get2 !== void 0 ? _map$get2 : 0) >= 3) {
                return 'YES';
              }
            } else {
              var _map$get3, _map$get4;
              if (((_map$get3 = map.get(i)) !== null && _map$get3 !== void 0 ? _map$get3 : 0) >= 2 && ((_map$get4 = map.get(k)) !== null && _map$get4 !== void 0 ? _map$get4 : 0) >= 1) {
                return 'YES';
              }
            }
          } else {
            if (j === k) {
              var _map$get5, _map$get6;
              if (((_map$get5 = map.get(i)) !== null && _map$get5 !== void 0 ? _map$get5 : 0) >= 1 && ((_map$get6 = map.get(j)) !== null && _map$get6 !== void 0 ? _map$get6 : 0) >= 2) {
                return 'YES';
              }
            } else {
              if (i === k) {
                var _map$get7, _map$get8;
                if (((_map$get7 = map.get(i)) !== null && _map$get7 !== void 0 ? _map$get7 : 0) >= 2 && ((_map$get8 = map.get(j)) !== null && _map$get8 !== void 0 ? _map$get8 : 0) >= 1) {
                  return 'YES';
                }
              } else {
                var _map$get9, _map$get10, _map$get11;
                if (((_map$get9 = map.get(i)) !== null && _map$get9 !== void 0 ? _map$get9 : 0) >= 1 && ((_map$get10 = map.get(j)) !== null && _map$get10 !== void 0 ? _map$get10 : 0) >= 1 && ((_map$get11 = map.get(k)) !== null && _map$get11 !== void 0 ? _map$get11 : 0) >= 1) {
                  return 'YES';
                }
              }
            }
          }
        }
      }
    }
  }
  return 'NO';
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

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

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    for (let i = 0; i < n; i++) arr[i] = arr[i] % 10;
    let obj = {},
      res = [];
    for (let i = 0; i < n; i++) {
      if (obj[arr[i]] === undefined) obj[arr[i]] = 1;
      else obj[arr[i]]++;
      if (obj[arr[i]] <= 3) res.push(arr[i]);
    }
    const helper = (arr) => {
      for (let i = 0; i < arr.length; i++) {
        for (let j = i + 1; j < arr.length; j++) {
          for (let k = j + 1; k < arr.length; k++) {
            if ((arr[i] + arr[j] + arr[k]) % 10 === 3) return true;
          }
        }
      }
      return false;
    };
    if (helper(res)) console.log("YES");
    else console.log("NO");
  }
};
solve();

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

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}
var T = readline();
for(var qe=1;qe<=T;qe++) {
  var n = readline()//.split(' ').map((x) => parseInt(x));
  var a = readline().split(' ')//.map((x) => parseInt(x));
  var cnt = [];
  for(var i=0;i<10;i++) cnt[i]=0;
  for(var i=0;i<n;i++) {

    var lst = parseInt(a[i][a[i].length-1]);
    cnt[lst]++;
  }
  var dp =[]
  for(var i=0;i<=3;i++) {
    dp[i] = []
    for(var j=0;j<10;j++) dp[i][j] = 0;
  }
  dp[0][0] = 1;
  for(var digits=0;digits<10;digits++) {
    for(var i=3;i>0;i--) {
      for(var j=0;j<=min(cnt[digits], 3);j++) {
        if(j == 0) continue;
        for(var k=0;k<10;k++) {
          var val = (j*digits)
          if(i-j >= 0) dp[i][(val+k)%10] |= dp[i-j][k];
        }
      }
    }
  }
  //if(qe==1) console.log(cnt, dp)
  var ans = dp[3][3] ? 'YES' : 'NO';
  console.log(ans)
   //fs.appendFileSync('output.txt', ans+'\r\n');

}
//

//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 c = [];
	for(var i = 0; i <= 9; i++){
		for(var j = 0; j <= 9; j++){
			for(var k = 0; k <= 9; k++){
				var V = (i + j + k) % 10;
				if(V == 3){
					var map = {};
					if(map[i] == null){
						map[i] = 0;
					}
					map[i]++;
					if(map[j] == null){
						map[j] = 0;
					}
					map[j]++;
					if(map[k] == null){
						map[k] = 0;
					}
					map[k]++;
					c.push(map);
				}
			}
		}
	}

	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var map = {};
		for(var i = 0; i < N; i++){
			if(map[list[i] % 10] == null){
				map[list[i] % 10] = 0;
			}
			map[list[i] % 10]++;
		}
		var ok = false;
		for(var i = 0; i < c.length; i++){
			var cm = c[i];
			var ck = Object.keys(cm);
			var cb = true;
			for(var j = 0; j < ck.length; j++){
				if(map[ck[j]] == null || map[ck[j]] < cm[ck[j]]){
					cb = false;
					break;
				}
			}
			if(cb){
				ok = true;
				break;
			}
		}
		if(ok){
			myout("YES");
		}else{
			myout("NO");
		}
	}
}

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

function solve(n, arr) {
    const map = arr.reduce((o, x) => {
        x = x % 10
        o[x] = (o[x] || 0) + 1
        return o
    }, Array(10).fill(0))
    // console.log(map);return
    for (let i = 0; i < 1e3; i++) {
        const a = Math.floor(i / 1e2)
        const b = Math.floor((i % 100) / 1e1)
        const c = i % 10
        const o = Array(10).fill(0)
        o[a] = (o[a] || 0) + 1
        o[b] = (o[b] || 0) + 1
        o[c] = (o[c] || 0) + 1
        if (map[a] < o[a] || map[b] < o[b] || map[c] < o[c]) continue
        const r = (a + b + c) % 10
        if (r === 3) {
            // console.log(a, b, c)
            return 'YES'
        }
    }
    return 'NO'
}

class Scaner {
    data = [];
    constructor() {
        process.stdin.setEncoding('utf-8');
        process.stdin.on('data', _data => {
            let lasttext = this.data.pop();
            if (lasttext == undefined)
                lasttext = ""
            _data = lasttext + _data;
            const l = _data.split('\n');
            this.data = this.data.concat(l.slice(0, -1).map(string => string.trim()), l[l.length - 1]);
        });
    }
    read = async () => {
        process.stdin.resume();
        while (this.data.length < 2) {
            await delay(0);
        }
        process.stdin.pause();
        let res = this.data.shift();
        if (res == "")
            return await read();
        return res;
    };
}
const delay = (ms=0) => new Promise(resolve => setTimeout(resolve, ms));
const print = (text) => process.stdout.write("" + text);
const scaner = new Scaner()
const read = scaner.read;
//----------------------------------------------------------------
//-----------------------the-code---------------------------------
//----------------------------------------------------------------
function solve(count=[]){
        for(let i in count){
            if(count[i]>0)
                count[i]--;
            else
                continue;
            for(let j in count){
                if(count[j]>0)
                    count[j]--;
                else
                    continue;
                {
                    let k=(13-( i+j )%10)%10;
                    if(count[k]>0){
                        return true;
                    }
                }
                count[j]++;
            }
            count[i]++;
        }
    return false;
}
(async () => {
    let t = parseInt(await read());
    while (t--) {
        let count= new Array(10).fill(0);
        _=await read();
        let a =(await read()).split(' ').map(x=>Number(x[x.length-1]));
        a.forEach(e => count[e]++);
        if(solve(count))
            console.log("YES");
        else
            console.log("NO");
    }
})().then(() => { }
)

'use strict';

function solve(n, a) {
  const map = new Map();
  for (let num of a) {
    var _map$get;
    const last = num % 10;
    map.set(last, ((_map$get = map.get(last)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);
  }
  for (let i = 0; i <= 9; i++) {
    for (let j = 0; j <= 9; j++) {
      for (let k = 0; k <= 9; k++) {
        if ((i + k + j) % 10 === 3) {
          if (i === j) {
            if (j === k) {
              var _map$get2;
              if (((_map$get2 = map.get(k)) !== null && _map$get2 !== void 0 ? _map$get2 : 0) >= 3) {
                return 'YES';
              }
            } else {
              var _map$get3, _map$get4;
              if (((_map$get3 = map.get(i)) !== null && _map$get3 !== void 0 ? _map$get3 : 0) >= 2 && ((_map$get4 = map.get(k)) !== null && _map$get4 !== void 0 ? _map$get4 : 0) >= 1) {
                return 'YES';
              }
            }
          } else {
            if (j === k) {
              var _map$get5, _map$get6;
              if (((_map$get5 = map.get(j)) !== null && _map$get5 !== void 0 ? _map$get5 : 0) >= 2 && ((_map$get6 = map.get(i)) !== null && _map$get6 !== void 0 ? _map$get6 : 0) >= 1) {
                return 'YES';
              }
            } else {
              var _map$get7, _map$get8, _map$get9;
              if (((_map$get7 = map.get(i)) !== null && _map$get7 !== void 0 ? _map$get7 : 0) >= 1 && ((_map$get8 = map.get(j)) !== null && _map$get8 !== void 0 ? _map$get8 : 0) >= 1 && ((_map$get9 = map.get(k)) !== null && _map$get9 !== void 0 ? _map$get9 : 0) >= 1) {
                return 'YES';
              }
            }
          }
        }
      }
    }
  }
  return 'NO';
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});


We just discovered a new data structure in our research group: a suffix three!It's very useful for natural language processing. Given three languages and three suffixes, a suffix three can determine which language a sentence is written in.It's super simple, 100% accurate, and doesn't involve advanced machine learning algorithms.Let us tell you how it works.  If a sentence ends with "po" the language is Filipino.  If a sentence ends with "desu" or "masu" the language is Japanese.  If a sentence ends with "mnida" the language is Korean. Given this, we need you to implement a suffix three that can differentiate Filipino, Japanese, and Korean.Oh, did I say three suffixes? I meant four.

The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 30$$$) denoting the number of test cases. The next lines contain descriptions of the test cases.  Each test case consists of a single line containing a single string denoting the sentence. Spaces are represented as underscores (the symbol "_") for ease of reading. The sentence has at least $$$1$$$ and at most $$$1000$$$ characters, and consists only of lowercase English letters and underscores. The sentence has no leading or trailing underscores and no two consecutive underscores. It is guaranteed that the sentence ends with one of the four suffixes mentioned above.

For each test case, print a single line containing either "FILIPINO", "JAPANESE", or "KOREAN" (all in uppercase, without quotes), depending on the detected language.

8
kamusta_po
genki_desu
ohayou_gozaimasu
annyeong_hashimnida
hajime_no_ippo
bensamu_no_sentou_houhou_ga_okama_kenpo
ang_halaman_doon_ay_sarisari_singkamasu
si_roy_mustang_ay_namamasu

FILIPINO
JAPANESE
JAPANESE
KOREAN
FILIPINO
FILIPINO
JAPANESE
JAPANESE

NoteThe first sentence ends with "po", so it is written in Filipino.The second and third sentences end with "desu" and "masu", so they are written in Japanese.The fourth sentence ends with "mnida", so it is written in Korean.

let s = '';

process.stdin.on('data', function (i) {
    s += i;
});

process.stdin.on('end', function () {
    s = s.trim().split('\n');
    s.shift();
    s.forEach(element => {
        console.log(element.trim().endsWith('po') ? 'FILIPINO' : element.trim().endsWith('mnida') ? 'KOREAN' : 'JAPANESE');
    });
});

let s = '';

process.stdin.on('data', function (i) {
    s += i;
});

process.stdin.on('end', function () {
    s = s.trim().split('\n');
    s.shift();
    s.forEach(element => {
        element = element.trim()
        console.log(element.endsWith('po') ? 'FILIPINO' : element.endsWith('mnida') ? 'KOREAN' : 'JAPANESE');
    });
});

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

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  const returnLang = (word) => {
    switch (word) {
      case 'desu': return 'JAPANESE';
      case 'masu': return 'JAPANESE';
      case 'po': return 'FILIPINO';
      case 'mnida': return 'KOREAN';
    }
  }
  let _result = ''
  const findOnStart = (el) => {
    const myRe = /(desu)|(masu)|(po)|(mnida)/g;
    let _answer = el.match(myRe)
    _answer = _answer[_answer.length - 1]
    const _lang = returnLang(_answer)
    if (_result !== '')
      _result += `\n${_lang}`
    else
      _result = _lang
  }
  const words = [...input.slice(1)]
  words.forEach(el => {
      findOnStart(el)
  })
  console.log(_result)
})

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

  const t = parseInt(arr.shift())

  for(let j = 0; j < t; j++) {
    const str = arr[j]
    const len = str.length
    // console.log(str, len, str.substr(len - 4), 'sdfdssssssssssss')

    let s = str.substr(len - 2)

    if(str.substr(len - 2) == 'po') console.log('FILIPINO')
    else if(len >= 4 && (str.substr(len - 4) == 'desu' || str.substr(len - 4) == 'masu')) console.log('JAPANESE')
    else if(len >= 5 && str.substr(len - 5) == 'mnida') console.log('KOREAN')

  }
})

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

rl.on('line', (str) => {
  if (c === 0) {
    c++;
    return;
  }

  if (str.endsWith('po')) {
    console.log('FILIPINO');
  }
  else if (str.endsWith('mnida')) {
    console.log('KOREAN');
  }
  else {
    console.log('JAPANESE');
  }

  c++;
});

const readline = require('readline');

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

rl.on('line', data => {
    if (data.endsWith('po')) {
        process.stdout.write('FILIPINO\n');
    } else if (data.endsWith('desu') || data.endsWith('masu')) {
        process.stdout.write('JAPANESE\n');
    } else if (data.endsWith('mnida')) {
        process.stdout.write('KOREAN\n');
    }
});

const readline = require("readline");

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

let words = [];
let i = 0;

const solver = () => {
  for (let i = 0; i < words.length; i++) {
    if (words[i].lastIndexOf('po') == words[i].length - 2) {
      console.log('FILIPINO');
    } else if (words[i].lastIndexOf('desu') == words[i].length - 4 || words[i].lastIndexOf('masu') == words[i].length - 4) {
      console.log('JAPANESE');
    } else if (words[i].lastIndexOf('mnida') == words[i].length - 5) {
      console.log('KOREAN');
    }
  }
};

rl.question('', (a) => {
  rl.on('line', (l) => {
    words.push(l);
    if (++i == a) {
      rl.close();
    }
  })

  rl.on('close', () => {
    solver();
  })
});

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

let index = 0;

// single line input
readline.on('line', line => {
  if (index++) {
    if (line.substr(line.length - 2) === "po") return console.log("FILIPINO");
    else if (line.substr(line.length - 4) === "desu" || line.substr(line.length - 4) === "masu") return console.log('JAPANESE');
    else if (line.substr(line.length - 5) === "mnida") return console.log("KOREAN");
  }
});

// readline.on("close", () => {
//   console.log(count, values);
// });

var s = '';
var n = 0;

process.stdin.on('data', function (c) {
    s += c;
});

process.stdin.on('end', function () {
    s = s.trim().split('\n');
    main();
});

function readline() {
    return s[n++];
}

function main() {
    var T = parseInt(readline());
    for (var t = 0; t < T; ++t) {
        var line = readline().trim();
        if (line.length >= 2 && line.slice(-2) === 'po') {
            console.log('FILIPINO');
        } else if (line.length >= 5 && line.slice(-5) === 'mnida') {
            console.log('KOREAN');
        } else {
            console.log('JAPANESE');
        }
    }
}

// A Suffix Three
//

var numberOfLines = parseInt(readline());

for( var i = 0; i < numberOfLines; i++ ) {
    var str = readline();
    if( str.endsWith("po") ) {
        print("FILIPINO");
    } else if( str.endsWith("mnida") ) {
        print("KOREAN");
    } else {
        print("JAPANESE");
    }
}

(function main()
{
    var n=readline();
    for(var i=1;i<=parseInt(n);i++)
    {
        var string=readline();
        var len=string.length;
        //print(string.substring(len-2,len));
        if(string.substring(len-2,len)=="po")
            print("FILIPINO");
        else if(string.substring(len-4,len)=="desu"||string.substring(len-4,len)=="masu")
            print("JAPANESE");
        else if(string.substring(len-5,len)=="mnida")
            print("KOREAN");
    }
})();

function myout(t){print(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main() {
  var N = myconv(readline(),0);
  var output = [];
  for(var i = 0; i < N; i++){
      var str = readline();
      var check = "";
      for(var j = str.length-1; j > str.length-1-6; j--){
          check += str.substring(j,j+1);
          //myout(check);
          if(check == "op"){
              output.push("FILIPINO");
              break;
          }else if(check == "used" || check == "usam"){
              output.push("JAPANESE");
              break;
          }else if(check == "adinm"){
              output.push("KOREAN");
              break;
          }
      }
  }
  myout(output.join("\n"));
}

Main();

var q = parseInt(readline());
var input = []
while (q != 0) {
    q--;
    input.push(readline().trim());
}
var langs = {
    po: "FILIPINO",
    su: "JAPANESE",
    da: "KOREAN"
}
print(input.map(z => langs[z.slice(-2)]).join("\n"))

var n = parseInt(readline());
while(n-- > 0) {
    var s = readline();

    if(s.slice(s.length - 2) === 'po'){
        print('FILIPINO');
    } else if(s.slice(s.length - 5) === 'mnida') {
        print('KOREAN');
    } else {
        print('JAPANESE');
    }
}

//var input = parseInt(readline());

var n = parseInt(readline());
while(n-- > 0) {
  var ar = readline().split(" ");
  var s = ar[0], L = s.length;

  if (s.slice(L - 2) === "po") print("FILIPINO");
  else if (s.slice(L - 5) === "mnida") print("KOREAN");
  else print("JAPANESE");

}

//var input = readline();

var T = parseInt(readline());
while (T-- > 0) {
  var ar = readline().split(' ');
  var s = ar[0];

  if (s[s.length - 1] == "o" && s[s.length - 2] == "p") print("FILIPINO");
  else if ((s[s.length - 1] == "u" && s[s.length - 2] == "s" && s[s.length - 3] == "e" && s[s.length - 4] == "d") ||
         (s[s.length - 1] == "u" && s[s.length - 2] == "s" && s[s.length - 3] == "a" && s[s.length - 4] == "m")) print("JAPANESE");
  else print("KOREAN");
}

//var input = parseInt(readline());

var n = parseInt(readline());
while(n-- > 0) {
  var Arr = readline().split(" ");
  var S = Arr[0];
  var s = S.split("").reverse().join("");

  if(s.substr(0, 2) === 'op') print("FILIPINO");
  else if (s.substr(0, 5) === "adinm") print("KOREAN");
  else print("JAPANESE");

}

let s = '';

process.stdin.on('data', function (i) {
    s += i;
});

process.stdin.on('end', function () {
    s = s.trim().split('\n');
    s.shift();
    s.forEach(element => {
        console.log(element.trim().endsWith('po') ? 'FILIPINO' : element.endsWith('mnida') ? 'KOREAN' : 'JAPANESE');
    });
});

var s = '';
var n = 0;

process.stdin.on('data', function (i) {
    s += i;
});

// ctrl + D
process.stdin.on('end', function () {
    s = s.split('\n');
    s.shift();
    s.forEach(element => {
        console.log(element.endsWith('po') ? 'FILIPINO' : element.endsWith('mnida') ? 'KOREAN' : 'JAPANESE');
    });
});

var s = '';
var n = 0;

process.stdin.on('data', function (i) {
    s += i;
});

// ctrl + D
process.stdin.on('end', function () {
    s = s.trim().split('\n');
    s.shift();
    console.log(s);
    s.forEach(element => {
        console.log(element.endsWith('po') ? 'FILIPINO' : element.endsWith('mnida') ? 'KOREAN' : 'JAPANESE');
    });
});

var s = '';
var n = 0;

process.stdin.on('data', function (i) {
    s += i;
});

// ctrl + D
process.stdin.on('end', function () {
    s = s.trim().split('\n');
    s.shift();
    s.forEach(element => {
        console.log(element.endsWith('po') ? 'FILIPINO' : element.endsWith('mnida') ? 'KOREAN' : 'JAPANESE');
    });
});

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

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
const languageCheck = ['desu', 'masu', 'po', 'mnida']
const returnLang = (word) => {
  switch (word) {
    case 'desu': return 'JAPANESE'; break;
    case 'masu': return 'JAPANESE'; break;
    case 'po': return 'FILIPINO'; break;
    case 'mnida': return 'KOREAN'; break;
  }
}
let _result = ''
const findOnEnd = (el) => {
  const lengthWord = el.length
  let stop = false
  let checkWord = ''
  let char = lengthWord - 1
  while (!stop) {
    if (char >= 0) {
      if (!languageCheck.includes(checkWord)) {
        checkWord = el.charAt(char) + checkWord
      } else {
        const _lang = returnLang(checkWord)
        if (_result !== '')
          _result += `\n${_lang}`
        else
          _result = _lang
        stop = true
      }
      char--
    } else {
      stop = true
    }
  }
}
const findOnStart = (el) => {
  let lang = ''
  if (el.match(/(desu|masu)/g)) {
    _lang = returnLang('desu')
  } else if (el.match(/(po)/g)) {
    _lang = returnLang('po')
  } else if (el.match(/(mnida)/g)) {
    _lang = returnLang('mnida')
  }
  if (_result !== '')
    _result += `\n${_lang}`
  else
    _result = _lang
}
const words = [...input.slice(1)]
words.forEach(el => {
  if (el.match(/(_)/g)) {
    findOnEnd(el)
  } else {
    findOnStart(el)
  }
})
console.log(_result)
})

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

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
const languageCheck = ['desu', 'masu', 'po', 'mnida']
const returnLang = (word) => {
  switch (word) {
    case 'desu': return 'JAPANESE'; break;
    case 'masu': return 'JAPANESE'; break;
    case 'po': return 'FILIPINO'; break;
    case 'mnida': return 'KOREAN'; break;
  }
}
const count = parseInt(input[0], 10)
const words = [...input.slice(1)]
let _result = ''
words.forEach(el => {
  const lengthWord = el.length
  let stop = false
  let checkWord = ''
  let char = lengthWord - 1
  while (!stop) {
    if (char >= 0) {
      if (!languageCheck.includes(checkWord)) {
        checkWord = el.charAt(char) + checkWord
      } else {
        const _lang = returnLang(checkWord)
        if (_result !== '')
          _result += `\n${_lang}`
        else
          _result = _lang
        stop = true
      }
      char--
    } else {
      stop = true
    }
  }
})
console.log(_result)
})

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

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
    const languageCheck = ['desu', 'masu', 'po', 'mnida']
  const returnLang = (word) => {
    switch (word) {
      case 'desu': return 'JAPANESE'; break;
      case 'masu': return 'JAPANESE'; break;
      case 'po': return 'FILIPINO'; break;
      case 'mnida': return 'KOREAN'; break;
    }
  }
  let _result = ''
  const findOnEnd = (el) => {
    const lengthWord = el.length
    let stop = false
    let checkWord = ''
    let char = lengthWord - 1
    while (!stop) {
      if (char >= 0) {
        if (!languageCheck.includes(checkWord)) {
          checkWord = el.charAt(char) + checkWord
        } else {
          const _lang = returnLang(checkWord)
          if (_result !== '')
            _result += `\n${_lang}`
          else
            _result = _lang
          stop = true
        }
        char--
      } else {
        stop = true
      }
    }
  }
  const findOnStart = (el) => {
    const myRe = /(desu)|(masu)|(po)|(mnida)/g;
    const _answer = el.match(myRe)[0]
    const _lang = returnLang(_answer)
    if (_result !== '')
      _result += `\n${_lang}`
    else
      _result = _lang
  }
  const words = [...input.slice(1)]
  words.forEach(el => {
    if (el.match(/(_)/g)) {
      findOnEnd(el)
    } else {
      findOnStart(el)
    }
  })
  console.log(_result)
})

const readline = require('readline');

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

rl.on('line', data => {
    if (data.endsWith('po')) {
        process.stdout.write('FILIPINO\n');
    } else if (data.endsWith('desu') || data.endsWith('masu')) {
        process.stdout.write('JAPANESE\n');
    } else {
        process.stdout.write('KOREAN\n');
    }
});

rl.on('close', () => {
    process.exit(0);
});

var s = '';
var n = 0;

process.stdin.on('data', function (c) {
    s += c;
});

process.stdin.on('end', function () {
    s = s.trim().split('\n');
    main();
});

function readline() {
    return s[n++];
}

function main() {
    var T = parseInt(readline());
    for (var t = 0; t < T; ++t) {
        var line = readline();
        if (line.length >= 2 && line.slice(-2) === 'po') {
            console.log('FILIPINO');
        } else if (line.length >= 5 && line.slice(-5) === 'mnida') {
            console.log('KOREAN');
        } else {
            console.log('JAPANESE');
        }
    }
}

function main()
{
    var n=readline();
    for(var i=1;i<=parseInt(n);i++)
    {
        var string=readline();
        var len=string.length;
        if(string[len-1]=='p'&&string[len-2]=='o')
            console.log("FILIPINO");
        else if(string.substring(len-4,len-1)=="desu"||string.substring(len-4,len-1)=="masu")
            console.log("JAPANESE");
        else if(string.substring(len-5,len-1)=="mnida")
            console.log("KOREAN");
    }
}

a = readline();
print(
    typeof a === 'number' ?
        skip :
    a.slice(a.length - 1, a.length) === 'po' ?
        'FILIPINO' :
    a.slice(a.length - 4, a.length) === 'desu' || a.slice(a.length - 4, a.length) === 'masu' ?
        'JAPANESE' :
        'KOREAN'
);

a = readline();
print(
    typeof a === 'number' && a<=30 ?
        '' :
    a.slice(a.length - 1, a.length) === 'po' ?
        'FILIPINO' :
    a.slice(a.length - 4, a.length) === 'desu' || a.slice(a.length - 4, a.length) === 'masu' ?
        'JAPANESE' :
        'KOREAN'
);

function suffix(str){
  if(str.slice(str.length-1, str.length) === 'po'){
    return "FILIPINO";
  } else if(str.slice(str.length-4, str.length) === 'desu' || str.slice(str.length-4, str.length) === 'masu'){
    return 'JAPANESE';
  } else if(str.slice(str.length-5, str.length)){
    return 'KOREAN';
  }
};

function suffix(str){
  if(string.splice(str.length-2, str.length-1) === 'po'){
    return "FILIPINO";
  } else if(string.splice(str.length-4, str.length-1) === 'desu' || string.splice(str.length-4, str.length-1) === 'masu'){
    return 'JAPANESE';
  } else {
    return 'KOREAN';
  }
}

var n = parseInt(readline());
while(n-- > 0) {
    var s = readline();

    if(s.slice(s.length - 1 , s.length) === 'po'){
        print('FILIPINO');
    } else if(s.slice(s.length - 5 , s.length) === 'mnida') {
        print('KOREAN');
    } else {
        print('JAPANESE');
    }
}


Phoenix has $$$n$$$ coins with weights $$$2^1, 2^2, \dots, 2^n$$$. He knows that $$$n$$$ is even.He wants to split the coins into two piles such that each pile has exactly $$$\frac{n}{2}$$$ coins and the difference of weights between the two piles is minimized. Formally, let $$$a$$$ denote the sum of weights in the first pile, and $$$b$$$ denote the sum of weights in the second pile. Help Phoenix minimize $$$|a-b|$$$, the absolute value of $$$a-b$$$.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 30$$$; $$$n$$$ is even) — the number of coins that Phoenix has.

For each test case, output one integer — the minimum possible difference of weights between the two piles.

NoteIn the first test case, Phoenix has two coins with weights $$$2$$$ and $$$4$$$. No matter how he divides the coins, the difference will be $$$4-2=2$$$.In the second test case, Phoenix has four coins of weight $$$2$$$, $$$4$$$, $$$8$$$, and $$$16$$$. It is optimal for Phoenix to place coins with weights $$$2$$$ and $$$16$$$ in one pile, and coins with weights $$$4$$$ and $$$8$$$ in another pile. The difference is $$$(2+16)-(4+8)=6$$$.

// Q: https://codeforces.com/contest/1348/problem/A

const readline = require('readline');

let input = [];

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

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

rl.on('close', () => {
	const test = parseInt(input[0]);
	for (let i=0; i < test; i++) {
		let n = parseInt(input[i+1]);
		console.log(solution(n));
	}
});

function solution(n) {
	return (Math.pow(2, parseInt(n/2)+1) - 2);
}

const readline = require('readline');

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

let lines = [];
rl.on('line', (line) => {
    lines.push(line);
}).on('close', () => {
  for (i = 1; i < lines.length; i++) {
    const n = +lines[i];
    let firstNum = Math.pow(2, n);
    let secondNum = Math.pow(2, n - 1);

    let f = 1;
    let s = n - 2;

    while (f < s) {
      firstNum += Math.pow(2, f);
      secondNum += Math.pow(2, s);

      f++; s--;
    }

    process.stdout.write(`${Math.abs(firstNum - secondNum)}\n`);
  }
});

var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj = null;
var inputFile = [];
reader.on('line', function(input){inputFile.push(input);});
reader.on('close', function(){
  obj = init(inputFile);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
});
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    "list" : input, "index" : 0, "max" : input.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error("debug:" + require("util").inspect(t,false,null));}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var n = nextInt();
		var sum1 = 0;
		var sum2 = 0;
		var list = new Array(n);
		for(var j = 1; j <= n; j++){
			list[j - 1] = Math.pow(2,j);
		}
		if(n == 2){
			output[i] = 2;
		}else{
			sum1 += list.pop();
			for(var j = 0; j < (n / 2) - 1; j++){
				sum1 += list.shift();
			}
			while(list.length > 0){
				sum2 += list.pop();
			}
			output[i] = Math.abs(sum1 - sum2);
		}

	}
	myout(myconv(output,9));
}

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

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    return;
  }

  let n = +d;
  let ans = 0;
  let v = 2;
  const mid = n / 2;

  for (let i = 1; i < n; i++) {
    if (i < mid) {
      ans += v ** i;
    }
    else {
      ans -= v ** i;
    }
  }

  ans += v ** n;

  console.log(ans);

  c++;
});

const processData = (lines) => {
  const nums = +lines[0]
  for (let i =0; i<nums;i++) {
    const n = +lines[i+1]
    let first = 0
    let second = 0
    for (let j=1; j<=n; j++) {
      if (j === n) {
        first += Math.pow(2, j)
      } else {
        if (j < n/2) {
          first += Math.pow(2, j)
        } else {
          second += Math.pow(2, j)
        }
      }
    }
    console.log(first - second)
  }
}

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

function processData(input) {
    let inpArr = input.split('\n');
    for (var k = 1; k <= (parseInt(inpArr[0])); k++) {
        console.log(minimum(parseInt(inpArr[k])));
    }
}

function minimum (n) {
    let heavy = Math.pow(2, n);
    let light = 0;

    for (let i = 0; i < ((n/2)-1); i ++) {
        heavy += Math.pow(2, i+1);
    }

    for (let j = ((n/2) - 1); j < n-1; j++) {
        light += Math.pow(2, j+1);
    }

    return heavy - light;
}

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

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

// Sample code to perform I/O:

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

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

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

/**
 *
 * @param {*} str
 * @param {*} seperator
 */
function splitter(str, seperator = '') {
    return str.trim().split(seperator);
}

/**
 *
 * @param {*} arr
 */
function strToNumArr(arr = []) {
    return arr.map(num => Number(num));
}

/**
 *
 * @param {*} num1
 * @param {*} num2
 */
function matrixArray(num1, num2) {
    return Array(num1).fill(Array(num2));
}

let log = function () {
    return Function.prototype.bind.call(console.log, console, '');
}();

function removeEmptyItem(arr, index) {
    return arr.slice(0, index).concat(arr.slice(index + 1, arr.length));
}

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

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

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

    let n = strToNumArr(splitter(str, '\n'));
    let t = n[0];
    let weights = n.slice(1);

    for (let index = 0; index < t; index++) {
        let sum1 = 1 << weights[index], sum2 = 0;
        for (let index2 = 1; index2 < Math.floor(weights[index] / 2); index2++) {
            sum1 += 1 << index2;
        }
        for (let index3 = Math.floor(weights[index] / 2); index3 < weights[index]; index3++) {
            sum2 += 1 << index3;
        }

        console.log(sum1 - sum2);
    }

    // return ''.toString();
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
/**
    5
    1 2
    2 3
    2 4
    4 5
**/

function main() {
    var range = readline();
    function minimum (n) {
        let heavy = Math.pow(2, n);
        let light = 0;

        for (let i = 0; i < ((n/2)-1); i ++) {
            heavy += Math.pow(2, i+1);
        }

        for (let j = ((n/2) - 1); j < n-1; j++) {
            light += Math.pow(2, j+1);
        }

        return heavy - light;
    }

    for(var r=0;r<range;r++) {
        var number = parseInt(readline());
        console.log(minimum(number));

    }
}

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
//atcoderのサンプルは最後に改行入れること
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
    var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var n = nextInt();
		var sum1 = 0;
		var sum2 = 0;
		var list = new Array(n);
		for(var j = 1; j <= n; j++){
			list[j - 1] = Math.pow(2,j);
		}
		if(n == 2){
			output[i] = 2;
		}else{
			sum1 += list.pop();
			for(var j = 0; j < (n / 2) - 1; j++){
				sum1 += list.shift();
			}
			while(list.length > 0){
				sum2 += list.pop();
			}
			output[i] = Math.abs(sum1 - sum2);
		}

	}
	myout(myconv(output,9));
}

var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)
var write = this.write || require('lol-io').write; //write --> creates output.txt with output
var readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt

var t = Number(readline().replace(/\r$/, '')), n, a, b;

for (i = 0; i < t; i++) {
    a = 0;
    b = 0;
    n = Number(readline().replace(/\r$/, ''));

    a += Math.pow(2, n);
    for (j = 0; j < n/2; j++) {
        b += Math.pow(2, n - 1 - j);
    }
    for (j = 1; j < n/2; j++) {
        a += Math.pow(2, j)
    }

    print(a - b);
}

var t = readline()
for (i=0;i<t;i++){
    var n = readline()
    print(Math.pow(2,n/2 + 1)-2)
}

const readline = require('readline');

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

let lines = [];
rl.on('line', (line) => {
    lines.push(line);
}).on('close', () => {
  for (i = 1; i < lines.length; i++) {
    const n = +lines[i];
    let firstNum = Math.pow(2, n);
    let secondNum = Math.pow(2, n - 1);

    let f = 1;
    let s = n - 2;

    while (f < s) {
      firstNum += Math.pow(2, f);
      secondNum += Math.pow(2, s);

      f++; s--;
    }

    process.stdout.write(Math.abs(firstNum - secondNum).toString());
  }
});

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

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    return;
  }

  let n = +d;
  let ans = 0;
  const arr = [];
  let v = 2;
  let inc = 1;
  let dec = n;
  const mid = Math.floor(n / 2);

  for (let i = 0; i < mid; i++) {
    arr.push(v ** inc);
    arr.push(v ** dec);

    inc++;
    dec--;
  }

  for (let i = 0; i < n; i++) {
    if (i < mid) {
      ans += arr[i];
    }
    else {
      ans -= arr[i];
    }
  }

  console.log(Math.abs(ans));

  c++;
});

function processData(input) {
    let inpArr = input.split('\n');
    for (var k = 1; k < inpArr[0]; k++) {
        console.log(minimum(parseInt(inpArr[k])));
    }
}

function minimum (n) {
    let heavy = Math.pow(2, n);;
    let light = 0;

    for (let i = 0; i < ((n/2)-1); i ++) {
        heavy += Math.pow(2, i+1);
    }

    for (let j =((n/2) - 1); j < n-1; j++) {
        light = Math.pow(2, j+1);
    }

    return heavy - light;
}

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

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

'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++];
}
/**
    5
    1 2
    2 3
    2 4
    4 5
**/

function main() {
    var range = readline();

    for(var r=0;r<range;r++) {
        var number = parseInt(readline());

        var output = Math.pow(2 , number);
        if(output > 5) {
            console.log((output / 2) - 2);
        } else {
            console.log(output / 2);
        }

    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
/**
    5
    1 2
    2 3
    2 4
    4 5
**/

function main() {
    var range = readline();

    for(var r=0;r<range;r++) {
        var number = parseInt(readline());

        console.log(2 * (number - 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++];
}
/**
    5
    1 2
    2 3
    2 4
    4 5
**/

function main() {
    var range = readline();

    for(var r=0;r<range;r++) {
        var number = parseInt(readline());

        var output = Math.pow(2 , number-1);
        if(output > 2) {
            console.log(output - 2);
        } else {
            console.log(output);
        }

    }
}


One important contest will take place on the most famous programming platform (Topforces) very soon!The authors have a pool of $$$n$$$ problems and should choose at most three of them into this contest. The prettiness of the $$$i$$$-th problem is $$$a_i$$$. The authors have to compose the most pretty contest (in other words, the cumulative prettinesses of chosen problems should be maximum possible).But there is one important thing in the contest preparation: because of some superstitions of authors, the prettinesses of problems cannot divide each other. In other words, if the prettinesses of chosen problems are $$$x, y, z$$$, then $$$x$$$ should be divisible by neither $$$y$$$, nor $$$z$$$, $$$y$$$ should be divisible by neither $$$x$$$, nor $$$z$$$ and $$$z$$$ should be divisible by neither $$$x$$$, nor $$$y$$$. If the prettinesses of chosen problems are $$$x$$$ and $$$y$$$ then neither $$$x$$$ should be divisible by $$$y$$$ nor $$$y$$$ should be divisible by $$$x$$$. Any contest composed from one problem is considered good.Your task is to find out the maximum possible total prettiness of the contest composed of at most three problems from the given pool.You have to answer $$$q$$$ independent queries.If you are Python programmer, consider using PyPy instead of Python when you submit your code.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of problems. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$2 \le a_i \le 2 \cdot 10^5$$$), where $$$a_i$$$ is the prettiness of the $$$i$$$-th problem. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$.

For each query print one integer — the maximum possible cumulative prettiness of the contest composed of at most three problems from the given pool of problems in the query.

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

function solve(cur, arr) {
  for (let i = arr.length - 1; i >= 0; i--) {
    let fail = false;
    let num = arr[i];
    cur.forEach(n => {fail |= (n % num == 0); });
    if (!fail) {
      cur.push(num);
      if (cur.length == 3)
        break;
    }
  }
  return cur.reduce((a, b) => a + b);
}

process.stdin.on('end', async () => {
  const {EOL} = require('os');
  const lines = c.split(EOL);
  let t = parseInt(lines[0]);
  for (let tt = 1; tt <= t; tt++) {
    let arr = [...new Set(lines[tt * 2].split(' ').map(v => parseInt(v)))].sort((a, b) => a - b);
    let maximum = arr.pop();
    let cur = solve([ maximum ], arr);
    let arg = [0];
    arr.forEach(e => {if (maximum % e == 0) arg[0] = e });
    if (arg[0]) cur = Math.max(cur, solve(arg, arr));
    console.log(cur);
  }
});