#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 29;
vector<pair<int, int> > e[12], ans;
int bit[20], kk;
long long val[9];
int dfs(int k, int pre) {
  if (k == kk) {
    if (pre == 0) {
      long long tt = 1;
      memset(val, 0, sizeof(val));
      for (int i = 0; i < ans.size(); i++) {
        for (int j = 0; j < ans[i].first; j++) val[j] += tt * 4;
        for (int j = ans[i].first; j < ans[i].first + ans[i].second; j++)
          val[j] += tt * 7;
        tt *= 10;
      }
      for (int i = 0; i < 6; i++) printf("%I64d ", val[i]);
      puts("");
      return 1;
    }
    return 0;
  }
  int t = (bit[k] - pre + 10) % 10;
  for (int i = 0; i < e[t].size(); i++) {
    ans.push_back(e[t][i]);
    if (dfs(k + 1, (e[t][i].first * 4 + e[t][i].second * 7) / 10)) return 1;
    ans.pop_back();
  }
  return 0;
}
int main() {
  for (int i = 0; i <= 6; i++) {
    for (int j = 0; j <= 6 - i; j++) {
      e[(4 * i + 7 * j) % 10].push_back(make_pair(i, j));
    }
  }
  int n;
  long long x;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    ans.clear();
    scanf("%I64d", &x);
    kk = 0;
    while (x) {
      bit[kk++] = x % 10;
      x /= 10;
    }
    int ans = dfs(0, 0);
    if (ans == 0) printf("-1\n");
  }
}
