#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int MAX = 1e9 + 5;
long long h[5005][10][10][30], t, i, j, k, n, on[20], m, l;
bool f(long long x, long long elde, long long basamak, long long a1,
       long long a2, long long a3, long long a4, long long a5, long long a6) {
  if (h[l][x % 10][elde][basamak]) return 0;
  h[l][x % 10][elde][basamak] = 1;
  if (x < 0) return 0;
  x -= elde;
  if (x == 0) {
    cout << a1 << ' ' << a2 << ' ' << a3 << ' ' << a4 << ' ' << a5 << ' ' << a6
         << '\n';
    t = 1;
    return 0;
  }
  if (x % 10 == 1) {
    if (t) return 0;
    f(x / 10, 1, basamak + 1, on[basamak] * 7 + a1, on[basamak] * 4 + a2, a3,
      a4, a5, a6);
    if (t) return 0;
    f(x / 10, 2, basamak + 1, on[basamak] * 7 + a1, on[basamak] * 7 + a2,
      on[basamak] * 7 + a3, a4, a5, a6);
  }
  if (x % 10 == 2) {
    if (t) return 0;
    f(x / 10, 3, basamak + 1, on[basamak] * 7 + a1, on[basamak] * 7 + a2,
      on[basamak] * 7 + a3, on[basamak] * 7 + a4, on[basamak] * 4 + a5, a6);
    if (t) return 0;
    f(x / 10, 4, basamak + 1, on[basamak] * 7 + a1, on[basamak] * 7 + a2,
      on[basamak] * 7 + a3, on[basamak] * 7 + a4, on[basamak] * 7 + a5,
      on[basamak] * 7 + a6);
    if (t) return 0;
    f(x / 10, 2, basamak + 1, on[basamak] * 7 + a1, on[basamak] * 7 + a2,
      on[basamak] * 4 + a3, on[basamak] * 4 + a4, a5, a6);
    if (t) return 0;
    f(x / 10, 1, basamak + 1, on[basamak] * 4 + a1, on[basamak] * 4 + a2,
      on[basamak] * 4 + a3, a4, a5, a6);
  }
  if (x % 10 == 4) {
    if (t) return 0;
    f(x / 10, 0, basamak + 1, on[basamak] * 4 + a1, a2, a3, a4, a5, a6);
    if (t) return 0;
    f(x / 10, 1, basamak + 1, on[basamak] * 7 + a1, on[basamak] * 7 + a2, a3,
      a4, a5, a6);
    if (t) return 0;
    f(x / 10, 2, basamak + 1, on[basamak] * 4 + a1, on[basamak] * 4 + a2,
      on[basamak] * 4 + a3, on[basamak] * 4 + a4, on[basamak] * 4 + a5,
      on[basamak] * 4 + a6);
    if (t) return 0;
  }
  if (x % 10 == 3) {
    if (t) return 0;
    f(x / 10, 2, basamak + 1, on[basamak] * 7 + a1, on[basamak] * 4 + a2,
      on[basamak] * 4 + a3, on[basamak] * 4 + a4, on[basamak] * 4 + a5, a6);
  }
  if (x % 10 == 5) {
    if (t) return 0;
    f(x / 10, 3, basamak + 1, on[basamak] * 7 + a1, on[basamak] * 7 + a2,
      on[basamak] * 7 + a3, on[basamak] * 7 + a4, on[basamak] * 7 + a5, a6);
    if (t) return 0;
    f(x / 10, 1, basamak + 1, on[basamak] * 7 + a1, on[basamak] * 4 + a2,
      on[basamak] * 4 + a3, a4, a5, a6);
    if (t) return 0;
    f(x / 10, 2, basamak + 1, on[basamak] * 7 + a1, on[basamak] * 7 + a2,
      on[basamak] * 7 + a3, on[basamak] * 4, a5, a6);
  }
  if (x % 10 == 6) {
    if (t) return 0;
    f(x / 10, 1, basamak + 1, on[basamak] * 4 + a1, on[basamak] * 4 + a2,
      on[basamak] * 4 + a3, on[basamak] * 4 + a4, a5, a6);
    if (t) return 0;
    f(x / 10, 3, basamak + 1, on[basamak] * 7 + a1, on[basamak] * 7 + a2,
      on[basamak] * 7 + a3, on[basamak] * 7 + a4, on[basamak] * 4 + a5,
      on[basamak] * 4 + a6);
    if (t) return 0;
    f(x / 10, 2, basamak + 1, on[basamak] * 7 + a1, on[basamak] * 7 + a2,
      on[basamak] * 4 + a3, on[basamak] * 4 + a4, on[basamak] * 4 + a5, a6);
    if (t) return 0;
  }
  if (x % 10 == 7) {
    if (t) return 0;
    f(x / 10, 0, basamak + 1, on[basamak] * 7 + a1, a2, a3, a4, a5, a6);
    if (t) return 0;
    f(x / 10, 2, basamak + 1, on[basamak] * 7 + a1, on[basamak] * 4 + a2,
      on[basamak] * 4 + a3, on[basamak] * 4 + a4, on[basamak] * 4 + a5,
      on[basamak] * 4 + a6);
    if (t) return 0;
  }
  if (x % 10 == 8) {
    if (t) return 0;
    f(x / 10, 2, basamak + 1, on[basamak] * 7 + a1, on[basamak] * 7 + a2,
      on[basamak] * 7 + a3, on[basamak] * 7 + a4, a5, a6);
    if (t) return 0;
    f(x / 10, 0, basamak + 1, on[basamak] * 4 + a1, on[basamak] * 4 + a2, a3,
      a4, a5, a6);
    if (t) return 0;
    f(x / 10, 1, basamak + 1, on[basamak] * 7 + a1, on[basamak] * 7 + a2,
      on[basamak] * 4 + a3, a4, a5, a6);
  }
  if (x % 10 == 9) {
    if (t) return 0;
    f(x / 10, 1, basamak + 1, on[basamak] * 4 + a1, on[basamak] * 4 + a2,
      on[basamak] * 4 + a3, on[basamak] * 7 + a4, a5, a6);
    if (t) return 0;
    f(x / 10, 3, basamak + 1, on[basamak] * 7 + a1, on[basamak] * 7 + a2,
      on[basamak] * 7 + a3, on[basamak] * 7 + a4, on[basamak] * 7 + a5,
      on[basamak] * 4 + a6);
    if (t) return 0;
    f(x / 10, 2, basamak + 1, on[basamak] * 7 + a1, on[basamak] * 7 + a2,
      on[basamak] * 7 + a3, on[basamak] * 4 + a4, on[basamak] * 4 + a5, a6);
    if (t) return 0;
  }
}
int main() {
  scanf("%lld", &n);
  long long x;
  on[0] = 1;
  for (int i = 1; i <= 18; i++) on[i] = on[i - 1] * 10;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &x);
    t = 0;
    f(x, 0, 0, 0, 0, 0, 0, 0, 0);
    if (!t) cout << -1 << '\n';
  }
  return 0;
}
