You are given a tree of $$$n$$$ vertices numbered from $$$1$$$ to $$$n$$$. A tree is a connected undirected graph without cycles. For each $$$i=1,2, \ldots, n$$$, let $$$w_i$$$ be the weight of the $$$i$$$-th vertex. A vertex is called good if its weight is equal to the sum of the weights of all its neighbors.Initially, the weights of all nodes are unassigned. Assign positive integer weights to each vertex of the tree, such that the number of good vertices in the tree is maximized. If there are multiple ways to do it, you have to find one that minimizes the sum of weights of all vertices in the tree.

The first line contains one integer $$$n$$$ ($$$2\le n\le 2\cdot 10^5$$$) — the number of vertices in the tree. Then, $$$n−1$$$ lines follow. Each of them contains two integers $$$u$$$ and $$$v$$$ ($$$1\le u,v\le n$$$) denoting an edge between vertices $$$u$$$ and $$$v$$$. It is guaranteed that the edges form a tree.

In the first line print two integers  — the maximum number of good vertices and the minimum possible sum of weights for that maximum. In the second line print $$$n$$$ integers $$$w_1, w_2, \ldots, w_n$$$ ($$$1\le w_i\le 10^9$$$)  — the corresponding weight assigned to each vertex. It can be proven that there exists an optimal solution satisfying these constraints. If there are multiple optimal solutions, you may print any.

NoteThis is the tree for the first test case:    In this case, if you assign a weight of $$$1$$$ to each vertex, then the good vertices (which are painted black) are $$$1$$$, $$$3$$$ and $$$4$$$. It impossible to assign weights so that all vertices are good vertices. The minimum sum of weights in this case is $$$1+1+1+1=4$$$, and it is impossible to have a lower sum because the weights have to be positive integers.This is the tree for the second test case:    In this case, if you assign a weight of $$$1$$$ to each vertex, then the good vertices (which are painted black) are $$$2$$$ and $$$3$$$. It can be proven that this is an optimal assignment.

const fs=require('fs')
const input=fs
    .readFileSync(0,'utf-8')
    .split('\n')
    .map(line=>line.split(' ').map(Number))
main(input)

function main(input) {
  const n = input[0][0]
  if (n === 2) {
    console.log(2, 2)
    console.log(`1 1`)
    return [2, 2, [1, 1]]
  }
  const g = new Array(n).fill(0).map(() => new Set())
  const p = new Array(n).fill(-1)
  const d = []
  const root = 0 //Math.floor(Math.random() * n)
  for (let i = 1; i < n; i++) {
    const [u, v] = input[i]
    g[u - 1].add(v - 1)
    g[v - 1].add(u - 1)
  }
  let queue = [[root, 0]],
    st = []
  st[root] = 1
  for (let [node, depth] of queue) {
    if (!d[depth]) d[depth] = new Set()
    d[depth].add(node)
    for (let child of g[node]) {
      if (st[child]) continue
      queue.push([child, depth + 1])
      p[child] = node
      st[child] = 1
    }
  }

  const dp = new Array(n).fill(0).map((_, i) => [
      [0, 1],
      [1, i === root ? 0 : 1],
    ]),
    dp1 = new Array(n).fill(0).map(() => [])
  for (let i = d.length - 1; i > 0; i--) {
    for (let node of d[i]) {
      const cur = dp[node],
        parent = dp[p[node]]

      for (let state of [0, 1]) {
        dp1[node][state] = state ^ 1
        if (state) {
          let [[count0, sum0]] = cur
          parent[1][0] += count0
          parent[1][1] += sum0 + 1
        } else {
          let [[count0, sum0], [count1, sum1]] = cur
          if (count0 < count1 || (count0 === count1 && sum0 > sum1)) {
            count0 = count1
            sum0 = sum1
          } else {
            dp1[node][state] = 0
          }
          parent[0][0] += count0
          parent[0][1] += sum0
        }
      }
    }
  }

  const isGood = []
  const [root0, root1] = dp[0]
  isGood[root] = root1[0] > root0[0] || (root1[0] === root0[0] && root1[1] < root0[1]) ? 1 : 0
  queue = [root]
  st = []
  st[root] = 1
  for (let node of queue) {
    for (let child of g[node]) {
      if (st[child]) continue
      st[child] = 1
      isGood[child] = dp1[child][isGood[node]]
      queue.push(child)
    }
  }
  let res = new Array(n).fill(0)
  for (let i = 0; i < n; i++) {
    if (isGood[i] === 0) {
      res[i] = 1
      for (let node of g[i]) {
        if (isGood[node] === 1) res[node]++
      }
    }
  }
  const [max, sum] = dp[root][isGood[root]]
  console.log(max, sum)
  console.log(res.join(' '))
  return [max, sum, res]
}

const readline = require('readline')
const rl = readline.createInterface({
  output: process.stdout,
  input: process.stdin,
})
const input = []
rl.on('line', line => input.push(line.split(' ').map(Number)))
rl.on('close', () => {
  main(input)
})

function main(input) {
  const n = input[0][0]
  if (n === 2) {
    console.log(2, 2)
    console.log(`1 1`)
    return [2, 2, [1, 1]]
  }
  const g = new Array(n).fill(0).map(() => new Set())
  const p = new Array(n).fill(-1)
  const d = []
  const root = 0 //Math.floor(Math.random() * n)
  for (let i = 1; i < n; i++) {
    const [u, v] = input[i]
    g[u - 1].add(v - 1)
    g[v - 1].add(u - 1)
  }
  let queue = [[root, 0]],
    st = []
  st[root] = 1
  for (let [node, depth] of queue) {
    if (!d[depth]) d[depth] = new Set()
    d[depth].add(node)
    for (let child of g[node]) {
      if (st[child]) continue
      queue.push([child, depth + 1])
      p[child] = node
      st[child] = 1
    }
  }

  const dp = new Array(n).fill(0).map((_, i) => [
      [0, 1],
      [1, i === root ? 0 : 1],
    ]),
    dp1 = new Array(n).fill(0).map(() => [])
  for (let i = d.length - 1; i > 0; i--) {
    for (let node of d[i]) {
      const cur = dp[node],
        parent = dp[p[node]]

      for (let state of [0, 1]) {
        dp1[node][state] = state ^ 1
        if (state) {
          let [[count0, sum0]] = cur
          parent[1][0] += count0
          parent[1][1] += sum0 + 1
        } else {
          let [[count0, sum0], [count1, sum1]] = cur
          if (count0 < count1 || (count0 === count1 && sum0 > sum1)) {
            count0 = count1
            sum0 = sum1
          } else {
            dp1[node][state] = 0
          }
          parent[0][0] += count0
          parent[0][1] += sum0
        }
      }
    }
  }

  const isGood = []
  const [root0, root1] = dp[0]
  isGood[root] = root1[0] > root0[0] || (root1[0] === root0[0] && root1[1] < root0[1]) ? 1 : 0
  queue = [root]
  st = []
  st[root] = 1
  for (let node of queue) {
    for (let child of g[node]) {
      if (st[child]) continue
      st[child] = 1
      isGood[child] = dp1[child][isGood[node]]
      queue.push(child)
    }
  }
  let res = new Array(n).fill(0)
  for (let i = 0; i < n; i++) {
    if (isGood[i] === 0) {
      res[i] = 1
      for (let node of g[i]) {
        if (isGood[node] === 1) res[node]++
      }
    }
  }
  const [max, sum] = dp[root][isGood[root]]
  console.log(max, sum)
  console.log(res.join(' '))
  return [max, sum, res]
}

const readline = require('readline')
const rl = readline.createInterface({
  output: process.stdout,
  input: process.stdin,
})
const input = []
rl.on('line', line => input.push(line.split(' ').map(Number)))
rl.on('close', () => {
  main(input)
})

function main(input) {
  function debug(str) {
    console.log(str)
  }
  const n = input[0][0]
  if (n === 2) {
    console.log(2, 2)
    console.log('1 1')
    return [2, 2, [1, 1]]
  }
  debug('构建图')
  const g = new Array(n).fill(0).map(() => new Set()),
    d = new Array(n).fill(0)
  const add = (i, j) => {
    g[i].add(j)
    d[j]++
  }
  for (let i = 1; i < n; i++) {
    const [u, v] = input[i]
    add(u - 1, v - 1)
    add(v - 1, u - 1)
  }

  debug('查找 root')
  let root = -1
  for (let i = 0, max = Infinity; i < n; i++) {
    if (d[i] < max) {
      max = d[i]
      root = i
    }
  }

  debug('构建树')
  const tree = new Array(n).fill(0).map(() => new Set()),
    st = []
  let queue = [root]
  st[root] = 1
  for (let root of queue) {
    for (let child of g[root]) {
      if (st[child]) continue
      st[child] = 1
      queue.push(child)
      tree[root].add(child)
    }
  }

  debug('查找最多好顶点数')
  const cache = new Array(n).fill(0).map(() => [])
  const dfs = (i, isGood) => {
    if (cache[i][isGood]) return cache[i][isGood]
    let state = isGood ^ 1
    let res = isGood ^ 1,
      sum = i === root ? 0 : 1
    for (let child of tree[i]) {
      const [r1, s1] = dfs(child, isGood ^ 1)
      res += r1
      sum += s1
      if (state) sum++
    }

    if (!isGood) {
      let max = 0,
        sum2 = 1
      for (let child of tree[i]) {
        const [r1, s1] = dfs(child, isGood)
        max += r1
        sum2 += s1
      }
      if (res < max) {
        res = max
        sum = sum2
        state = 0
      } else if (res === max && sum >= sum2) {
        sum = sum2
        state = 0
      }
    }

    cache[i][isGood] = [res, sum, state]
    return [res, sum]
  }

  dfs(root, 0)

  debug('对所有点进行分类')
  const colors = new Array(n).fill(0)
  const dfs2 = (node, state) => {
    colors[node] = cache[node][state][2]
    for (let child of tree[node]) {
      dfs2(child, colors[node])
    }
  }
  dfs2(root, 0)

  debug('统计两种情况总数')
  let s0 = 0,
    s1 = 0
  for (let i = 0; i < n; i++) {
    if (colors[i] === 0) s0++
    else s1++
  }
  let min = s0 > s1 ? 1 : 0
  let res = new Array(n).fill(0)
  for (let i = 0; i < n; i++) {
    if (colors[i] === min) {
      res[i] = 1
      for (let j of g[i]) {
        if (colors[j] === 0) continue
        res[j] += 1
      }
    }
  }

  debug('计算最小权重和')
  let sum = 0
  for (let i = 0; i < n; i++) {
    sum += res[i]
  }

  console.log(s1, sum)
  console.log(res.join(' '))
  return [s1, sum, res]
}

