#include <bits/stdc++.h>
using namespace std;
const int inf = 0x20202020;
const int mod = 1000000007;
inline void read(int &x) {
  char ch;
  bool f = 0;
  int a = 0;
  while (!((((ch = getchar()) >= '0') && (ch <= '9')) || (ch == '-')))
    ;
  if (ch != '-')
    a *= 10, a += ch - '0';
  else
    f = 1;
  while (((ch = getchar()) >= '0') && (ch <= '9')) a *= 10, a += ch - '0';
  if (f) a = -a;
  x = a;
}
const int DX[] = {1, 0, -1, 0}, DY[] = {0, 1, 0, -1};
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long powmod(long long a, long long b, long long mod) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int N = 111111, M = 111111;
const long long chen[] = {1,
                          10,
                          100,
                          1000,
                          10000,
                          100000,
                          1000000,
                          100000000,
                          1000000000,
                          10000000000ll,
                          100000000000ll,
                          1000000000000ll,
                          10000000000000ll,
                          100000000000000ll,
                          1000000000000000ll,
                          10000000000000000ll,
                          100000000000000000ll,
                          1000000000000000000ll};
int l, m, n, t, a[66], b[66], v[N], dp[22][11], C;
long long ans[11];
pair<int, int> pre[22][66];
long long pp;
queue<pair<int, int> > Q;
int main() {
  for (int i = 1; i <= 65; ++i) a[i] = b[i] = -1;
  for (int i = 0; i <= 6; ++i)
    for (int j = 0; j <= 6 - i; ++j) a[i * 4 + j * 7] = i, b[i * 4 + j * 7] = j;
  scanf("%d", &C);
  for (int _ = 1; _ <= C; ++_) {
    scanf("%lld", &pp);
    n = 0;
    memset(dp, 0, sizeof(dp));
    memset(ans, 0, sizeof(ans));
    memset(v, 0, sizeof(v));
    while (pp) v[++n] = pp % 10, pp /= 10;
    Q.push(make_pair(0, v[1]));
    while (Q.size()) {
      pair<int, int> k = Q.front();
      Q.pop();
      for (int i = 0; i <= min(v[k.first + 2], 5); ++i)
        if (!dp[k.first + 1][v[k.first + 2] - i] && k.first <= 18 &&
            (a[i * 10 + k.second] >= 0 || b[i * 10 + k.second] >= 0)) {
          Q.push(make_pair(k.first + 1, v[k.first + 2] - i));
          pre[k.first + 1][v[k.first + 2] - i] = k;
          dp[k.first + 1][v[k.first + 2] - i] = 1;
        }
    }
    if (!dp[19][0]) {
      puts("-1");
      continue;
    }
    pair<int, int> k = make_pair(19, 0);
    while (k.first) {
      pair<int, int> p = pre[k.first][k.second];
      int tmp = (v[k.first + 1] - k.second) * 10 + p.second;
      for (int i = 1; i <= a[tmp]; ++i) ans[i] += chen[k.first - 1] * 4;
      for (int i = 6; i >= 6 - b[tmp] + 1; --i) ans[i] += chen[k.first - 1] * 7;
      k = p;
    }
    for (int i = 1; i <= 5; ++i) printf("%d ", ans[i]);
    printf("%d\n", ans[6]);
  }
  return 0;
}
