#include <bits/stdc++.h>
using namespace std;
inline int ni() {
  int a;
  scanf("%d", &a);
  return a;
}
inline double nf() {
  double a;
  scanf("%lf", &a);
  return a;
}
template <class T>
void out(T a, T b) {
  bool first = true;
  for (T i = a; i != b; i++) {
    if (!first) printf(" ");
    first = false;
    cout << *i;
  }
  puts("");
}
template <class T>
void outl(T a, T b) {
  for (T i = a; i != b; i++) cout << *i << "\n";
}
const int MAXLEN = 19;
const int MAXMASK = 800;
const int MAXADD = 5;
int t;
long long x;
bool d[MAXLEN][MAXADD];
pair<int, int> p[MAXLEN][MAXADD];
vector<int> v;
int cur;
const int MAXSUM = 50;
bool g[MAXSUM];
vector<int> gp[MAXSUM];
inline int o(int a) {
  if (a == 0) return 0;
  if (a == 1) return 4;
  return 7;
}
long long tod(vector<int> &a) {
  long long ans = 0;
  for (int i = 0; i < (int)(((int)(a).size())); i++) ans = ans * 10 + a[i];
  return ans;
}
int main() {
  for (int i1 = 0; i1 < 3; i1++)
    for (int i2 = 0; i2 < 3; i2++)
      for (int i3 = 0; i3 < 3; i3++)
        for (int i4 = 0; i4 < 3; i4++)
          for (int i5 = 0; i5 < 3; i5++)
            for (int i6 = 0; i6 < 3; i6++) {
              int val = o(i1) + o(i2) + o(i3) + o(i4) + o(i5) + o(i6);
              if (!g[val]) {
                g[val] = true;
                gp[val].push_back(o(i1));
                gp[val].push_back(o(i2));
                gp[val].push_back(o(i3));
                gp[val].push_back(o(i4));
                gp[val].push_back(o(i5));
                gp[val].push_back(o(i6));
              }
            }
  cin >> t;
  while (t--) {
    cin >> x;
    v.clear();
    for (int i = 0; i < MAXLEN - 1; i++) {
      v.push_back(x % 10);
      x /= 10;
    }
    reverse((v).begin(), (v).end());
    memset(d, 0, sizeof(d));
    d[0][0] = true;
    p[0][0] = make_pair(-1, -1);
    for (int i = 0; i < MAXLEN - 1; i++) {
      for (int j = 0; j < MAXADD; j++) {
        if (!d[i][j]) continue;
        cur = v[((int)(v).size()) - i - 1];
        for (int k = 0; k < MAXSUM; k++) {
          if (g[k] && (k + j) % 10 == cur) {
            d[i + 1][(k + j) / 10] = true;
            p[i + 1][(k + j) / 10] = make_pair(j, k);
          }
        }
      }
    }
    if (d[MAXLEN - 1][0]) {
      vector<int> ans;
      cur = MAXLEN - 1;
      int curadd = 0;
      while (cur > 0) {
        pair<int, int> prev = p[cur][curadd];
        ans.push_back(prev.second);
        curadd = prev.first;
        cur--;
      }
      vector<vector<int> > res(6, vector<int>(ans.size(), 0));
      for (int i = 0; i < (int)(((int)(ans).size())); i++) {
        for (int j = 0; j < (int)(((int)(gp[ans[i]]).size())); j++)
          res[j].push_back(gp[ans[i]][j]);
      }
      for (int i = 0; i < (int)(6); i++) {
        cout << tod(res[i]) << " ";
      }
      cout << "\n";
    } else {
      puts("-1");
      continue;
    }
  }
}