const readline = require('readline')
const rl = readline.createInterface({
  output: process.stdout,
  input: process.stdin,
})
const input = []
rl.on('line', line => input.push(line.split(' ').map(Number)))
rl.on('close', () => {
  main(input)
})
function main(input){
    console.log(input)
}

const readline = require('readline')
const rl = readline.createInterface({
  output: process.stdout,
  input: process.stdin,
})
const input = []
rl.on('data', line => input.push(line.split(' ').map(Number)))
rl.on('close', () => {
  main(input)
})

function main(input){
    console.log(input)
}

const fs = require('fs')
const input = fs
  .readFileSync(0, 'utf-8')
  .split('\n')
  .map((line) => line.split(' ').map(Number))
main(input)

function main(input) {
  const n = input[0][0]
  if (n === 2) {
    console.log(2, 2)
    console.log('1 1')
    return [2, 2, [1, 1]]
  }

  const g = new Array(n).fill(0).map(() => new Set()),
    d = new Array(n).fill(0)
  const add = (i, j) => {
    g[i].add(j)
    d[j]++
  }
  console.log(input,g,d)

}

const fs = require('fs')
const input = fs
  .readFileSync(0, 'utf-8')
  .split('\n')
  .map((line) => line.split(' ').map(Number))
main(input)
function main(input) {
  const n = input[0][0]
  if (n === 2) {
    console.log(2, 2)
    console.log('1 1')
    return [2, 2, [1, 1]]
  }

  const g = new Array(n).fill(0).map(() => new Set()),
    d = new Array(n).fill(0)
  const add = (i, j) => {
    g[i].add(j)
    d[j]++
  }

}

const fs = require('fs')
const input = fs
  .readFileSync(0, 'utf-8')
  .split('\n')
  .map((line) => line.split(' ').map(Number))
main(input)
function main(input) {
  const n = input[0][0]
  if (n === 2) {
    console.log(2, 2)
    console.log('1 1')
    return [2, 2, [1, 1]]
  }
}

const fs = require('fs')
const input = fs
  .readFileSync(0, 'utf-8')
  .split('\n')
  .map((line) => line.split(' ').map(Number))
main(input)
function main(input) {
  const n = input[0][0]
  if (n === 2) {
    console.log(`2 2\n1 1`)
    return
  }
  const h = new Array(n).fill(-1),
    e = [],
    ne = []
  let idx = 0
  const add = (i, j) => ((e[idx] = j), (ne[idx] = h[i]), (h[i] = idx++))
  for (let i = 1; i < input.length; i++) {
    const [u, v] = input[i]
    add(u - 1, v - 1)
    add(v - 1, u - 1)
  }
  const colors = []
  const dfs = (i, color) => {
    if (colors[i]) return
    colors[i] = color
    for (let k = h[i]; k !== -1; k = ne[k]) {
      const j = e[k]
      dfs(j, 3 - color)
    }
  }
  dfs(0, 1)
  let s1 = 0,
    s2 = 0
  for (let num of colors) {
    if (num === 1) s1++
    else if (num === 2) s2++
  }
  if (s1 === s2) {
    console.log(`${s1} ${s1 + s2}`)
    console.log(new Array(n).fill(1).join(' '))
    return
  }

  const lt = s1 > s2 ? 2 : 1
  const res = new Array(n).fill(0)
  for (let i = 0; i < colors.length; i++) {
    if (colors[i] === lt) {
      res[i] = 1
      for (let k = h[i]; k !== -1; k = ne[k]) {
        const j = e[k]
        res[j] += 1
      }
    }
  }
  let sum = 0
  for (let i = 0; i < res.length; i++) sum += res[i]
  console.log(`${s1 > s2 ? s1 : s2} ${sum}`)
  console.log(res.join(' '))
}

const fs = require('fs')
const input = fs
  .readFileSync(0, 'utf-8')
  .split('\n')
  .map((line) => line.split(' ').map(Number))
main(input)
function main(input) {
  const n = input[0][0]
  if (n === 2) {
    console.log(`2 2\n1 1`)
    return
  }
  const h = new Array(n).fill(-1),
    e = [],
    ne = []
  let idx = 0
  const add = (i, j) => ((e[idx] = j), (ne[idx] = h[i]), (h[i] = idx++))
  for (let i = 1; i < input.length; i++) {
    const [u, v] = input[i]
    add(u - 1, v - 1)
    add(v - 1, u - 1)
  }
  const colors = []
  const dfs = (i, color) => {
    if (colors[i]) return
    colors[i] = color
    for (let k = h[i]; k !== -1; k = ne[k]) {
      const j = e[k]
      dfs(j, 3 - color)
    }
  }
  dfs(0, 1)
  let s1 = 0,
    s2 = 0
  for (let num of colors) {
    if (num === 1) s1++
    else if (num === 2) s2++
  }
  const lt = s1 > s2 ? 2 : 1
  const res = new Array(n).fill(0)
  for (let i = 0; i < colors.length; i++) {
    if (colors[i] === lt) {
      res[i] = 1
      for (let k = h[i]; k !== -1; k = ne[k]) {
        const j = e[k]
        res[j] += 1
      }
    }
  }
  let sum = 0
  for (let i = 0; i < res.length; i++) sum += res[i]
  console.log(`${s1 > s2 ? s1 : s2} ${sum}`)
  console.log(res.join(' '))
}

const fs = require('fs')
const input = fs
  .readFileSync(0, 'utf-8')
  .split('\n')
  .map((line) => line.split(' ').map(Number))
main(input)
function main(input) {
  const n = input[0][0]
  const h = new Array(n).fill(-1),
    e = [],
    ne = []
  let idx = 0
  const add = (i, j) => ((e[idx] = j), (ne[idx] = h[i]), (h[i] = idx++))
  for (let i = 1; i < input.length; i++) {
    const [u, v] = input[i]
    add(u - 1, v - 1)
    add(v - 1, u - 1)
  }
  const colors = []
  const dfs = (i, color) => {
    if (colors[i]) return
    colors[i] = color
    for (let k = h[i]; k !== -1; k = ne[k]) {
      const j = e[k]
      dfs(j, 3 - color)
    }
  }
  dfs(0, 1)
  let s1 = 0,
    s2 = 0
  for (let num of colors) {
    if (num === 1) s1++
    else if (num === 2) s2++
  }
  const lt = s1 > s2 ? 2 : 1
  const res = new Array(n).fill(0)
  for (let i = 0; i < colors.length; i++) {
    if (colors[i] === lt) {
      res[i] = 1
      for (let k = h[i]; k !== -1; k = ne[k]) {
        const j = e[k]
        res[j] += 1
      }
    }
  }
  let sum = 0
  for (let i = 0; i < res.length; i++) sum += res[i]
  console.log(`${s1 > s2 ? s1 : s2} ${sum}`)
  console.log(res.join(' '))
}


You have an $$$n \times n$$$ chessboard and $$$k$$$ rooks. Rows of this chessboard are numbered by integers from $$$1$$$ to $$$n$$$ from top to bottom and columns of this chessboard are numbered by integers from $$$1$$$ to $$$n$$$ from left to right. The cell $$$(x, y)$$$ is the cell on the intersection of row $$$x$$$ and collumn $$$y$$$ for $$$1 \leq x \leq n$$$ and $$$1 \leq y \leq n$$$.The arrangement of rooks on this board is called good, if no rook is beaten by another rook.A rook beats all the rooks that shares the same row or collumn with it.The good arrangement of rooks on this board is called not stable, if it is possible to move one rook to the adjacent cell so arrangement becomes not good. Otherwise, the good arrangement is stable. Here, adjacent cells are the cells that share a side.  Such arrangement of $$$3$$$ rooks on the $$$4 \times 4$$$ chessboard is good, but it is not stable: the rook from $$$(1, 1)$$$ can be moved to the adjacent cell $$$(2, 1)$$$ and rooks on cells $$$(2, 1)$$$ and $$$(2, 4)$$$ will beat each other. Please, find any stable arrangement of $$$k$$$ rooks on the $$$n \times n$$$ chessboard or report that there is no such arrangement.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$, $$$k$$$ ($$$1 \leq k \leq n \leq 40$$$) — the size of the chessboard and the number of rooks.

If there is a stable arrangement of $$$k$$$ rooks on the $$$n \times n$$$ chessboard, output $$$n$$$ lines of symbols . and R. The $$$j$$$-th symbol of the $$$i$$$-th line should be equals R if and only if there is a rook on the cell $$$(i, j)$$$ in your arrangement. If there are multiple solutions, you may output any of them. If there is no stable arrangement, output $$$-1$$$.

NoteIn the first test case, you should find stable arrangement of $$$2$$$ rooks on the $$$3 \times 3$$$ chessboard. Placing them in cells $$$(3, 1)$$$ and $$$(1, 3)$$$ gives stable arrangement.In the second test case it can be shown that it is impossbile to place $$$3$$$ rooks on the $$$3 \times 3$$$ chessboard to get stable arrangement.

/**
 * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools
 *
 * To modify the template, go to Preferences -> Editor -> File and Code Templates -> Other
 */

// Write your solution here
const {EOL} = require("os");

function board({n, k}) {
    return Array.from({length: n}, (_, i) =>
        Array.from({length: n}, (_, j) => i % 2 === 0 && j % 2 === 0 && i === j && ((i / 2) + 1) <= k ? 'R' : '.').join('')
    ).join('\n');
}

function solution({n, k}) {
    return Math.ceil(n / 2) < k ? -1 : board({n, k});
}

function parse(input) {
    const [n, k] = input.shift().split(' ').map(Number);
    return {n, k};
}

let lines = '';

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

process.stdin.on('end', () => {
    const input = lines.split(EOL);
    const number_of_test_cases = Number(input.shift());
    for (let _ = 0; _ < number_of_test_cases; _ += 1) {
        console.log(solution(parse(input)));
    }
});

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

const getLine = (function () {
    const getLineGen = (async function* () {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async () => {
        let next;
        do {
            next = (await getLineGen.next());
        } while (!next.done && next.value === '');
        return next.value;
    };
})();

const readInt = async function(){
    return parseInt(await getLine());
}

const readIntArray = async function() {
    return (await getLine()).split(' ').map(num => parseInt(num));
}

let solve = async () => {
    const nsc = await readInt();
    for(let sc = 0; sc < nsc; sc++) {
        const [n,k] = await readIntArray();
        if (k > Math.floor(n + 1) / 2) {
           console.log(-1);
        } else {
            const a = new Array(n);
            let nrooks = 0;
            for(let i = 0; i < n; i++) {
                for(let j = 0; j < n; j++)
                    if (i===j && i % 2===0 && nrooks < k) {
                        a[j] = 'R';
                        nrooks++;
                    }
                else
                    a[j] = '.';
                console.log(a.join(''));
            }
        }
    }
}

solve();

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

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

let nl = nextLine();

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

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

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

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

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

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		let [n, k] = nl.nums();
		if ((2 * k - 1) <= n) {
			let s = [];
			for(let x = 0; x < n; x++){
				for(let y = 0; y < n; y++){
					if (x === y && x % 2 === 0 && k > 0){
						s.push("R");
						k--;
					} else {
						s.push(".");
					}
				}
				if (x != n-1) {
					s.push('\n');
				}
			}
			ans.push(s.join(''));
		} else {
				ans.push('-1');
		}
	}
	console.log(ans.join('\n'));
};

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

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader();

