#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T BM(T p, T e, T M) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T MDINV(T a, T M) {
  return BM(a, M - 2, M);
}
template <class T>
inline T PW(T p, T e) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p);
    p = (p * p);
  }
  return (T)ret;
}
template <class T>
string NTS(T Number) {
  stringstream ss;
  ss << Number;
  return ss.str();
}
template <class T>
T stringtonumber(const string &Text) {
  istringstream ss(Text);
  T result;
  return ss >> result ? result : 0;
}
long long int res[22][10];
long long int len;
long long int a[] = {7, 4, 0};
long long int vis[10][25];
string s;
long long int solve(long long int x, long long int y) {
  if (x == len) {
    if (y == 0)
      return 1;
    else
      return 0;
  }
  long long int &ret = res[x][y];
  if (ret != -1) return ret;
  ret = 0;
  for (long long int i = 0; i <= 2; i++) {
    for (long long int j = 0; j <= 2; j++) {
      for (long long int k = 0; k <= 2; k++) {
        for (long long int l = 0; l <= 2; l++) {
          for (long long int m = 0; m <= 2; m++) {
            for (long long int n = 0; n <= 2; n++) {
              long long int lp = a[i] + a[j] + a[k] + a[l] + a[m] + a[n] + y;
              long long int op = lp % 10;
              long long int re = lp / 10;
              if (op == (s[x] - '0')) {
                ret = max(ret, solve(x + 1, re));
                if (ret == 1) {
                  vis[1][x] = i;
                  vis[2][x] = j;
                  vis[3][x] = k;
                  vis[4][x] = l;
                  vis[5][x] = m;
                  vis[6][x] = n;
                  return ret;
                }
              }
            }
          }
        }
      }
    }
  }
  return ret;
}
int main() {
  long long int tc;
  scanf("%lld", &tc);
  for (long long int t = 1; t <= tc; t++) {
    memset(vis, 0, sizeof vis);
    cin >> s;
    reverse(s.begin(), s.end());
    string h = "0";
    h += s;
    s = h;
    len = s.size();
    memset(res, -1, sizeof res);
    long long int re = solve(1, 0);
    if (re == 0) {
      pair<long long int, long long int>(-1ll);
    } else {
      for (long long int i = 1; i <= 6; i++) {
        long long int ops = 0;
        for (long long int j = 1; j < len; j++) {
          ops = ops * 10 + a[vis[i][j]];
        }
        string d = NTS(ops);
        reverse(d.begin(), d.end());
        ops = stringtonumber<long long int>(d);
        cout << ops << " ";
      }
      printf("\n");
    }
  }
  return 0;
}
