#include <bits/stdc++.h>
using namespace std;
map<int, vector<long long> > s;
vector<long long> operator+(const vector<long long> &a,
                            const vector<long long> &b) {
  vector<long long> res((int)(a.size()));
  for (int i = (0); i <= (int((int)(a.size())) - 1); i++) res[i] = a[i] + b[i];
  return res;
}
vector<long long> operator*(const vector<long long> &v, int x) {
  vector<long long> res = v;
  for (int i = (0); i <= (int((int)(res.size())) - 1); i++) res[i] *= x;
  return res;
}
vector<long long> solve(long long x) {
  if (x <= 42) {
    if (s.find(x) != s.end())
      return s[x];
    else
      return vector<long long>();
  }
  for (map<int, vector<long long> >::iterator it = s.begin(); it != s.end();
       it++) {
    if ((x - it->first) % 10 == 0) {
      vector<long long> q = solve((x - it->first) / 10);
      if ((int)(q.size())) {
        q = q * 10;
        q = q + it->second;
        return q;
      }
    }
  }
  return vector<long long>();
}
int main() {
  vector<long long> v;
  for (int i = (0); i <= (int(7) - 1); i++)
    for (int j = (0); j <= (int(7 - i) - 1); j++) {
      vector<long long> v;
      for (int k = (0); k <= (int(i) - 1); k++) v.push_back(4);
      for (int k = (0); k <= (int(j) - 1); k++) v.push_back(7);
      while ((int)(v.size()) < 6) v.push_back(0);
      s[i * 4 + j * 7] = v;
    }
  int tc;
  scanf("%d", &tc);
  while (tc--) {
    long long x;
    cin >> x;
    vector<long long> q = solve(x);
    if (q.size()) {
      for (int i = (0); i <= (int(6) - 1); i++) {
        if (i) cout << " ";
        cout << q[i];
      }
      cout << endl;
    } else {
      cout << -1 << endl;
    }
  }
  return 0;
}