function _main() {
  _inputLines = _inputData
    .trim()
    .split("\n")
    .map((string) => {
      return string.trim();
    });

  let t = inputReader.readNumber();

  function solve() {
    let [n, k] = inputReader.readNumberArray();
    let v = [];
    for (let i = 0; i < n; i++) {
      v[i] = new Array(n);
      for (let j = 0; j < n; j++) v[i][j] = ".";
    }

    let possibleRooks = Math.ceil(n / 2);
    if (k > possibleRooks) {
      console.log(-1);
      return;
    }
    let i = 0,
      j = 0;
    while (k > 0) {
      v[i][j] = "R";
      i += 2;
      j += 2;
      k -= 1;
    }
    for (let i = 0; i < n; i++) {
      let string = "";
      for (let j = 0; j < n; j++) {
        string += v[i][j];
      }
      console.log(string);
    }
  }

  while (t--) {
    solve();
  }
}

var _inputData = "";
function cacheInput(data) {
  _inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", cacheInput).on("end", _main);

function _inputReader() {
  function readNumber() {
    return Number(_inputLines[_lineNumber++]);
  }

  function readNumberArray() {
    return _inputLines[_lineNumber++].split(" ").map((val) => Number(val));
  }

  return {
    readNumber,
    readNumberArray,
  };
}

const readline = require('readline')

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

function solve(n, k) {
    if (k > Math.ceil(n / 2)) return -1

    const grid = []
    for (let i = 0; i < n; i++) {
        grid[i] = []
        for (let j = 0; j < n; j++) {
            grid[i][j] = '.'
        }
    }
    for (let i = 0; i < k; i++) {
        grid[2 * i][2 * i] = 'R'
    }
    return grid.map(r => r.join('')).join('\n')
}

const {EOL} = require("os");

function board({n, k}) {
    return Array.from({length: n}, (_, i) =>
        Array.from({length: n}, (_, j) => i%2 === 0 && j%2 === 0 && i === j && i <= k? 'R': '.').join('')
    ).join('\n');
}

function solution({n, k}) {
    return Math.ceil(n/2) < k ? -1 : board({n, k});
}

function parse(input) {
    const [n, k] = input.shift().split(' ').map(Number);
    return {n, k};
}

let lines = '';

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

process.stdin.on('end', () => {
    const input = lines.split(EOL);
    const number_of_test_cases = Number(input.shift());
    for (let _ = 0; _ < number_of_test_cases; _ += 1) {
        console.log(solution(parse(input)));
    }
});

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

const getLine = (function () {
    const getLineGen = (async function* () {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async () => {
        let next;
        do {
            next = (await getLineGen.next());
        } while (!next.done && next.value === '');
        return next.value;
    };
})();

const readInt = async function(){
    return parseInt(await getLine());
}

const readIntArray = async function() {
    return (await getLine()).split(' ').map(num => parseInt(num));
}

let solve = async () => {
    const nsc = await readInt();
    for(let sc = 0; sc < nsc; sc++) {
        const [n,k] = await readIntArray();
        if (k > Math.floor(n + 1) / 2) {
           console.log(-1);
        } else {
            const a = new Array(n);
            for(let i = 0; i < n; i++) {
                for(let j = 0; j < n; j++)
                    if (i===j && i % 2===0)
                        a[j] = 'R';
                else
                    a[j] = '.';
                console.log(a.join(''));
            }
        }
    }
}

solve();


Recently a new building with a new layout was constructed in Monocarp's hometown. According to this new layout, the building consists of three types of apartments: three-room, five-room, and seven-room apartments. It's also known that each room of each apartment has exactly one window. In other words, a three-room apartment has three windows, a five-room — five windows, and a seven-room — seven windows.Monocarp went around the building and counted $$$n$$$ windows. Now he is wondering, how many apartments of each type the building may have.Unfortunately, Monocarp only recently has learned to count, so he is asking you to help him to calculate the possible quantities of three-room, five-room, and seven-room apartments in the building that has $$$n$$$ windows. If there are multiple answers, you can print any of them.Here are some examples:  if Monocarp has counted $$$30$$$ windows, there could have been $$$2$$$ three-room apartments, $$$2$$$ five-room apartments and $$$2$$$ seven-room apartments, since $$$2 \cdot 3 + 2 \cdot 5 + 2 \cdot 7 = 30$$$;  if Monocarp has counted $$$67$$$ windows, there could have been $$$7$$$ three-room apartments, $$$5$$$ five-room apartments and $$$3$$$ seven-room apartments, since $$$7 \cdot 3 + 5 \cdot 5 + 3 \cdot 7 = 67$$$;  if Monocarp has counted $$$4$$$ windows, he should have mistaken since no building with the aforementioned layout can have $$$4$$$ windows.

Th first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The only line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of windows in the building.

For each test case, if a building with the new layout and the given number of windows just can't exist, print $$$-1$$$. Otherwise, print three non-negative integers — the possible number of three-room, five-room, and seven-room apartments. If there are multiple answers, print any of them.

'use strict'; /*jslint node:true, browser:true, es6:true*/
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
const print = console.log
const lines = []
rl.on('line', line => {
    lines.push(line);
});
rl.on('close', main)
let rli = 0;
function readline() {
    return lines[rli++];
}

let mem = new Map();
function query(n){
    if (n<0)
        return;
    if (n==0)
        return [0, 0, 0];
    if (mem.has(n))
        return mem.get(n);
    for (let [i, d] of [3, 5, 7].entries())
    {
        let res = query(n-d);
        if (!res)
            continue;
        res = res.slice(0);
        res[i]++;
        mem.set(n, res);
        return res;
    }
    mem.set(n, null);
}

function main() {
    var q = +readline();
    while (q--)
    {
        var n = +readline();
        let res = query(n);
        if (res)
            print(res.join(' '));
        else
            print(-1);
    }
}

const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
let isFirst = true;
readline.on('line', line => {
  if(isFirst) return isFirst = false;
  const variant = getCombination(+line);
  const map = {3:0,5:0,7:0}
  if(variant) {
    variant.forEach(num => map[num]++);
    console.log(`${map[3]} ${map[5]} ${map[7]}`);
  } else {
    console.log(-1);
  }

});

function getCombination(total, acc = []) {
  if(total === 0) return acc;
  if(total < 0) return null;
  let possible = null;
  for(let num of [3,5,7]) {
    const variant = getCombination(total - num, [...acc, num]);
    if(variant) {
      possible = variant;
      break;
    }
  }

  return possible;
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    let num = +readLine();
    let [a, b, c] = [0, 0, 0];

    if (num === 1 || num === 2 || num === 4) {
      console.log(-1);
      continue;
    } else {
      if (num % 3 == 0) {
        console.log(`${Math.floor(num / 3)} ${b} ${c}`);
        continue;
      } else if (num % 5 == 0) {
        console.log(`${a} ${Math.floor(num / 5)} ${c}`);
        continue;
      } else if (num % 7 == 0) {
        console.log(`${a} ${b} ${Math.floor(num / 7)}`);
        continue;
      } else {
        while (num) {
          if (num % 3 === 0) {
            a = Math.floor(num / 3);
            break;
          }
          b++;
          num -= 5;
        }
        console.log(`${a} ${b} ${c}`);
        continue;
      }
    }
  }
}

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

let stdinInput = '';

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

process.stdin.on('end', () => {
  main(stdinInput);
})

function main(data) {
    data = data.split('\n');
    const testCases = data[0] * 1;
    let i = 1;
    while (i <= testCases) {
      // let a = data[i].trim().split(' ').map(Number);
      const n = data[i] * 1;
      if (n % 7 === 0) console.log('0 0 ' + n / 7);
      else if (n % 5 === 0) console.log('0 ' + n / 5 + ' 0');
      else if(n % 3 === 0) console.log(n / 3 + ' 0 0');
      else if (n % 10 === 7) console.log('0 ' + (n - 7) / 5 + ' 1');
      else if (n % 10 === 3 || n % 10 === 8) console.log('1 ' + (n - 3) / 5 + ' 0');
      else if (n > 2 && n % 10 === 2) console.log('4 ' + (n - 12) / 5 + ' 0');
      else if (n % 10 === 6 || n % 10 === 9) console.log((n % 10) / 3 + ' ' + (n - (n % 10)) / 5 + ' 0');
      // else if (n > 8 && n % 10 === 8) console.log('6 ' + (n - 18) / 5 + ' 0');
      else if (n > 1 && n % 10 === 1) console.log('2 ' + (n - 6) / 5 + ' 0');
      else if (n > 14 && n % 10 === 4) console.log('8 ' + (n - 24) / 5 + ' 0');
      else console.log(-1);
      // const k = a[1];
      // let s = data[i + 1].trim().split(' ');

      i += 1;
    }
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b);
  if (b < a) return [];
  let arr = Array(b - a + 1)
  for (let i = a; i <= b; i++) arr[i - a] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return a;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  a = a || 0;
  b = b || (this.length - 1);
  let prev = a;
  for (let i = a; i <= b; i++) {
    if (i == b || fn(this[i], this[i + 1], i, this)) {
      arr.push(this.slice(prev, i + 1));
      prev = i + 1;
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
function inv(b, m) {
  for (var a = m, u = 0, v = 1, t; b; v = t)
    (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
  return (u + m) % m;
}

// let MOD = 1e9 + 7
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,
    bi = BigInt, rand = n => Math.random() * n | 0;

  let f = Arr(1e3 + 1, i => []);
  f[0] = [0, 0, 0]
  For(1, 1e3, i => {
    if (i >= 3 && f[i - 3].length) { f[i] = [...f[i - 3]]; f[i][0]++ }
    if (i >= 5 && f[i - 5].length) { f[i] = [...f[i - 5]]; f[i][1]++ }
    if (i >= 7 && f[i - 7].length) { f[i] = [...f[i - 7]]; f[i][2]++ }
  })

  let t = $()
  while (t--) {
    let n = $()
    if (f[n].length) {
      log(f[n].join(' '))
    } else {
      log(-1)
    }
  }
}

const { createInterface } = require('readline')

const f = (it, obj) => {
  if (it === 0) return true
  if (it < 0) return
  obj.a++
  if (f(it - 7, obj)) return true; else obj.a--
  obj.b++
  if (f(it - 5, obj)) return true; else obj.b--
  obj.c++
  if (f(it - 3, obj)) return true; else obj.c--
}

let count = -1
createInterface(process.stdin, process.stdout).on('line', q => {
  if (count === 0) return
  if (count === -1) {
    count = +q
    return
  } else count--
  const obj = { a: 0, b: 0, c: 0 }
  if (f(+q, obj)) console.log(obj.c, obj.b, obj.a)
  else console.log('-1')
  if (!count) process.exit()
})

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

    A();
});

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

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let a = 0;
        let b = 0;
        let c = 0;
        let isFound = false;
        for(let i = 0; i <= Math.floor(n/3); i++){
            if(isFound)
                break;
            if(3*i > n)
                break;
            else if(3*i === n){
                a = i;
                isFound = true;
                break;
            }
            for(let j = 0; j <= Math.floor(n/5); j++){
                if(isFound)
                    break;
                if(3*i + 5*j > n)
                    break;
                else if(3*i + 5*j === n){
                    a = i; b = j;
                    isFound = true;
                    break;
                }
                for(let k = 0; k <= Math.floor(n/7); k++){
                    if(3*i + 5*j + 7*k === n){
                        a = i; b = j; c = k;
                        isFound = true;
                        break;
                    }else if(3*i + 5*j + 7*k > n){
                        break;
                    }
                }
            }
        }

        if(isFound)
            console.log(a,b,c)
        else
            console.log(-1);
    }
}

