#include <bits/stdc++.h>
using namespace std;
bool dp[20][10];
int dp4[20][10], dp7[20][10], dpj[20][10];
long long n;
int bit = 1;
long long ten[20];
long long r[6];
int w[20];
int main() {
  int tcase;
  scanf("%d", &tcase);
  ten[0] = 1;
  for (int i = 1; i <= 18; i++) ten[i] = ten[i - 1] * 10;
  while (tcase--) {
    memset(dp, 0, sizeof(dp));
    bit = 1;
    scanf("%lld", &n);
    while (n) {
      w[bit++] = n % 10;
      n /= 10;
    }
    bit--;
    dp[1][0] = true;
    for (int i = 1; i <= bit; i++) {
      for (int j = 0; j < 9; j++)
        if (dp[i][j]) {
          for (int x = 0; x <= 6; x++)
            for (int y = 0; x + y <= 6; y++) {
              if ((x * 4 + y * 7 + j - w[i]) % 10 != 0) continue;
              dp[i + 1][(x * 4 + y * 7 + j - w[i]) / 10] = 1;
              dp4[i + 1][(x * 4 + y * 7 + j - w[i]) / 10] = x;
              dp7[i + 1][(x * 4 + y * 7 + j - w[i]) / 10] = y;
              dpj[i + 1][(x * 4 + y * 7 + j - w[i]) / 10] = j;
            }
        }
    }
    if (!dp[bit + 1][0]) {
      puts("-1");
      continue;
    }
    int j = 0;
    memset(r, 0, sizeof(r));
    for (int i = bit + 1; i >= 2; i--) {
      int x = dp4[i][j], y = dp7[i][j], jj = dpj[i][j];
      for (int k = 0; k < 6; k++) {
        if (k < x)
          r[k] += 4 * ten[i - 2];
        else if (k < x + y)
          r[k] += 7 * ten[i - 2];
      }
      j = jj;
    }
    for (int i = 0; i < 6; i++) printf("%lld ", r[i]);
    puts("");
  }
  return 0;
}
