#include <bits/stdc++.h>
using namespace std;
long long x;
int v[111][111], dp[111][111], l[111][111];
vector<int> mem[111];
int calc(long long x, int p, int red) {
  if (x < 0) return 0;
  if (x == 0) return 1;
  if (v[p][red]) return dp[p][red];
  v[p][red] = 1;
  dp[p][red] = 0;
  for (int i = 0; i < (10); ++i) {
    if (l[i][(int)(x % 10LL)]) {
      dp[p][red] |= calc(x / 10LL - (long long)i, p + 1, i);
    }
  }
  return dp[p][red];
}
int main() {
  int pos[100] = {0};
  for (int i = 0; i < (7); ++i)
    for (int j = 0; j < (7 - i); ++j) {
      if (!pos[4 * i + 7 * j]) {
        pos[4 * i + 7 * j] = 1;
        for (int _i = 0; _i < (i); ++_i) mem[4 * i + 7 * j].push_back(4);
        for (int _i = 0; _i < (j); ++_i) mem[4 * i + 7 * j].push_back(7);
        for (int _i = 0; _i < (6 - i - j); ++_i)
          mem[4 * i + 7 * j].push_back(0);
      }
    }
  for (int i = 0; i < (100); ++i)
    if (pos[i]) {
      l[i / 10][i % 10] = 1;
    }
  int _n;
  scanf("%d", &_n);
  for (int _i = 0; _i < (_n); ++_i) {
    long long x;
    scanf("%I64d", &x);
    memset(v, 0, sizeof(v));
    if (!calc(x, 0, 0)) {
      puts("-1");
    } else {
      vector<long long> ans(6);
      long long total = 0, ten = 1LL, _x = x;
      int p = 0;
      while (total != _x) {
        for (int i = 0; i < (10); ++i) {
          if (l[i][(int)(x % 10LL)] &&
              calc(x / 10LL - (long long)i, p + 1, i)) {
            for (int j = 0; j < (6); ++j)
              ans[j] += ten * mem[10 * i + (int)(x % 10LL)][j];
            x = x / 10LL - (long long)i;
            break;
          }
        }
        p++;
        ten *= 10LL;
        total = 0;
        for (int i = 0; i < (6); ++i) total += ans[i];
      }
      for (int i = 0; i < (6); ++i) printf("%I64d ", ans[i]);
      puts("");
    }
  }
  return 0;
}