var inputs = parseInt(readline());
for (var i = 0; i < inputs; i++) {
  var totalWindows = parseInt(readline());
  var rooms = [0, 0, 0];
  if (totalWindows < 3 || totalWindows === 4) {
    print("-1");
    continue;
  } else {
    var isCompvared = false;

    if (totalWindows % 3 === 0) {
      rooms[0] = totalWindows / 3;
      print(rooms[0] + " " + rooms[1] + " " + rooms[2]);
      continue;
    }
    if (totalWindows % 5 === 0) {
        rooms[1] = totalWindows / 5;
        print(rooms[0] + " " + rooms[1] + " " + rooms[2]);
        continue;
      }
      if (totalWindows % 7 === 0) {
        rooms[2] = totalWindows / 7;
        print(rooms[0] + " " + rooms[1] + " " + rooms[2]);
        continue;
      }
    for (var j = Math.floor(totalWindows / 3); j >= 0; j--) {
      var leftOverWindows = totalWindows - 3 * j;

      if (leftOverWindows >= 5 && leftOverWindows % 5 === 0) {
        rooms = [j, leftOverWindows / 5, 0];
        isCompvared = true;
        break;
      } else if (leftOverWindows >= 7 && leftOverWindows % 7 === 0) {
        rooms = [j, 0, leftOverWindows / 7];
        isCompvared = true;
        break;
      } else if (leftOverWindows >= 8 && leftOverWindows % 8 === 0) {
        var total = leftOverWindows / 8;
        rooms = [j + total, total, 0];
        isCompvared = true;
        break;
      }
    }
    if (isCompvared) {
      print(rooms[0] + " " + rooms[1] + " " + rooms[2]);
    } else {
      print("-1");
    }
  }
}

/*
......descrition.....
...................
A. Number of Apartments
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Recently a new building with a new layout was constructed in Monocarp's hometown. According to this new layout, the building consists of three types of apartments: three-room, five-room, and seven-room apartments. It's also known that each room of each apartment has exactly one window. In other words, a three-room apartment has three windows, a five-room — five windows, and a seven-room — seven windows.

Monocarp went around the building and counted n windows. Now he is wondering, how many apartments of each type the building may have.

Unfortunately, Monocarp only recently has learned to count, so he is asking you to help him to calculate the possible quantities of three-room, five-room, and seven-room apartments in the building that has n windows. If there are multiple answers, you can print any of them.

Here are some examples:

if Monocarp has counted 30 windows, there could have been 2 three-room apartments, 2 five-room apartments and 2 seven-room apartments, since 2⋅3+2⋅5+2⋅7=30;
if Monocarp has counted 67 windows, there could have been 7 three-room apartments, 5 five-room apartments and 3 seven-room apartments, since 7⋅3+5⋅5+3⋅7=67;
if Monocarp has counted 4 windows, he should have mistaken since no building with the aforementioned layout can have 4 windows.
Input
Th first line contains one integer t (1≤t≤1000) — the number of test cases.

The only line of each test case contains one integer n (1≤n≤1000) — the number of windows in the building.

Output
For each test case, if a building with the new layout and the given number of windows just can't exist, print −1.

Otherwise, print three non-negative integers — the possible number of three-room, five-room, and seven-room apartments. If there are multiple answers, print any of them.

Example
inputCopy
4
30
67
4
14
outputCopy
2 2 2
7 5 3
-1
0 0 2

Trois tableua des multipliant de 3 et 5 et 7 et un boolean found
puis chercher si existe dans chaque tableau et mettre found a true
puis cherchhr si somme de valeurs entre chaque deux tableau et mettre found a true
si not found afficher -1
*/

var testCasesNumber = readline();
var listOfWindowsNumber = [];
var valus0fX3 =[0,	3,	6,	9,	12,	15,	18,	21,	24,	27,	30,	33,	36,	39,	42,	45,	48,	51,	54,	57,	60,	63,	66,	69,	72,	75,	78,	81,	84,	87,	90,	93,	96,	99,	102,	105,	108,	111,	114,	117,	120,	123,	126,	129,	132,	135,	138,	141,	144,	147,	150,	153,	156,	159,	162,	165,	168,	171,	174,	177,	180,	183,	186,	189,	192,	195,	198,	201,	204,	207,	210,	213,	216,	219,	222,	225,	228,	231,	234,	237,	240,	243,	246,	249,	252,	255,	258,	261,	264,	267,	270,	273,	276,	279,	282,	285,	288,	291,	294,	297,	300,	303,	306,	309,	312,	315,	318,	321,	324,	327,	330,	333,	336,	339,	342,	345,	348,	351,	354,	357,	360,	363,	366,	369,	372,	375,	378,	381,	384,	387,	390,	393,	396,	399,	402,	405,	408,	411,	414,	417,	420,	423,	426,	429,	432,	435,	438,	441,	444,	447,	450,	453,	456,	459,	462,	465,	468,	471,	474,	477,	480,	483,	486,	489,	492,	495,	498,	501,	504,	507,	510,	513,	516,	519,	522,	525,	528,	531,	534,	537,	540,	543,	546,	549,	552,	555,	558,	561,	564,	567,	570,	573,	576,	579,	582,	585,	588,	591,	594,	597,	600,	603,	606,	609,	612,	615,	618,	621,	624,	627,	630,	633,	636,	639,	642,	645,	648,	651,	654,	657,	660,	663,	666,	669,	672,	675,	678,	681,	684,	687,	690,	693,	696,	699,	702,	705,	708,	711,	714,	717,	720,	723,	726,	729,	732,	735,	738,	741,	744,	747,	750,	753,	756,	759,	762,	765,	768,	771,	774,	777,	780,	783,	786,	789,	792,	795,	798,	801,	804,	807,	810,	813,	816,	819,	822,	825,	828,	831,	834,	837,	840,	843,	846,	849,	852,	855,	858,	861,	864,	867,	870,	873,	876,	879,	882,	885,	888,	891,	894,	897,	900,	903,	906,	909,	912,	915,	918,	921,	924,	927,	930,	933,	936,	939,	942,	945,	948,	951,	954,	957,	960,	963,	966,	969,	972,	975,	978,	981,	984,	987,	990,	993,	996,	999];
var valus0fX5 =[0,	5,	10,	15,	20,	25,	30,	35,	40,	45,	50,	55,	60,	65,	70,	75,	80,	85,	90,	95,	100,	105,	110,	115,	120,	125,	130,	135,	140,	145,	150,	155,	160,	165,	170,	175,	180,	185,	190,	195,	200,	205,	210,	215,	220,	225,	230,	235,	240,	245,	250,	255,	260,	265,	270,	275,	280,	285,	290,	295,	300,	305,	310,	315,	320,	325,	330,	335,	340,	345,	350,	355,	360,	365,	370,	375,	380,	385,	390,	395,	400,	405,	410,	415,	420,	425,	430,	435,	440,	445,	450,	455,	460,	465,	470,	475,	480,	485,	490,	495,	500,	505,	510,	515,	520,	525,	530,	535,	540,	545,	550,	555,	560,	565,	570,	575,	580,	585,	590,	595,	600,	605,	610,	615,	620,	625,	630,	635,	640,	645,	650,	655,	660,	665,	670,	675,	680,	685,	690,	695,	700,	705,	710,	715,	720,	725,	730,	735,	740,	745,	750,	755,	760,	765,	770,	775,	780,	785,	790,	795,	800,	805,	810,	815,	820,	825,	830,	835,	840,	845,	850,	855,	860,	865,	870,	875,	880,	885,	890,	895,	900,	905,	910,	915,	920,	925,	930,	935,	940,	945,	950,	955,	960,	965,	970,	975,	980,	985,	990,	995,	1000];
var valus0fX7 =[0,	7,	14,	21,	28,	35,	42,	49,	56,	63,	70,	77,	84,	91,	98,	105,	112,	119,	126,	133,	140,	147,	154,	161,	168,	175,	182,	189,	196,	203,	210,	217,	224,	231,	238,	245,	252,	259,	266,	273,	280,	287,	294,	301,	308,	315,	322,	329,	336,	343,	350,	357,	364,	371,	378,	385,	392,	399,	406,	413,	420,	427,	434,	441,	448,	455,	462,	469,	476,	483,	490,	497,	504,	511,	518,	525,	532,	539,	546,	553,	560,	567,	574,	581,	588,	595,	602,	609,	616,	623,	630,	637,	644,	651,	658,	665,	672,	679,	686,	693,	700,	707,	714,	721,	728,	735,	742,	749,	756,	763,	770,	777,	784,	791,	798,	805,	812,	819,	826,	833,	840,	847,	854,	861,	868,	875,	882,	889,	896,	903,	910,	917,	924,	931,	938,	945,	952,	959,	966,	973,	980,	987,	994];

//Saisie des données

for (var i = 0; i < testCasesNumber; i++) {
    listOfWindowsNumber[i] = readline();
    }

