/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};

/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {

/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId])
/******/ 			return installedModules[moduleId].exports;

/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			exports: {},
/******/ 			id: moduleId,
/******/ 			loaded: false
/******/ 		};

/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ 		// Flag the module as loaded
/******/ 		module.loaded = true;

/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}

/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;

/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;

/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";

/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	var List = __webpack_require__(1);
	var n = List.map(parseInt, readline().split(' '))[0];
	var a = List.map(parseInt, readline().split(' '));
	var level = 0;
	var changes = 0;
	var i = 0;
	var di = 1;
	while (true) {
	    while (i >= 0 && i < n) {
	        if (a[i] <= level) {
	            level++;
	            a[i] = n + 1;
	        }
	        i += di;
	    }
	    if (level == n)
	        break;
	    i -= di;
	    di = -di;
	    changes++;
	}
	print(changes);

/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {

	var Prelude_1 = __webpack_require__(2);
	function add(xs, ys) {
	    return xs.concat(ys);
	}
	exports.add = add;
	function head(xs) {
	    return xs[0];
	}
	exports.head = head;
	function last(xs) {
	    return xs[xs.length - 1];
	}
	exports.last = last;
	function tail(xs) {
	    return xs.slice(1);
	}
	exports.tail = tail;
	function init(xs) {
	    return xs.slice(0, xs.length - 1);
	}
	exports.init = init;
	function map(f, xs) {
	    var result = new Array(xs.length);
	    for (var i = 0; i < xs.length; i++) {
	        result[i] = f(xs[i]);
	    }
	    return result;
	}
	exports.map = map;
	function reverse(xs) {
	    return xs.slice().reverse();
	}
	exports.reverse = reverse;
	function intersperse(x, xs) {
	    if (xs.length == 0) {
	        return [];
	    }
	    var result = new Array(xs.length + xs.length - 1);
	    for (var i = 0; i + 1 < xs.length; i++) {
	        result[i + i] = xs[i];
	        result[i + i + 1] = x;
	    }
	    result[result.length - 1] = xs[xs.length - 1];
	    return result;
	}
	exports.intersperse = intersperse;
	function intercalate(xs, xss) {
	    return concat(intersperse(xs, xss));
	}
	exports.intercalate = intercalate;
	function foldl(f, initial, xs) {
	    var result = initial;
	    for (var i = 0; i < xs.length; i++) {
	        result = f(result, xs[i]);
	    }
	    return result;
	}
	exports.foldl = foldl;
	function foldr(f, initial, xs) {
	    var result = initial;
	    for (var i = xs.length - 1; i >= 0; i--) {
	        result = f(xs[i], result);
	    }
	    return result;
	}
	exports.foldr = foldr;
	function concat(xss) {
	    var total = sum(map(function (xs) { return xs.length; }, xss));
	    var result = new Array(total);
	    var m = 0;
	    for (var i = 0; i < xss.length; i++) {
	        var xs = xss[i];
	        for (var j = 0; j < xs.length; j++) {
	            result[m++] = xs[j];
	        }
	    }
	    return result;
	}
	exports.concat = concat;
	function sum(xs) {
	    var result = 0;
	    for (var i = 0; i < xs.length; i++) {
	        result += xs[i];
	    }
	    return result;
	}
	exports.sum = sum;
	function product(xs) {
	    var result = 1;
	    for (var i = 0; i < xs.length; i++) {
	        result *= xs[i];
	    }
	    return result;
	}
	exports.product = product;
	function sort(xs, compare) {
	    return copy(xs).sort(compare);
	}
	exports.sort = sort;
	function sortInPlace(xs, compare) {
	    xs.sort(compare);
	    return xs;
	}
	exports.sortInPlace = sortInPlace;
	function maximumInRange(xs, s, e) {
	    var result = xs[s];
	    for (var i = s + 1; i <= e; i++) {
	        if (result < xs[i])
	            result = xs[i];
	    }
	    return result;
	}
	exports.maximumInRange = maximumInRange;
	function maximum(xs) {
	    return maximumInRange(xs, 0, xs.length - 1);
	}
	exports.maximum = maximum;
	function maximumInRangeWith(xs, s, e, f) {
	    var result = f(xs[s]);
	    for (var i = s + 1; i <= e; i++) {
	        var candidate = f(xs[i]);
	        if (result < candidate)
	            result = candidate;
	    }
	    return result;
	}
	exports.maximumInRangeWith = maximumInRangeWith;
	function maximumWith(xs, f) {
	    return maximumInRangeWith(xs, 0, xs.length - 1, f);
	}
	exports.maximumWith = maximumWith;
	function minimumInRange(xs, s, e) {
	    var result = xs[s];
	    for (var i = s + 1; i <= e; i++) {
	        if (result > xs[i])
	            result = xs[i];
	    }
	    return result;
	}
	exports.minimumInRange = minimumInRange;
	function minimum(xs) {
	    return minimumInRange(xs, 0, xs.length - 1);
	}
	exports.minimum = minimum;
	function minimumInRangeWith(xs, s, e, f) {
	    var result = f(xs[s]);
	    for (var i = s + 1; i <= e; i++) {
	        var candidate = f(xs[i]);
	        if (result > candidate)
	            result = candidate;
	    }
	    return result;
	}
	exports.minimumInRangeWith = minimumInRangeWith;
	function minimumWith(xs, f) {
	    return minimumInRangeWith(xs, 0, xs.length - 1, f);
	}
	exports.minimumWith = minimumWith;
	function replicate(n, x) {
	    var result = new Array(n);
	    for (var i = 0; i < result.length; i++) {
	        result[i] = x;
	    }
	    return result;
	}
	exports.replicate = replicate;
	function take(n, xs) {
	    return xs.slice(0, n);
	}
	exports.take = take;
	function drop(n, xs) {
	    return xs.slice(n);
	}
	exports.drop = drop;
	function splitAt(n, xs) {
	    return [take(n, xs), drop(n, xs)];
	}
	exports.splitAt = splitAt;
	function takeWhile(f, xs) {
	    for (var i = 0; i < xs.length; i++) {
	        if (!f(xs[i])) {
	            return xs.slice(0, i);
	        }
	    }
	    return xs.slice();
	}
	exports.takeWhile = takeWhile;
	function dropWhile(f, xs) {
	    for (var i = 0; i < xs.length; i++) {
	        if (!f(xs[i])) {
	            return xs.slice(i);
	        }
	    }
	    return [];
	}
	exports.dropWhile = dropWhile;
	function group(xs) {
	    if (xs.length == 0)
	        return [];
	    var result = [];
	    var last = [xs[0]];
	    for (var i = 1; i < xs.length; i++) {
	        if (last[0] === xs[i]) {
	            last.push(xs[i]);
	        }
	        else {
	            result.push(last);
	            last = [xs[i]];
	        }
	    }
	    result.push(last);
	    return result;
	}
	exports.group = group;
	function nub(xs) {
	    if (xs.length == 0)
	        return [];
	    var result = [];
	    result.push(xs[0]);
	    for (var i = 1; i < xs.length; i++) {
	        if (xs[i] !== xs[i - 1]) {
	            result.push(xs[i]);
	        }
	    }
	    return result;
	}
	exports.nub = nub;
	function filter(f, xs) {
	    var result = [];
	    for (var i = 0; i < xs.length; i++) {
	        if (f(xs[i]))
	            result.push(xs[i]);
	    }
	    return result;
	}
	exports.filter = filter;
	function zip(xs, ys) {
	    var n = Prelude_1.min(xs.length, ys.length);
	    var result = new Array(n);
	    for (var i = 0; i < n; i++) {
	        result[i] = [xs[i], ys[i]];
	    }
	    return result;
	}
	exports.zip = zip;
	function unzip(xs) {
	    var r1 = new Array(xs.length);
	    var r2 = new Array(xs.length);
	    for (var i = 0; i < xs.length; i++) {
	        r1[i] = xs[i][0];
	        r2[i] = xs[i][1];
	    }
	    return [r1, r2];
	}
	exports.unzip = unzip;
	function range(from, to) {
	    var result = Array(to - from + 1);
	    for (var i = from; i <= to; i++) {
	        result[i - from] = i;
	    }
	    return result;
	}
	exports.range = range;
	function copy(xs) {
	    return xs.slice(0);
	}
	exports.copy = copy;
	function apply_permutation(p, xs) {
	    var n = xs.length;
	    var result = new Array(n);
	    for (var i = 0; i < n; i++) {
	        result[i] = xs[p[i]];
	    }
	    return result;
	}
	exports.apply_permutation = apply_permutation;
	function next_permutation(p) {
	    var n = p.length;
	    if (n < 2)
	        return null;
	    var r = copy(p);
	    var k = n - 2;
	    for (; k >= 0 && r[k] >= r[k + 1]; k--)
	        ;
	    if (k < 0)
	        return null;
	    for (var i = k + 1, j = n - 1; i < j; i++, j--) {
	        var t_1 = r[i];
	        r[i] = r[j];
	        r[j] = t_1;
	    }
	    var next = k + 1;
	    for (; r[next] <= r[k]; next++)
	        ;
	    var t = r[k];
	    r[k] = r[next];
	    r[next] = t;
	    return r;
	}
	exports.next_permutation = next_permutation;
	function create(n, value) {
	    return replicate(n, value);
	}
	exports.create = create;
	function createWith(n, f) {
	    var result = new Array(n);
	    for (var i = 0; i < n; i++) {
	        result[i] = f(i);
	    }
	    return result;
	}
	exports.createWith = createWith;
	function create2D(n1, n2, value) {
	    return map(function (_) { return replicate(n2, value); }, replicate(n1, 0));
	}
	exports.create2D = create2D;
	function create2DWith(n1, n2, f) {
	    var result = new Array(n1);
	    for (var i = 0; i < n1; i++) {
	        result[i] = new Array(n2);
	        for (var j = 0; j < n2; j++) {
	            result[i][j] = f(i, j);
	        }
	    }
	    return result;
	}
	exports.create2DWith = create2DWith;

/***/ },
/* 2 */
/***/ function(module, exports) {

	function min(a, b) {
	    return a < b ? a : b;
	}
	exports.min = min;
	function max(a, b) {
	    return a < b ? b : a;
	}
	exports.max = max;
	function curry(f) {
	    return function (x) { return function (y) { return f(x, y); }; };
	}
	exports.curry = curry;
	function uncurry(f) {
	    return function (x, y) { return f(x)(y); };
	}
	exports.uncurry = uncurry;
	function id(x) {
	    return x;
	}
	exports.id = id;
	function constant(x) {
	    return function (_) { return x; };
	}
	exports.constant = constant;
	function flip(f) {
	    return function (y) { return function (x) { return f(x)(y); }; };
	}
	exports.flip = flip;
	function flip2(f) {
	    return function (y, x) { return f(x, y); };
	}
	exports.flip2 = flip2;
	function compose(g, f) {
	    return function (x) { return g(f(x)); };
	}
	exports.compose = compose;
	function gcd(a, b) {
	    var r = a % b;
	    while (r !== 0) {
	        a = b;
	        b = r;
	        r = a % b;
	    }
	    return b;
	}
	exports.gcd = gcd;

/***/ }
/******/ ]);

