// process.stdin.setEncoding('utf8');
let lines = [];
// process.stdin.on('readable', () => {
//   let chunk;
//   // Use a loop to make sure we read all available data.
//   while ((chunk = process.stdin.read()) !== null) {
//     lines.push(chunk);
//     process.stdout.write('end');
//     if (lines.length === 2) {
//       process.stdout.write(`${equivalent(lines[0], lines[1]) ? 'YES' : 'NO'}`);
//       lines = [];
//     }
//   }
// });

// process.stdin.on('end', () => {
//   process.stdout.write('end');
// });

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

rl.on('line', function (line) {
  lines.push(line);
  if (lines.length === 2) {
    console.log(`${buildKey(lines[0]) === buildKey(lines[1]) ? 'YES' : 'NO'}`);
    lines = [];
    rl.close();
  }
})

function buildKey(str) {
  if ((str.length % 2) != 0) return str;
  const mid = str.length / 2;
  const lkey = buildKey(str.slice(0, mid)), rkey = buildKey(str.slice(mid));
  if (lkey <= rkey) {
    return `${lkey}${rkey}`;
  } else {
    return `${rkey}${lkey}`;
  }
}

function equivalent(strA, strB) {
  // process.stdout.write('[' + strA + '-' + strB + ']')
  if (strA.length !== strB.length) {
    return false;
  }
  // condition 1
  if (strA === strB) {
    return true;
  }
  // condition 2
  const length = strA.length;
  if ((length % 2) === 0) {
    const mid = length / 2;
    const a1 = strA.slice(0, mid), a2 = strA.slice(mid);
    const b1 = strB.slice(0, mid), b2 = strB.slice(mid);
    if (equivalent(a1, b1) && equivalent(a2, b2))
      return true;
    if (equivalent(a1, b2) && equivalent(a2, b1))
      return true;
  }

  return false;
}

var print = this.print || require("lol-io").print;
var readline = this.readline || require("lol-io").readline;

const s1 = readline(); const s2 = readline();
print(is_equivalent(s1, s2)  ? 'YES' : 'NO');

function is_equivalent(s1, s2) {
  if(s1.length % 2) return s1 === s2;

  const n = s1.length;
  const a1 = s1.substr(0, n / 2); const a2 = s1.substr(n / 2, n / 2);
  const b1 = s2.substr(0, n / 2); const b2 = s2.substr(n / 2, n / 2);
  return ((is_equivalent(a1, b2) && is_equivalent(a2, b1) || is_equivalent(a1, b1) && is_equivalent(a2, b2)));
}

var print = this.print || require("lol-io").print;
var readline = this.readline || require("lol-io").readline;

const s1 = readline(); const s2 = readline();
print(is_equivalent(s1, s2)  ? 'YES' : 'NO');

function is_equivalent(s1, s2) {
  if(s1.length & 1) return s1 === s2;

  const n = s1.length;
  const a1 = s1.substr(0, n / 2); const a2 = s1.substr(n / 2, n / 2);
  const b1 = s2.substr(0, n / 2); const b2 = s2.substr(n / 2, n / 2);
  return ((is_equivalent(a1, b2) && is_equivalent(a2, b1) || is_equivalent(a1, b1) && is_equivalent(a2, b2)));
}

function equal(a, b) {
    var size = a.length;
    var half = a.length / 2;

    var a1 = a.substr(0,half);
    var a2 = a.substr(half,a.length);
    var b1 = b.substr(0,half);
    var b2 = b.substr(half,b.length);

    if (a === b) {
        return true;
    } else if (size % 2 === 1 || size <= 1) {
        return false;
    } else if (equal(a1, b2) && equal(a2, b1)) {
        return true;
    } else if (equal(a1, b1) && equal(a2, b2)) {
        return true;
    } else {
        return false;
    }
}

var input_a = readline();
var input_b = readline();

equal(input_a, input_b) ? print('YES') : print('NO');

const s1 = readline(); const s2 = readline();
print(is_equivalent(s1, s2)  ? 'YES' : 'NO');

function is_equivalent(s1, s2) {
  if(s1.length % 2 === 1) return s1 === s2;

  const n = s1.length;
  const a1 = s1.substr(0, n / 2); const a2 = s1.substr(n / 2, n / 2);
  const b1 = s2.substr(0, n / 2); const b2 = s2.substr(n / 2, n / 2);
  return ((is_equivalent(a1, b2) && is_equivalent(a2, b1) || is_equivalent(a1, b1) && is_equivalent(a2, b2)));
}