for (var i = 0; i < testCasesNumber; i++) {
    var found=false;
    var number = parseInt(listOfWindowsNumber[i]);
    if (number==1 || number==2 || number==4)
    {
        print(-1);
        found=true;
    }
    if (valus0fX3.indexOf(number,0)!=-1) {
        print (number/3,0,0);
        found=true;
    }

    if ((valus0fX5.indexOf(number,0)!=-1) && (found == false)) {
        print (0,number/5,0);
        found=true;
    }

    if ((valus0fX7.indexOf(number,0)!=-1) && (found == false)) {
        print (0,0,number/7);
        found=true;
    }

    for(var t3 in valus0fX3){
        if (found==true){
            break;
        }
        for (var t5 in valus0fX5){
            if (number==t3*3+t5*5){
                print(t3,t5,0);
                found=true;
                break;
            }
        }
    }

    /* for(var t32 in valus0fX3){
        if (found==true){
            break;
        }
        for (var t7 in valus0fX7){
            if (number==t32*3+t7*7){
                print(t32,0,t7);
                found=true;
                break;
            }
        }
    }

    for(var t52 in valus0fX5){
        if (found==true){
            break;
        }
        for (var t72 in valus0fX7){
            if (number==t52*5+t72*7){
                print(0,t52,t72);
                found=true;
                break;
            }
        }
    } */
/**/
    if (found==false){
    print(-1);
}

}

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

readline.on('line', line => {
  const variant = getCombination(+line);
  const map = {3:0,5:0,7:0}
  if(variant) {
    variant.forEach(num => map[num]++);
    console.log(`${map[3]} ${map[5]} ${map[7]}`);
  } else {
    console.log(-1);
  }

});

function getCombination(total, acc = []) {
  if(total === 0) return acc;
  if(total < 0) return null;
  let possible = null;
  for(let num of [3,5,7]) {
    const variant = getCombination(total - num, [...acc, num]);
    if(variant) {
      possible = variant;
      break;
    }
  }

  return possible;
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const num = +readLine();
    const ans = [0, 0, 0];

    if (num % 3 === 0) {
      ans[0] = Math.floor(num / 3);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 3) % 5 === 0) {
      ans[0] = Math.floor(num / 3);
      ans[1] = Math.floor((num % 3) / 5);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 3) % 7 === 0) {
      ans[0] = Math.floor(num / 3);
      ans[2] = Math.floor((num % 3) / 7);
      console.log(ans.join(" "));
      continue;
    } else if (num % 5 === 0) {
      ans[1] = Math.floor(num / 5);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 5) % 3 === 0) {
      ans[1] = Math.floor(num / 5);
      ans[0] = Math.floor((num % 5) / 3);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 5) % 7 === 0) {
      ans[1] = Math.floor(num / 5);
      ans[2] = Math.floor((num % 5) / 7);
      console.log(ans.join(" "));
      continue;
    } else if (num % 7 === 0) {
      ans[2] = Math.floor(num / 7);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 7) % 5 === 0) {
      ans[2] = Math.floor(num / 7);
      ans[1] = Math.floor((num % 7) / 5);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 7) % 3 === 0) {
      ans[2] = Math.floor(num / 7);
      ans[0] = Math.floor((num % 7) / 3);
      console.log(ans.join(" "));
      continue;
    } else if (num % 8 === 0) {
      ans[0] = Math.floor(num / 8);
      ans[1] = Math.floor(num / 8);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 8) % 7 === 0) {
      ans[0] = Math.floor(num / 8);
      ans[1] = Math.floor(num / 8);
      ans[2] = Math.floor((num % 8) / 7);
      console.log(ans.join(" "));
      continue;
    } else if (num % 10 === 0) {
      ans[0] = Math.floor(num / 10);
      ans[2] = Math.floor(num / 10);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 10) % 5 === 0) {
      ans[0] = Math.floor(num / 10);
      ans[1] = Math.floor((num % 10) / 5);
      ans[2] = Math.floor(num / 10);
      console.log(ans.join(" "));
      continue;
    } else if (num % 12 === 0) {
      ans[1] = Math.floor(num / 12);
      ans[2] = Math.floor(num / 12);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 12) % 3 === 0) {
      ans[0] = Math.floor((num % 12) / 3);
      ans[1] = Math.floor(num / 12);
      ans[2] = Math.floor(num / 12);
      console.log(ans.join(" "));
      continue;
    } else if (num % 15 === 0) {
      ans[0] = Math.floor(num / 15);
      ans[1] = Math.floor(num / 15);
      ans[2] = Math.floor(num / 15);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 15) % 3 === 0) {
      ans[0] = Math.floor(num / 15) + Math.floor((num % 15) / 3);
      ans[1] = Math.floor(num / 15);
      ans[2] = Math.floor(num / 15);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 15) % 5 === 0) {
      ans[0] = Math.floor(num / 15);
      ans[1] = Math.floor(num / 15) + Math.floor((num % 15) / 5);
      ans[2] = Math.floor(num / 15);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 15) % 7 === 0) {
      ans[0] = Math.floor(num / 15);
      ans[1] = Math.floor(num / 15);
      ans[2] = Math.floor(num / 15) + Math.floor((num % 15) / 7);
      console.log(ans.join(" "));
      continue;
    } else {
      console.log(-1);
      continue;
    }
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const num = +readLine();
    const ans = [0, 0, 0];

    if (num % 3 === 0) {
      ans[0] = Math.floor(num / 3);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 3) % 5 === 0) {
      ans[0] = Math.floor(num / 3);
      ans[1] = Math.floor((num % 3) / 5);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 3) % 7 === 0) {
      ans[0] = Math.floor(num / 3);
      ans[2] = Math.floor((num % 3) / 7);
      console.log(ans.join(" "));
      continue;
    } else if (num % 5 === 0) {
      ans[1] = Math.floor(num / 5);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 5) % 3 === 0) {
      ans[1] = Math.floor(num / 5);
      ans[0] = Math.floor((num % 5) / 3);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 5) % 7 === 0) {
      ans[1] = Math.floor(num / 5);
      ans[2] = Math.floor((num % 5) / 7);
      console.log(ans.join(" "));
      continue;
    } else if (num % 7 === 0) {
      ans[2] = Math.floor(num / 7);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 7) % 5 === 0) {
      ans[2] = Math.floor(num / 7);
      ans[1] = Math.floor((num % 7) / 5);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 7) % 3 === 0) {
      ans[2] = Math.floor(num / 7);
      ans[0] = Math.floor((num % 7) / 3);
      console.log(ans.join(" "));
      continue;
    } else if (num % 8 === 0) {
      ans[0] = Math.floor(num / 8);
      ans[1] = Math.floor(num / 8);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 8) % 3 === 0) {
      ans[0] = Math.floor((num % 8) / 3) + Math.floor(num / 8);
      ans[1] = Math.floor(num / 8);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 8) % 5 === 0) {
      ans[0] = Math.floor(num / 8);
      ans[1] = Math.floor((num % 8) / 5) + Math.floor(num / 8);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 8) % 7 === 0) {
      ans[0] = Math.floor(num / 8);
      ans[1] = Math.floor(num / 8);
      ans[2] = Math.floor((num % 8) / 7);
      console.log(ans.join(" "));
      continue;
    } else if (num % 10 === 0) {
      ans[0] = Math.floor(num / 10);
      ans[2] = Math.floor(num / 10);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 10) % 3 === 0) {
      ans[0] = Math.floor((num % 10) / 3) + Math.floor(num / 10);
      ans[2] = Math.floor(num / 10);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 10) % 7 === 0) {
      ans[0] = Math.floor(num / 10);
      ans[2] = Math.floor((num % 10) / 7) + Math.floor(num / 10);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 10) % 5 === 0) {
      ans[0] = Math.floor(num / 10);
      ans[1] = Math.floor((num % 10) / 5);
      ans[2] = Math.floor(num / 10);
      console.log(ans.join(" "));
      continue;
    } else if (num % 12 === 0) {
      ans[1] = Math.floor(num / 12);
      ans[2] = Math.floor(num / 12);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 12) % 5 === 0) {
      ans[1] = Math.floor((num % 12) / 5) + Math.floor(num / 12);
      ans[2] = Math.floor(num / 12);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 12) % 7 === 0) {
      ans[1] = Math.floor(num / 12);
      ans[2] = Math.floor((num % 12) / 7) + Math.floor(num / 12);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 12) % 3 === 0) {
      ans[0] = Math.floor((num % 12) / 3);
      ans[1] = Math.floor(num / 12);
      ans[2] = Math.floor(num / 12);
      console.log(ans.join(" "));
      continue;
    } else if (num % 15 === 0) {
      ans[0] = Math.floor(num / 15);
      ans[1] = Math.floor(num / 15);
      ans[2] = Math.floor(num / 15);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 15) % 3 === 0) {
      ans[0] = Math.floor(num / 15) + Math.floor((num % 15) / 3);
      ans[1] = Math.floor(num / 15);
      ans[2] = Math.floor(num / 15);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 15) % 5 === 0) {
      ans[0] = Math.floor(num / 15);
      ans[1] = Math.floor(num / 15) + Math.floor((num % 15) / 5);
      ans[2] = Math.floor(num / 15);
      console.log(ans.join(" "));
      continue;
    } else if ((num % 15) % 7 === 0) {
      ans[0] = Math.floor(num / 15);
      ans[1] = Math.floor(num / 15);
      ans[2] = Math.floor(num / 15) + Math.floor((num % 15) / 7);
      console.log(ans.join(" "));
      continue;
    } else {
      console.log(-1);
      continue;
    }
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    let num = +readLine();
    let [a, b, c] = [0, 0, 0];

    if (num === 1 || num === 2 || num === 4) {
      console.log(-1);
      continue;
    } else {
      while (num) {
        c++;
        num -= 7;
        if (num % 3 === 0) {
          a = Math.floor(num / 3);
          break;
        }
      }
      console.log(`${a} ${b} ${c}`);
      continue;
    }
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    let num = +readLine();
    let [a, b, c] = [0, 0, 0];

    if (num === 1 || num === 2 || num === 4) {
      console.log(-1);
      continue;
    } else {
      while (num) {
        if (num % 3 === 0) {
          a = Math.floor(num / 3);
          break;
        }
        c++;
        num -= 7;
      }
      console.log(`${a} ${b} ${c}`);
      continue;
    }
  }
}

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

let stdinInput = '';

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

process.stdin.on('end', () => {
  main(stdinInput);
})

