#include <bits/stdc++.h>
using namespace std;
template <typename X>
inline X abs(const X& a) {
  return (a < 0 ? -a : a);
}
template <typename X>
inline X sqr(const X& a) {
  return a * a;
}
const int INF = int(1e9);
const int INF64 = int(1e18);
const long double EPS = long double(1e-9);
const long double PI = long double(3.1415926535897932384626433832795);
const int N = 50;
const int M = 50;
int s[N];
int d[N][M];
pair<int, pair<int, int> > p[N][M];
inline bool read() {
  long long n;
  cin >> n;
  int iter = 0;
  memset(s, 0, sizeof s);
  while (n > 0) {
    s[iter] = n % 10;
    iter++;
    n /= 10;
  }
  return true;
}
inline void solve() {
  memset(d, 0, sizeof d);
  d[0][0] = 1;
  for (int i = 0; i < int(N - 1); i++) {
    for (int j = 0; j < int(M); j++) {
      if (d[i][j] != 1) continue;
      for (int k = 0; k < int(7); k++) {
        for (int t = 0; t < int(7 - k); t++) {
          int sum = 4 * k + 7 * t;
          if ((sum + j) % 10 == s[i]) {
            d[i + 1][(sum + j) / 10] += d[i][j];
            p[i + 1][(sum + j) / 10] = make_pair(j, make_pair(k, t));
          }
        }
      }
    }
  }
  cerr << d[N - 1][0] << endl;
  if (d[N - 1][0] > INF) throw;
  if (d[N - 1][0] != 1) {
    puts("-1");
    return;
  } else {
    int s = N - 1;
    int j = 0;
    vector<long long> ans(6, 0);
    while (true) {
      if (s == 0 && j == 0) break;
      pair<int, pair<int, int> > curs = p[s][j];
      int fours = curs.second.first;
      int sevens = curs.second.second;
      for (int k = 0; k < int(int((ans).size())); k++) {
        ans[k] *= 10;
        if (fours > 0) {
          ans[k] += 4;
          fours--;
          continue;
        }
        if (sevens > 0) {
          ans[k] += 7;
          sevens--;
          continue;
        }
      }
      s--;
      j = curs.first;
    }
    for (int j = 0; j < int(int((ans).size())); j++) {
      cout << ans[j] << ' ';
    }
    cout << endl;
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    assert(read());
    solve();
  }
}
