#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
vector<pair<long long, pair<long long, long long> > > here[10];
vector<pair<long long, long long> > ans;
bool work(long long val) {
  if (val < 0) return false;
  if (val == 0) return true;
  long long v = val % 10;
  for (long long i = 0; i < here[v].size(); i++) {
    if (work(val / 10 - here[v][i].first)) {
      ans.push_back(
          make_pair(here[v][i].second.first, here[v][i].second.second));
      return true;
    }
  }
  return false;
}
void printAns() {
  long long Ans[6] = {0};
  for (long long i = 0; i < ans.size(); i++) {
    long long pos = 0;
    for (long long j = 0; j < ans[i].first; j++, pos++)
      Ans[pos] = Ans[pos] * 10 + 4;
    for (long long j = 0; j < ans[i].second; j++, pos++)
      Ans[pos] = Ans[pos] * 10 + 7;
    for (long long j = pos; j < 6; j++) Ans[pos] *= 10;
  }
  for (long long i = 0; i < 6; i++) printf("%lld ", Ans[i]);
  return;
}
void solve() {
  long long n;
  scanf("%lld", &n);
  ans.clear();
  if (work(n))
    printAns();
  else
    printf("-1");
  cout << endl;
  return;
}
void pre() {
  for (long long i = 0; i <= 6; i++) {
    for (long long j = 0; i + j <= 6; j++) {
      long long val = i * 4 + j * 7;
      here[val % 10].push_back(make_pair(val / 10, make_pair(i, j)));
    }
  }
  return;
}
signed main() {
  pre();
  long long t;
  scanf("%lld", &t);
  while (t--) solve();
  return 0;
}