function main(data) {
    data = data.split('\n');
    const testCases = data[0] * 1;
    let i = 1;
    while (i <= testCases) {
      // let a = data[i].trim().split(' ').map(Number);
      const n = data[i] * 1;
      if (n % 7 === 0) console.log('0 0 ' + n / 7);
      else if (n % 5 === 0) console.log('0 ' + n / 5 + ' 0');
      else if(n % 3 === 0) console.log(n / 3 + ' 0 0');
      else if (n % 10 === 7) console.log('0 ' + (n - 7) / 5 + ' 1');
      else if (n % 10 === 3) console.log('1 ' + (n - 3) / 5 + ' 0');
      else if (n > 2 && n % 10 === 2) console.log('4 ' + (n - 12) / 5 + ' 0');
      else if (n % 10 === 6 || n % 10 === 9) console.log((n % 10) / 3 + ' ' + (n - (n % 10)) / 5 + ' 0');
      else if (n > 8 && n % 10 === 8) console.log('6 ' + (n - 18) / 5 + ' 0');
      else if (n > 11 && n % 10 === 1) console.log('7 ' + (n - 21) / 5 + ' 0');
      else if (n > 14 && n % 10 === 4) console.log('8 ' + (n - 24) / 5 + ' 0');
      else console.log(-1);
      // const k = a[1];
      // let s = data[i + 1].trim().split(' ');

      i += 1;
    }
}

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

let stdinInput = '';

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

process.stdin.on('end', () => {
  main(stdinInput);
})

function main(data) {
    data = data.split('\n');
    const testCases = data[0] * 1;
    let i = 1;
    while (i <= testCases) {
      // let a = data[i].trim().split(' ').map(Number);
      const n = data[i] * 1;
      if (n % 7 === 0) console.log('0 0 ' + n / 7);
      else if (n % 5 === 0) console.log('0 ' + n / 5 + ' 0');
      else if(n % 3 === 0) console.log(n / 3 + ' 0 0');
      else if (n % 10 === 7) console.log('0 ' + (n - 7) / 5 + ' 1');
      else if (n % 10 === 3 || n % 10 === 8) console.log('1 ' + (n - 3) / 5 + ' 0');
      else if (n > 2 && n % 10 === 2) console.log('4 ' + (n - 12) / 5 + ' 0');
      else if (n % 10 === 6 || n % 10 === 9) console.log((n % 10) / 3 + ' ' + (n - (n % 10)) / 5 + ' 0');
      // else if (n > 8 && n % 10 === 8) console.log('6 ' + (n - 18) / 5 + ' 0');
      else if (n > 11 && n % 10 === 1) console.log('7 ' + (n - 21) / 5 + ' 0');
      else if (n > 14 && n % 10 === 4) console.log('8 ' + (n - 24) / 5 + ' 0');
      else console.log(-1);
      // const k = a[1];
      // let s = data[i + 1].trim().split(' ');

      i += 1;
    }
}

/* eslint-disable @typescript-eslint/no-var-requires */
const { createInterface } = require('readline')

const f = (it, obj) => {
  if (it === 0) return true
  if (it < 0) return
  obj.a++
  if (f(it - 7, obj)) return true; else obj.a--
  obj.b++
  if (f(it - 5, obj)) return true; else obj.b--
  obj.c++
  if (f(it - 3, obj)) return true; else obj.c--
}

let count = -1
createInterface(process.stdin, process.stdout).on('line', q => {
  if (count === 0) return
  if (count === -1) {
    count = +q
    return
  } else count--
  const obj = { a: 0, b: 0, c: 0 }
  if (f(+q, obj)) console.log(obj.a, obj.b, obj.c)
  else console.log('-1')
  if (!count) process.exit()
})

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

    A();
});

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

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let a = 0;
        let b = 0;
        let c = 0;
        let isFound = false;
        for(let i = 0; i <= Math.floor(n/3); i++){
            if(3*i > n)
                break;
            else if(3*i === n){
                a = i;
                isFound = true;
                break;
            }
            for(let j = 0; j <= Math.floor(n/5); j++){
                if(3*i + 5*j > n)
                    break;
                    else if(3*i + 5*j === n){
                        a = i; b = j;
                        isFound = true;
                        break;
                    }
                for(let k = 0; k <= Math.floor(n/7); k++){
                    if(3*i + 5*j + 7*k === n){
                        a = i; b = j; c = k;
                        isFound = true;
                        break;
                    }else if(3*i + 5*j + 7*k > n){
                        break;
                    }
                }
            }
        }

        if(isFound)
            console.log(a,b,c)
        else
            console.log(-1);
    }
}

var inputs = parseInt(readline());
for (var i = 0; i < inputs; i++) {
  var totalWindows = parseInt(readline());
  var rooms = [0, 0, 0];
  if (totalWindows < 3 || totalWindows === 4) {
    print("-1");
    continue;
  } else {
    var isCompvared = false;

    if (totalWindows % 3 === 0) {
      rooms[0] = totalWindows / 3;
      print(rooms[0] + " " + rooms[1] + " " + rooms[2]);
      continue;
    }
    for (var j = Math.floor(totalWindows / 3); j >= 0; j--) {
      var leftOverWindows = totalWindows - 3 * j;

      if (leftOverWindows > 5 && leftOverWindows % 5 === 0) {
        rooms = [j, leftOverWindows / 5, 0];
        isCompvared = true;
        break;
      } else if (leftOverWindows > 7 && leftOverWindows % 7 === 0) {
        rooms = [j, 0, leftOverWindows / 7];
        isCompvared = true;
        break;
      } else if (leftOverWindows > 8 && leftOverWindows % 8 === 0) {
        var total = leftOverWindows / 8;
        rooms = [j + total, total, 0];
        isCompvared = true;
        break;
      }
    }
    if (isCompvared) {
      print(rooms[0] + " " + rooms[1] + " " + rooms[2]);
    } else {
      print("-1");
    }
  }
}

/*
......descrition.....
...................
A. Number of Apartments
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Recently a new building with a new layout was constructed in Monocarp's hometown. According to this new layout, the building consists of three types of apartments: three-room, five-room, and seven-room apartments. It's also known that each room of each apartment has exactly one window. In other words, a three-room apartment has three windows, a five-room — five windows, and a seven-room — seven windows.

Monocarp went around the building and counted n windows. Now he is wondering, how many apartments of each type the building may have.

Unfortunately, Monocarp only recently has learned to count, so he is asking you to help him to calculate the possible quantities of three-room, five-room, and seven-room apartments in the building that has n windows. If there are multiple answers, you can print any of them.

Here are some examples:

if Monocarp has counted 30 windows, there could have been 2 three-room apartments, 2 five-room apartments and 2 seven-room apartments, since 2⋅3+2⋅5+2⋅7=30;
if Monocarp has counted 67 windows, there could have been 7 three-room apartments, 5 five-room apartments and 3 seven-room apartments, since 7⋅3+5⋅5+3⋅7=67;
if Monocarp has counted 4 windows, he should have mistaken since no building with the aforementioned layout can have 4 windows.
Input
Th first line contains one integer t (1≤t≤1000) — the number of test cases.

The only line of each test case contains one integer n (1≤n≤1000) — the number of windows in the building.

Output
For each test case, if a building with the new layout and the given number of windows just can't exist, print −1.

Otherwise, print three non-negative integers — the possible number of three-room, five-room, and seven-room apartments. If there are multiple answers, print any of them.

Example
inputCopy
4
30
67
4
14
outputCopy
2 2 2
7 5 3
-1
0 0 2 */

var testCasesNumber = readline();
var listOfWindowsNumber = [];

//Saisie des données

for (var i = 0; i < testCasesNumber; i++) {
    listOfWindowsNumber[i] = readline();
    }
var resultx =[];
var resulty =[];
var resultz =[];
var k=0;
for (var i = 0; i < testCasesNumber; i++) {
    var number = parseInt(listOfWindowsNumber[i]);
    for(var x = 0; x < 334; x++){
        for(var y= 0; y < 201; y++){
            for(var z = 0;z < 143; z++){
                if ((x * 3 + y * 5 + z * 7)>number){break;}
                if (number == (x * 3 + y * 5 + z * 7)) {
                    resultx.push(x);
                    resulty.push(y);
                    resultz.push(z);
                    k++;

                }
            }
        }
    }
if (k==0) {
    print(-1);}
    else {
    print(resultx[k-1]," ",resulty[k-1], " ", resultz[k-1]);

    }
}

/*
......descrition.....
...................
A. Number of Apartments
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Recently a new building with a new layout was constructed in Monocarp's hometown. According to this new layout, the building consists of three types of apartments: three-room, five-room, and seven-room apartments. It's also known that each room of each apartment has exactly one window. In other words, a three-room apartment has three windows, a five-room — five windows, and a seven-room — seven windows.

Monocarp went around the building and counted n windows. Now he is wondering, how many apartments of each type the building may have.

Unfortunately, Monocarp only recently has learned to count, so he is asking you to help him to calculate the possible quantities of three-room, five-room, and seven-room apartments in the building that has n windows. If there are multiple answers, you can print any of them.

Here are some examples:

if Monocarp has counted 30 windows, there could have been 2 three-room apartments, 2 five-room apartments and 2 seven-room apartments, since 2⋅3+2⋅5+2⋅7=30;
if Monocarp has counted 67 windows, there could have been 7 three-room apartments, 5 five-room apartments and 3 seven-room apartments, since 7⋅3+5⋅5+3⋅7=67;
if Monocarp has counted 4 windows, he should have mistaken since no building with the aforementioned layout can have 4 windows.
Input
Th first line contains one integer t (1≤t≤1000) — the number of test cases.

The only line of each test case contains one integer n (1≤n≤1000) — the number of windows in the building.

Output
For each test case, if a building with the new layout and the given number of windows just can't exist, print −1.

Otherwise, print three non-negative integers — the possible number of three-room, five-room, and seven-room apartments. If there are multiple answers, print any of them.

Example
inputCopy
4
30
67
4
14
outputCopy
2 2 2
7 5 3
-1
0 0 2

Trois tableua des multipliant de 3 et 5 et 7 et un boolean found
puis chercher si existe dans chaque tableau et mettre found a true
puis cherchhr si somme de valeurs entre chaque deux tableau et mettre found a true
si not found afficher -1
*/

