#include <bits/stdc++.h>
using namespace std;
int lk[] = {7, 4, 0};
int n, ar[20], dp[20][2];
vector<vector<int> > pre;
int tot, Sm[200005];
vector<int> v;
void gen(int p, int lp, int sm) {
  if (p == 6) {
    pre.push_back(v);
    Sm[tot] = sm;
    tot++;
    return;
  }
  if (lp >= 3) return;
  int smm = sm;
  gen(p, lp + 1, smm);
  for (int i = p; i < 6; i++) {
    v[i] = lk[lp];
    smm += v[i];
    gen(i + 1, lp + 1, smm);
  }
}
int go(int p, int c) {
  if (p == n) return (c == 0);
  int &ret = dp[p][c];
  if (ret != -1) return ret;
  ret = 0;
  for (int i = 0; i < tot; i++) {
    int nsm = (c + Sm[i]);
    if (nsm % 10LL == ar[p]) {
      ret = (ret || go(p + 1, nsm / 10LL));
    }
  }
  return ret;
}
long long br[22][22];
void po(int p, int c) {
  if (p == n) return;
  int &ret = dp[p][c];
  for (int i = 0; i < tot; i++) {
    int nsm = (c + Sm[i]);
    if ((nsm) % 10LL == ar[p]) {
      if (ret == go(p + 1, (nsm / 10LL))) {
        for (int j = 0; j < 6; j++) {
          br[j][p] = pre[i][j];
        }
        po(p + 1, nsm / 10LL);
        return;
      }
    }
  }
  return;
}
int main() {
  int tc, cs = 1, i, j, k;
  long long m;
  tot = 0;
  v.clear();
  for (i = 1; i <= 6; i++) v.push_back(0);
  gen(0, 0, 0);
  scanf("%d", &tc);
  while (tc--) {
    scanf("%I64d", &m);
    n = (floor(log10(m)) + 1);
    for (i = 1; i <= n; i++) {
      ar[i - 1] = (m % 10LL);
      m /= 10LL;
    }
    memset(dp, -1, sizeof(dp));
    bool ans = go(0, 0);
    if (!ans) {
      printf("-1\n");
      continue;
    }
    po(0, 0);
    for (i = 0; i <= 5; i++) {
      long long res = 0LL;
      for (j = n - 1; j >= 0; j--) {
        res = (res * 10LL + br[i][j]);
      }
      printf("%I64d ", res);
    }
    puts("");
  }
  return 0;
}