const s1 = readline(); const s2 = readline();
print(is_equivalent(s1, s2)  ? 'YES' : 'NO');

function is_equivalent(s1, s2) {
  if(s1.length === 1 || s1 === s2) return s1 === s2;

  n = s1.length;
  a1 = s1.substr(0, n / 2); a2 = s1.substr(n / 2, n / 2);
  b1 = s2.substr(0, n / 2); b2 = s2.substr(n / 2, n / 2);
  return ((is_equivalent(a1, b2) && is_equivalent(a2, b1) || is_equivalent(a1, b1) && is_equivalent(a2, b2)));
}

const s1 = readline(); const s2 = readline();
print(is_equivalent(s1, s2)  ? 'YES' : 'NO');

function is_equivalent(s1, s2) {
  if(s1.length % 2 === 1 || s1 === s2) return s1 === s2;

  n = s1.length;
  a1 = s1.substr(0, n / 2); a2 = s1.substr(n / 2, n / 2);
  b1 = s2.substr(0, n / 2); b2 = s2.substr(n / 2, n / 2);
  return ((is_equivalent(a1, b2) && is_equivalent(a2, b1) || is_equivalent(a1, b1) && is_equivalent(a2, b2)));
}

const s1 = readline(); const s2 = readline();
print(is_equivalent(s1, s2)  ? 'YES' : 'NO');

function is_equivalent(s1, s2) {
  if(s1.length % 2 === 1) return s1 === s2;

  n = s1.length;
  a1 = s1.substr(0, n / 2); a2 = s1.substr(n / 2, n / 2);
  b1 = s2.substr(0, n / 2); b2 = s2.substr(n / 2, n / 2);
  return ((is_equivalent(a1, b2) && is_equivalent(a2, b1) || is_equivalent(a1, b1) && is_equivalent(a2, b2)));
}

var a = 'aaba'.split('');
var b = 'abaa'.split('');

if (a.length != b.length) {
  print('NO');
} else {
  for (var index = 0; index < a.length; index++) {
    for (var j = 0; j < a.length - 1; j++) {
      if (a[j] < a[j + 1]) {
        aux = a[j];
        a[j] = a[j + 1];
        a[j + 1] = aux;
      }
      if (b[j] < b[j + 1]) {
        aux = b[j];
        b[j] = b[j + 1];
        b[j + 1] = aux;
      }
    }
  }
  if (a.join() == b.join()) {
    print('YES');
  } else {
    print('NO');
  }
}

// process.stdin.setEncoding('utf8');
let lines = [];
// process.stdin.on('readable', () => {
//   let chunk;
//   // Use a loop to make sure we read all available data.
//   while ((chunk = process.stdin.read()) !== null) {
//     lines.push(chunk);
//     process.stdout.write('end');
//     if (lines.length === 2) {
//       process.stdout.write(`${equivalent(lines[0], lines[1]) ? 'YES' : 'NO'}`);
//       lines = [];
//     }
//   }
// });

// process.stdin.on('end', () => {
//   process.stdout.write('end');
// });

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

rl.on('line', function (line) {
  lines.push(line);
  if (lines.length === 2) {
    console.log(`${buildKey(lines[0]) === buildKey(lines[1]) ? 'YES' : 'NO'}`);
    lines = [];
    rl.close();
  }
})

function buildKey(str) {
  if ((str % 2) != 0) return str;

  const mid = str.length / 2;
  const lkey = buildKey(str.slice(0, mid)), rkey = buildKey(str.slice(mid));
  if (lkey <= rkey) {
    return `${lkey}${rkey}`;
  } else {
    return `${rkey}${lkey}`;
  }
}

function equivalent(strA, strB) {
  // process.stdout.write('[' + strA + '-' + strB + ']')
  if (strA.length !== strB.length) {
    return false;
  }
  // condition 1
  if (strA === strB) {
    return true;
  }
  // condition 2
  const length = strA.length;
  if ((length % 2) === 0) {
    const mid = length / 2;
    const a1 = strA.slice(0, mid), a2 = strA.slice(mid);
    const b1 = strB.slice(0, mid), b2 = strB.slice(mid);
    if (equivalent(a1, b1) && equivalent(a2, b2))
      return true;
    if (equivalent(a1, b2) && equivalent(a2, b1))
      return true;
  }

  return false;
}


