#include <bits/stdc++.h>
using namespace std;
bool debug = false;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long ln, lk, lm;
map<int, vector<int>> mp;
void init() {
  for (int(j) = 0; (j) < (int)(7); (j)++)
    for (int(i) = 0; (i) < (int)(7); (i)++)
      if (i + j <= 6) {
        m = 0;
        vector<int> v;
        int p = 0;
        for (p = 0; p < i; p++) {
          v.push_back(4);
          m += 4;
        }
        for (p = 0; p < j; p++) {
          v.push_back(7);
          m += 7;
        }
        while (v.size() < 6) v.push_back(0);
        mp[m] = (v);
      }
}
int dp[20][10], pre[20][10];
long long ans[6];
void add(int x) {
  vector<int> vp = mp[x];
  for (int(i) = 0; (i) < (int)(6); (i)++) ans[i] = ans[i] * 10 + vp[i];
}
void cal(long long x) {
  for (int(i) = 0; (i) < (int)(20); (i)++)
    for (int(j) = 0; (j) < (int)(10); (j)++) {
      dp[i][j] = -1;
      pre[i][j] = -1;
    }
  long long tx = x;
  int i = 0;
  dp[0][0] = 0;
  while (tx) {
    int tar = tx % 10;
    tx /= 10;
    bool ok = 0;
    i++;
    for (int j = 0; j < 10; j++)
      if (dp[i - 1][j] != -1) {
        for (auto p : mp) {
          int ss = (j + p.first);
          if (ss % 10 == tar) {
            dp[i][ss / 10] = p.first;
            pre[i][ss / 10] = j;
            ok = 1;
          }
        }
      }
    if (!ok) {
      puts("-1");
      return;
    }
  }
  for (int(j) = 0; (j) < (int)(6); (j)++) ans[j] = 0;
  if (dp[i][0] == -1) {
    puts("-1");
    return;
  }
  for (int j = i, q = 0; j > 0; j--) {
    add(dp[j][q]);
    q = pre[j][q];
  }
  for (int(j) = 0; (j) < (int)(6); (j)++) printf("%d ", ans[j]);
  puts("");
}
int main() {
  init();
  scanf("%d", &n);
  for (int(i) = 0; (i) < (int)(n); (i)++) {
    scanf("%lld", &ln);
    cal(ln);
  }
  return 0;
}
