#include <bits/stdc++.h>
using namespace std;
set<long long> s;
const long long maxn = 20;
long long a[maxn];
map<long long, vector<long long>> invS;
long long n;
long long dp[maxn][101];
bool recur(long long pos, long long last) {
  if (last > 100 || last < 0) return false;
  if (pos == n) {
    if (last == 0)
      return true;
    else
      return false;
  }
  if (dp[pos][last] != -1) return dp[pos][last];
  long long res = false;
  for (long long i : s) {
    long long x = last * 10 + a[pos] - i;
    if (recur(pos + 1, x)) {
      res = true;
    }
  }
  dp[pos][last] = res;
  return res;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  for (long long i : {0, 4, 7})
    for (long long b : {0, 4, 7})
      for (long long c : {0, 4, 7})
        for (long long d : {0, 4, 7})
          for (long long e : {0, 4, 7})
            for (long long f : {0, 4, 7})
              if (s.count(i + b + c + d + e + f) == 0) {
                s.insert(i + b + c + d + e + f);
                invS[i + b + c + d + e + f] = {i, b, c, d, e, f};
              }
  long long t;
  cin >> t;
  while (t--) {
    string str;
    cin >> str;
    for (long long i = 0; i < str.length(); i++) a[i] = str[i] - '0';
    for (long long i = 0; i < maxn; i++)
      for (long long j = 0; j < 101; j++) dp[i][j] = -1;
    n = str.length();
    bool res = recur(0, 0);
    if (!res) {
      cout << "-1\n";
      continue;
    }
    long long pos = 0;
    long long last = 0;
    long long ans[6];
    for (long long i = 0; i < 6; i++) ans[i] = 0;
    while (pos != n) {
      for (long long i : s) {
        long long x = last * 10 + a[pos] - i;
        if (recur(pos + 1, x)) {
          for (long long j = 0; j < 6; j++) {
            long long d = invS[i][j];
            ans[j] += d * pow(10, n - pos - 1);
          }
          pos++;
          last = x;
          break;
        }
      }
    }
    for (long long i = 0; i < 6; i++) cout << ans[i] << ' ';
    cout << '\n';
  }
}
