#include <bits/stdc++.h>
using namespace std;
int T, tt, tmp;
long long N, b[6];
int a[25], g[25][25][3], L;
bool f[25][25];
void doit() {
  cin >> N;
  tmp++;
  if (tt == 5000) {
    if (tmp == 4391) cout << N << endl;
    return;
  }
  long long nn = N;
  L = 0;
  for (; N; N /= 10) a[++L] = N % 10;
  memset(f, 0, sizeof(f)), memset(b, 0, sizeof(b)), f[0][0] = 1;
  for (int i = 1; i <= L; i++)
    for (int j = 0; j < 25; j++)
      if (f[i - 1][j])
        for (int k = 0; k <= 6; k++)
          for (int l = 0, x, y; k + l <= 6; l++)
            if ((x = j + k * 4 + l * 7) % 10 == a[i])
              f[i][y = x / 10] = 1, g[i][y][0] = j, g[i][y][1] = k,
                           g[i][y][2] = l;
  if (!f[L][0]) {
    cout << -1 << endl;
    return;
  }
  for (int i = L, j = 0, k, x, y; i; i--, j = k) {
    k = g[i][j][0], x = g[i][j][1], y = g[i][j][2];
    for (int l = 1; l <= x; l++) (b[l - 1] *= 10) += 4;
    for (int l = 1; l <= y; l++) (b[x + l - 1] *= 10) += 7;
    for (int l = x + y; l < 6; l++) b[l] *= 10;
  }
  for (int i = 0; i < 6; i++) cout << b[i] << " ";
  cout << endl;
}
int main() {
  scanf("%d", &T);
  tt = T, tmp = 0;
  for (; T; T--) doit();
}