var testCasesNumber = readline();
var listOfWindowsNumber = [];
var valus0fX3 =[0,	3,	6,	9,	12,	15,	18,	21,	24,	27,	30,	33,	36,	39,	42,	45,	48,	51,	54,	57,	60,	63,	66,	69,	72,	75,	78,	81,	84,	87,	90,	93,	96,	99,	102,	105,	108,	111,	114,	117,	120,	123,	126,	129,	132,	135,	138,	141,	144,	147,	150,	153,	156,	159,	162,	165,	168,	171,	174,	177,	180,	183,	186,	189,	192,	195,	198,	201,	204,	207,	210,	213,	216,	219,	222,	225,	228,	231,	234,	237,	240,	243,	246,	249,	252,	255,	258,	261,	264,	267,	270,	273,	276,	279,	282,	285,	288,	291,	294,	297,	300,	303,	306,	309,	312,	315,	318,	321,	324,	327,	330,	333,	336,	339,	342,	345,	348,	351,	354,	357,	360,	363,	366,	369,	372,	375,	378,	381,	384,	387,	390,	393,	396,	399,	402,	405,	408,	411,	414,	417,	420,	423,	426,	429,	432,	435,	438,	441,	444,	447,	450,	453,	456,	459,	462,	465,	468,	471,	474,	477,	480,	483,	486,	489,	492,	495,	498,	501,	504,	507,	510,	513,	516,	519,	522,	525,	528,	531,	534,	537,	540,	543,	546,	549,	552,	555,	558,	561,	564,	567,	570,	573,	576,	579,	582,	585,	588,	591,	594,	597,	600,	603,	606,	609,	612,	615,	618,	621,	624,	627,	630,	633,	636,	639,	642,	645,	648,	651,	654,	657,	660,	663,	666,	669,	672,	675,	678,	681,	684,	687,	690,	693,	696,	699,	702,	705,	708,	711,	714,	717,	720,	723,	726,	729,	732,	735,	738,	741,	744,	747,	750,	753,	756,	759,	762,	765,	768,	771,	774,	777,	780,	783,	786,	789,	792,	795,	798,	801,	804,	807,	810,	813,	816,	819,	822,	825,	828,	831,	834,	837,	840,	843,	846,	849,	852,	855,	858,	861,	864,	867,	870,	873,	876,	879,	882,	885,	888,	891,	894,	897,	900,	903,	906,	909,	912,	915,	918,	921,	924,	927,	930,	933,	936,	939,	942,	945,	948,	951,	954,	957,	960,	963,	966,	969,	972,	975,	978,	981,	984,	987,	990,	993,	996,	999];
var valus0fX5 =[0,	5,	10,	15,	20,	25,	30,	35,	40,	45,	50,	55,	60,	65,	70,	75,	80,	85,	90,	95,	100,	105,	110,	115,	120,	125,	130,	135,	140,	145,	150,	155,	160,	165,	170,	175,	180,	185,	190,	195,	200,	205,	210,	215,	220,	225,	230,	235,	240,	245,	250,	255,	260,	265,	270,	275,	280,	285,	290,	295,	300,	305,	310,	315,	320,	325,	330,	335,	340,	345,	350,	355,	360,	365,	370,	375,	380,	385,	390,	395,	400,	405,	410,	415,	420,	425,	430,	435,	440,	445,	450,	455,	460,	465,	470,	475,	480,	485,	490,	495,	500,	505,	510,	515,	520,	525,	530,	535,	540,	545,	550,	555,	560,	565,	570,	575,	580,	585,	590,	595,	600,	605,	610,	615,	620,	625,	630,	635,	640,	645,	650,	655,	660,	665,	670,	675,	680,	685,	690,	695,	700,	705,	710,	715,	720,	725,	730,	735,	740,	745,	750,	755,	760,	765,	770,	775,	780,	785,	790,	795,	800,	805,	810,	815,	820,	825,	830,	835,	840,	845,	850,	855,	860,	865,	870,	875,	880,	885,	890,	895,	900,	905,	910,	915,	920,	925,	930,	935,	940,	945,	950,	955,	960,	965,	970,	975,	980,	985,	990,	995,	1000];
var valus0fX7 =[0,	7,	14,	21,	28,	35,	42,	49,	56,	63,	70,	77,	84,	91,	98,	105,	112,	119,	126,	133,	140,	147,	154,	161,	168,	175,	182,	189,	196,	203,	210,	217,	224,	231,	238,	245,	252,	259,	266,	273,	280,	287,	294,	301,	308,	315,	322,	329,	336,	343,	350,	357,	364,	371,	378,	385,	392,	399,	406,	413,	420,	427,	434,	441,	448,	455,	462,	469,	476,	483,	490,	497,	504,	511,	518,	525,	532,	539,	546,	553,	560,	567,	574,	581,	588,	595,	602,	609,	616,	623,	630,	637,	644,	651,	658,	665,	672,	679,	686,	693,	700,	707,	714,	721,	728,	735,	742,	749,	756,	763,	770,	777,	784,	791,	798,	805,	812,	819,	826,	833,	840,	847,	854,	861,	868,	875,	882,	889,	896,	903,	910,	917,	924,	931,	938,	945,	952,	959,	966,	973,	980,	987,	994];

//Saisie des données

for (var i = 0; i < testCasesNumber; i++) {
    listOfWindowsNumber[i] = readline();
    }

for (var i = 0; i < testCasesNumber; i++) {
    var found=false;
    var number = parseInt(listOfWindowsNumber[i]);
    if (valus0fX3.indexOf(number,0)!=-1) {
        print (number/3,0,0);
        found=true;
    }

    if ((valus0fX5.indexOf(number,0)!=-1) && (found == false)) {
        print (0,number/5,0);
        found=true;
    }

    if ((valus0fX7.indexOf(number,0)!=-1) && (found == false)) {
        print (0,0,number/7);
        found=true;
    }

    for(var t3 in valus0fX3){
        if (found==true){
            break;
        }
        for (var t5 in valus0fX5){
            if (number==t3*3+t5*5){
                print(t3,t5,0);
                found=true;
                break;
            }
        }
    }

    for(var t32 in valus0fX3){
        if (found==true){
            break;
        }
        for (var t7 in valus0fX7){
            if (number==t32*3+t7*7){
                print(t32,0,t7);
                found=true;
                break;
            }
        }
    }

    for(var t52 in valus0fX5){
        if (found==true){
            break;
        }
        for (var t72 in valus0fX7){
            if (number==t52*5+t72*7){
                print(0,t52,t72);
                found=true;
                break;
            }
        }
    }
/**/
    if (found==false){
    print(-1,"inexistant");
}

}


Suppose you had an array $$$A$$$ of $$$n$$$ elements, each of which is $$$0$$$ or $$$1$$$.Let us define a function $$$f(k,A)$$$ which returns another array $$$B$$$, the result of sorting the first $$$k$$$ elements of $$$A$$$ in non-decreasing order. For example, $$$f(4,[0,1,1,0,0,1,0]) = [0,0,1,1,0,1,0]$$$. Note that the first $$$4$$$ elements were sorted.Now consider the arrays $$$B_1, B_2,\ldots, B_n$$$ generated by $$$f(1,A), f(2,A),\ldots,f(n,A)$$$. Let $$$C$$$ be the array obtained by taking the element-wise sum of $$$B_1, B_2,\ldots, B_n$$$.For example, let $$$A=[0,1,0,1]$$$. Then we have $$$B_1=[0,1,0,1]$$$, $$$B_2=[0,1,0,1]$$$, $$$B_3=[0,0,1,1]$$$, $$$B_4=[0,0,1,1]$$$. Then $$$C=B_1+B_2+B_3+B_4=[0,1,0,1]+[0,1,0,1]+[0,0,1,1]+[0,0,1,1]=[0,2,2,4]$$$.You are given $$$C$$$. Determine a binary array $$$A$$$ that would give $$$C$$$ when processed as above. It is guaranteed that an array $$$A$$$ exists for given $$$C$$$ in the input.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$)  — the number of test cases. Each test case has two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$). The second line contains $$$n$$$ integers $$$c_1, c_2, \ldots, c_n$$$ ($$$0 \leq c_i \leq n$$$). It is guaranteed that a valid array $$$A$$$ exists for the given $$$C$$$. The sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output a single line containing $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$a_i$$$ is $$$0$$$ or $$$1$$$). If there are multiple answers, you may output any of them.

NoteHere's the explanation for the first test case. Given that $$$A=[1,1,0,1]$$$, we can construct each $$$B_i$$$:   $$$B_1=[\color{blue}{1},1,0,1]$$$;  $$$B_2=[\color{blue}{1},\color{blue}{1},0,1]$$$;  $$$B_3=[\color{blue}{0},\color{blue}{1},\color{blue}{1},1]$$$;  $$$B_4=[\color{blue}{0},\color{blue}{1},\color{blue}{1},\color{blue}{1}]$$$  And then, we can sum up each column above to get $$$C=[1+1+0+0,1+1+1+1,0+0+1+1,1+1+1+1]=[2,4,2,4]$$$.

'use strict';

var readline = require('readline');

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

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

class SegTree {
  constructor(nums = [], n = nums.length - 1) {
    this.nums = nums;
    this.n = n;
    this.root = this._newNode(0, n);
    this._build(this.root);
    this.update = this._update.bind(this, this.root);
    this.query = this._query.bind(this, this.root);
  }
  _newNode(l, r, val = 0, left = null, right = null) {
    return {
      val,
      l,
      r,
      left,
      right,
      add: 0
    };
  }
  _down(node) {
    const {
      left,
      right
    } = node;
    if (!left || !right) return;
    for (let child of [left, right]) {
      child.add += node.add;
      child.val += node.add * (child.r - child.l + 1);
    }
    node.add = 0;
  }
  _up(node) {
    const {
      left,
      right
    } = node;
    if (!left || !right) return;
    node.val = left.val + right.val;
  }
  _build(node = this.root) {
    const {
      l,
      r
    } = node;
    if (l === r) {
      var _this$nums$l;
      node.val = (_this$nums$l = this.nums[l]) !== null && _this$nums$l !== void 0 ? _this$nums$l : 0;
      return;
    }
    const mid = Math.floor((l + r) / 2);
    node.left = this._newNode(l, mid);
    node.right = this._newNode(mid + 1, r);
    this._build(node.left);
    this._build(node.right);
    node.val = node.left.val + node.right.val;
  }
  _update(node, x, y, z) {
    if (!node) return;
    const {
      l,
      r
    } = node;
    if (l === x && r === y) {
      node.add += z;
      node.val += z * (r - l + 1);
      return;
    }
    this._down(node);
    const mid = Math.floor((l + r) / 2);
    if (y <= mid) this._update(node.left, x, y, z);else if (x > mid) this._update(node.right, x, y, z);else this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z);
    this._up(node);
  }
  _query(node, x, y) {
    if (y < x) return 0;
    if (!node) return 0;
    const {
      l,
      r
    } = node;
    if (l === x && r === y) return node.val;
    this._down(node);
    let res = 0,
        mid = Math.floor((l + r) / 2);
    if (y <= mid) res = this._query(node.left, x, y);else if (x > mid) res = this._query(node.right, x, y);else res = this._query(node.left, x, mid) + this._query(node.right, mid + 1, y);
    this._up(node);
    return res;
  }
}
function solve(n, a) {
  let res = new Array(n).fill(0),
      one = a.reduce((a, b) => a + b, 0) / n;
  const segTree = new SegTree(a);
  for (let i = n - 1; i >= 0; i--) {
    const cur = segTree.query(i, i);
    segTree.update(i - one + 1, i - 1, -1);
    if (cur === i + 1) {
      res[i] = 1;
      one--;
    }
  }
  console.log(res.join(' '));
}