var nt = readline().split(' ').map(v=>(parseInt(v)))
var n = nt[0]
var t = nt[1]

var bestR = 1, bestT=-1;
for(var i=0;i<n; i++) {
    var sd = readline().split(' ').map(v=>(parseInt(v)))
    var s = sd[0]
    var d = sd[1]

    var D = (t>=s) ? Math.floor((t-s)/d):0;
    var cur = s + D*d;
    var waitingTime = (cur>=t) ? cur-t: (cur+d-t);

    //print('>>', s, '+', D, '*', d, cur, waitingTime)
    if(bestT===-1 || (waitingTime<bestT)) {
        bestT = waitingTime;
        bestR = i + 1;
    }
//    print(i, s,d, cur, bestT, bestR);
}
print(bestR);

const nt = readline().split(" ").map(e => parseInt(e));
const n = nt[0];
const t = nt[1];

var ans = 0;
var timeA;
for (var i = 0; i < n; i++) {
    var sd = readline().split(" ").map(e => parseInt(e));
    var s = sd[0];
    var d = sd[1];

    var time;
    for (time = s; time < t; time += d) {

    }
    if (ans === 0 || timeA > time) {
        ans = i + 1;
        timeA = time;
    }
}
print(ans);

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

function sol() {
  const [meta, ...routes] = input
    .split('\n')
    .map(line => line.split(' '));
  const [n, t] = meta.map(Number);
  let minRouteNum;
  let minWaitTime = Number.MAX_SAFE_INTEGER;
  for (let i = 0; i < n; ++i) {
    const [si, di] = routes[i].map(Number);
    let waitTime;
    if (t <= si) {
      waitTime = si - t;
    } else {
      const k = Math.ceil((t - si) / di);
      waitTime = si + k * di - t;
    }
    if (waitTime < minWaitTime) {
      minRouteNum = i + 1;
      minWaitTime = waitTime;
    }
  }
  process.stdout.write(
    minRouteNum.toString(),
    'utf8',
    () => process.stdout.end()
  );
}

(function() {
    var read = {
        number: function() {
            return +readline();
        },
        arr: function(divider) {
            return readline().split(divider ? divider : '');
        },
        arrNumber: function(divider) {
            return readline()
                .split(divider ? divider : '')
                .map(item => +item);
        }
    }

    var a = read.arrNumber(' ');
    var n = a[0];
    var t = a[1];

    var min;
    var res;
    for(var i = 0, line; i < n; i++) {
        line = read.arrNumber(' ');
        if(line[0] === t) {
            print(i + 1);
            return;
        }

        var time;
        if(line[0] > t) {
           time = line[0];
        }
        else {
            time = Math.ceil((t - line[0]) / line[1]) * line[1] + line[0];
        }

        if(!min || min > time) {
            min = time;
            res = i + 1;
        }
    }

    print(res);
}());

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

function sol() {
  const [meta, ...routes] = input
    .split('\n')
    .map(line => line.split(' '));
  const [n, t] = meta.map(Number);
  let minRouteNum = -1;
  let minWaitTime = 0;
  for (let i = 0; i < n; ++i) {
    const [si, di] = routes[i].map(Number);
    const k = Math.ceil((t - si) / di);
    const waitTime = si + k * di - t;
    if (minRouteNum === -1 ||
      waitTime < minWaitTime) {
      minRouteNum = i + 1;
      minWaitTime = waitTime;
    }
  }
  process.stdout.write(
    minRouteNum.toString(),
    'utf8',
    () => process.stdout.end()
  );
}

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

function sol() {
  const [meta, ...routes] = input
    .split('\n')
    .map(line => line.split(' '));
  const [n, t] = meta.map(Number);
  let minRouteNum;
  let minWaitTime;
  for (let i = 0; i < n; ++i) {
    const [si, di] = routes[i].map(Number);
    const k = Math.ceil(Math.abs(t - si) / di);
    const waitTime = si + k * di - t;
    if (i === 0 || waitTime < minWaitTime) {
      minRouteNum = i + 1;
      minWaitTime = waitTime;
    }
  }
  process.stdout.write(
    minRouteNum.toString(),
    'utf8',
    () => process.stdout.end()
  );
}


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

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

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

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

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

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

  })
}


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 = 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, " "));

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


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

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

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


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

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

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

}

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

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

}

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

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


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

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

    }
}