'use strict';

/*let input = `
7
0 3 1 0 5 2 6
`.trim().split('\n');
function print(output) {
	console.log(output);
}
function readline() {
	return input.shift();
}
*/
//code

var n = Number(readline());
var coveredComputers = [],
    directionChanges = 0,
    i = 0,
    direction = 1;
var infoRequired = readline().split(' ').map(Number);

while (coveredComputers.length != n) {
	if (i >= n || i < 0) {
		direction *= -1;
		directionChanges++;
		i += direction * 2;
	}
	if (coveredComputers.indexOf(i) === -1) {
		if (infoRequired[i] <= coveredComputers.length) {
			coveredComputers.push(i);
		}
	}
	i += direction;
}
print(directionChanges);

n = readline();
a = readline().split(" ").map(Number);

answer = -1;
hacked = 0;

while (hacked < n) {
	answer += 1;
	if (answer % 2 == 0) {
		// right
		for (var i = 0; i < a.length; i++) {
			if (a[i] <= hacked && a[i] != -1) {
				a[i] = -1;
				hacked += 1;
			}
		}
	} else {
		for (var i = a.length-1; i >= 0; --i) {
			if (a[i] <= hacked && a[i] != -1) {
				a[i] = -1;
				hacked += 1;
			}
		}
	}

}

write(answer);

var n = +readline(), a = readline().split(" ").map(Number);
var x = 0, bool = [], proof;

for(var i = 0; i < n; i++){
	bool[i] = true;
}

for(var i = 0; ;i++){
	proof = true;

	for(var j = 0; j < n; j++){
		if(a[j] <= x){
			if(bool[j]){
				x++;
				bool[j] = false;
			}
			else{
				continue;
			}
		}
		else{
			proof = false;
		}
	}

	if(proof){
		write(i);
		break;
	}

	a = a.reverse();
	bool = bool.reverse();
}


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


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

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

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


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

}

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

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

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

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

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

}


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

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

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


// 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[array[i]] === undefined)
        categories[array[i]] = 1;
    else
        categories[array[i]]++;
}

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

print(combinations);

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