async function main(read) {
  const t = Number(await read());
  for (let i = 0; i < t; i++) {
    const n = Number(await read());
    const c = (await read()).split(' ').map(Number);
    solve(n, c);
  }
}

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

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) {
    let one = arr.reduce((s, x) => s + x, 0) / n
    let zero = n - one
    const last = Array(n).fill(n) // row of the first zero for each column
    for (let i = 0; i < zero; i++) {
        last[i] = n - 1
    }
// console.log(one, zero, last)
    const ans = Array(n)
    for (let i = arr.length - 1; i >= 0; i--) {
        const a = i + 1 // if ans[i] = 1
        let b = (last[i] - 1) - (i + 1) + 1 // at least contains how many 1s
        if (i + 1 >= n) {
            b = 0
        }
    // console.log('sb', a, b, last[i])
        // const b = n - last[i]
        if (a + b === arr[i]) {
            ans[i] = 1
        } else {
            ans[i] = 0
            zero--
            last[zero] = i
    // console.log(zero, i)
        }
    }
    return ans.join(' ')
}

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a);

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

const calc = (n, c)=>{
    if (n === 1) {
        if (c[0] === 0) return '0';
        else return '1';
    }
    if (c[n - 1] === 0) {
        return new Array(n).fill(0).join(' ');
    }

    let result = new Array(n).fill(1);

    let sum = 0;
    for (let i = 0; i < n; i++) {
        sum += c[i];
    }
    let ones = Math.round(sum / n);

    let idx = 0;
    while (idx < n && c[idx] === 0) {
        result[idx++] = 0;
    }

    while (idx < n) {
        if (result[idx] === 1) {
            if (c[idx] < n) result[c[idx]] = 0;
        } else {
            if (c[idx] + idx < n) result[c[idx] + idx] = 0;
        }
        idx++;
    }

    return result.join(' ');
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let n = +readline();
        let c = ra();
        console.log(`${calc(n, c)}`);
    }
}

'use strict';

var readline = require('readline');

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

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

function solve(n, a) {
  let res = new Array(n).fill(0),
      sum = 0;
  for (let i = n - 1; i >= 0; i--) {
    if (a[i] - sum >= i + 1) {
      res[i] = 1;
      sum++;
    } else {
      sum = 0;
    }
  }
  console.log(res.join(' '));
}

async function main(read) {
  const t = Number(await read());
  for (let i = 0; i < t; i++) {
    const n = Number(await read());
    const c = (await read()).split(' ').map(Number);
    solve(n, c);
  }
}

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

'use strict';

var readline = require('readline');

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

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

function solve(n, a) {
  let res = new Array(n).fill(0),
      sum = 0;
  for (let i = n - 1; i >= 0; i--) {
    if (a[i] - sum >= i + 1) {
      res[i] = 1;
      sum++;
    } else {
      sum = Math.max(0, sum - 1);
    }
  }
  console.log(res.join(' '));
}

async function main(read) {
  const t = Number(await read());
  for (let i = 0; i < t; i++) {
    const n = Number(await read());
    const c = (await read()).split(' ').map(Number);
    solve(n, c);
  }
}

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

'use strict';

var readline = require('readline');

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

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

function solve(n, a) {
  let res = [],
      one = a.reduce((a, b) => a + b, 0) / n,
      p = new Array(n).fill(0),
      cur = 0;
  for (let i = 0; i < n; i++) {
    cur += p[i];
    res[i] = a[i] > cur ? 1 : 0;
    if (res[i]) {
      one--;
      const add = one - (a[i] - cur - (i + 1));
      p[i + 1] += 1;
      p[n - one - 1] += add;
      p[n - one] -= add;
    }
  }
  console.log(res.join(' '));
}

async function main(read) {
  const t = Number(await read());
  for (let i = 0; i < t; i++) {
    const n = Number(await read());
    const c = (await read()).split(' ').map(Number);
    solve(n, c);
  }
}

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

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) {
    let one = arr.reduce((s, x) => s + x, 0) / n
    let zero = n - one
    const last = Array(n).fill(n) // row of the last zero for each column
    for (let i = 0; i < zero; i++) {
        last[i] = n - 1
    }
// console.log(one, zero)
    const ans = Array(n)
    for (let i = arr.length - 1; i >= 0; i--) {
        // const a = i + 1 // if ans[i] = 1
        // const b = Math.max(0, Math.min(zero, i + 1) - (i + 1)) // at least contains how many 1s
    // console.log('sb', a, b)
        const b = n - last[i]
        if (n - b === arr[i]) {
            ans[i] = 1
        } else {
            ans[i] = 0
            zero--
            last[zero] = i
        }
    }
    return ans.join(' ')
}


Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are n books on sale from one of m genres.In the bookshop, Jack decides to buy two books of different genres.Based on the genre of books on sale in the shop, find the number of options available to Jack for choosing two books of different genres for Emily. Options are considered different if they differ in at least one book.The books are given by indices of their genres. The genres are numbered from 1 to m.

The first line contains two positive integers n and m (2 ≤ n ≤ 2·105, 2 ≤ m ≤ 10) — the number of books in the bookstore and the number of genres. The second line contains a sequence a1, a2, ..., an, where ai (1 ≤ ai ≤ m) equals the genre of the i-th book. It is guaranteed that for each genre there is at least one book of that genre.

Print the only integer — the number of ways in which Jack can choose books. It is guaranteed that the answer doesn't exceed the value 2·109.

NoteThe answer to the first test sample equals 5 as Sasha can choose:  the first and second books,  the first and third books,  the first and fourth books,  the second and third books,  the third and fourth books.

var summaryBooks = readline().split(' ')[0];
var array = readline().split(' ');
var categories = {};
var combinations = 0;

for (var i = 0; i < array.length; i++){
    if (categories[array[i]] === undefined)
        categories[array[i]] = 1;
    else
        categories[array[i]]++;
}

for (category in categories){
    summaryBooks -= categories[category];
    combinations += categories[category]*summaryBooks;
}

print(combinations);

// O(n) time complexity, O(m) additional memory.
var input = readline().split(" ").map(i => +i);
var n = input[0];
var m = input[1];
var genreHistogram = new Array(m).fill(0);
for (var ai of readline().split(" ").map(i => +i)) {
    ++genreHistogram[ai - 1];
}
var possibilities = 0;
for (var mh of genreHistogram) {
    // Each book within current genre can be combined with any book from any other genre.
    possibilities += mh * (n - mh);
}
// We took all pairs into account twice.
possibilities /= 2;
write(possibilities + "\n");

var summaryBooks = readline().split(' ')[0];
var array = readline().split(' ');
var categories = {};
var combinations = 0;

for (var i = 0; i < array.length; i++){
    if (categories[i] === undefined)
    categories[i] = 1;
  else
    categories[i]++;
}

for (category in categories){
    summaryBooks -= category;
  combinations += category*summaryBooks;
}

print(combinations);


As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...

The first and only line of input contains a single nonempty string s of length at most 1000 composed of lowercase letters (a-z).

Output YES if the string s contains heidi as a subsequence and NO otherwise.

NoteA string s contains another string p as a subsequence if it is possible to delete some characters from s and obtain p.

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

rl.on('line', (str) => {
  const matrix = new Array(word.length).fill(0).map(x => new Array(str.length).fill(0));

  for (let i = 0; i < word.length; i++) {
    for (let j = 0; j < str.length; j++) {
      if (word[i] === str[j]) {
        const prevDiagonal = matrix[i - 1] && matrix[i - 1][j - 1] || 0;
        matrix[i][j] = prevDiagonal + 1;
      }
      else {
        const prevRow = matrix[i - 1] && matrix[i - 1][j] || 0;
        const prevCell = matrix[i][j - 1] || 0;
        matrix[i][j] = Math.max(prevRow, prevCell);
      }
    }
  }

  if (matrix[matrix.length - 1][matrix[0].length - 1] === word.length) {
    console.log('YES');
  }
  else {
    console.log('NO');
  }

  c++;
});

function solve(){
	var fake = readline();
	if(fake.length>5){
		var h = fake.indexOf("h");
		if(h!= -1){
			var e = fake.indexOf("e", h+1);
			if (e!= -1){
				var i = fake.indexOf("i", e+1);
				if (i!= -1){
					var d = fake.indexOf("d", i+1);
					if(d!= -1){
						if (i != -1){
							var i2 = fake.indexOf("i", d+1);
						}
					}
				}
			}
		}

		if((h!=-1 && e!= -1 && i !=-1 && d != -1 && i2 !=-1) && (h<e && e<i && i< d && d<i2) ){
			print("YES");
		}
		else{
			print("NO");

		}
	}
	else{
		print("NO");
	}

}

if (typeof DEBUG_ENV_CAN_RUN == "undefined") solve();

// Getting problem data from codeforces.
const heidi = 'heidi', problemString = readline();
// Determing if subsequence heidi is present.
var index = 0;
for(var j = 0;j<problemString.length;++j){
  problemString[j] == heidi[index]?
    ++index:undefined;
}
// Solution.
index == heidi.length?print('YES'):print('NO');

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

rl.on('line', (str) => {
  const matrix = new Array(word.length).fill(0).map(x => new Array(str.length).fill(0));

  for (let i = 0; i < word.length; i++) {
    for (let j = 0; j < str.length; j++) {
      const prevRow = matrix[i - 1] && matrix[i - 1][j] || 0;
      const prevCell = matrix[i][j - 1] || 0;

      if (word[i] === str[j]) {
        const prevDiagonal = matrix[i - 1] && matrix[i - 1][j - 1] || 0;
        matrix[i][j] = Math.max(prevRow, prevCell, prevDiagonal) + 1;
      }
      else {
        matrix[i][j] = Math.max(prevRow, prevCell);
      }
    }
  }

  if (matrix[matrix.length - 1][matrix[0].length - 1] === word.length) {
    console.log('YES');
  }
  else {
    console.log('NO');
  }

  c++;
});

function solve(){
	var fake = readline();
	if(fake.length>5){
		var h = fake.indexOf("h");
		var e = fake.indexOf("e");
		var i = fake.indexOf("i");
		var d = fake.indexOf("d");
		if (i != -1){
			var i2 = fake.indexOf("i", i+1);
		}

		if((h!=-1 && e!= -1 && i !=-1 && d != -1 && i2 !=-1) && (h<e && e<i && i< d && d<i2) ){
			print("YES");
		}
		else{
			print("NO");

		}
	}
	else{
		print("NO");
	}

}

if (typeof DEBUG_ENV_CAN_RUN == "undefined") solve();