#include <bits/stdc++.h>
using namespace std;
bool possible[51];
long long L = 0;
long long nums[51];
long long ways[51][7];
long long digs[20];
long long F[20][5];
long long Path[7];
long long pL = 0;
void Batrak(long long cursum, long long numsleft) {
  if (numsleft == 0) {
    if (!possible[cursum]) {
      long long i;
      possible[cursum] = true;
      L++;
      nums[L] = cursum;
      for (i = 1; i <= 6; i++) {
        ways[L][i] = Path[i];
      }
    }
    return;
  }
  pL++;
  Path[pL] = 0;
  Batrak(cursum, numsleft - 1);
  Path[pL] = 4;
  Batrak(cursum + 4, numsleft - 1);
  Path[pL] = 7;
  Batrak(cursum + 7, numsleft - 1);
  pL--;
  return;
}
long long thenums[7][20];
void Restore(long long dig, long long rem) {
  long long i;
  long long tn = F[dig][rem];
  long long val = nums[tn] + rem;
  if (dig == 20) return;
  for (i = 1; i <= 6; i++) {
    thenums[i][dig] = ways[tn][i];
  }
  Restore(dig + 1, val / 10);
  return;
}
int main() {
  long long i, j, in, ja;
  long long ctr = 0;
  long long n, t;
  long long val;
  long long n_rev;
  long long firstnonzero;
  long long pr;
  Batrak(0, 6);
  scanf("%I64d", &t);
  for (i = 1; i <= t; i++) {
    memset(F, -1, sizeof(F));
    scanf("%I64d", &n);
    n_rev = 0;
    while (n > 0) {
      n_rev = n_rev * 10 + n % 10;
      n = n / 10;
    }
    n = n_rev;
    for (j = 19; j >= 1; j--) {
      digs[j] = n % 10;
      n /= 10;
    }
    for (j = 1; j <= 19; j++) {
      if (digs[j] != 0) {
        firstnonzero = j;
        break;
      }
    }
    for (j = 0; j <= 4; j++) {
      for (in = 1; in <= L; in++) {
        val = j + nums[in];
        if (val == digs[19]) {
          F[19][j] = in;
          break;
        }
      }
    }
    for (j = 18; j >= firstnonzero; j--) {
      for (in = 0; in <= 4; in++) {
        for (ja = 1; ja <= L; ja++) {
          val = in + nums[ja];
          if (val % 10 == digs[j] && F[j + 1][val / 10] != -1) {
            F[j][in] = ja;
            break;
          }
        }
      }
    }
    if (F[firstnonzero][0] == -1) {
      printf("-1\n");
    } else {
      memset(thenums, 0, sizeof(thenums));
      Restore(firstnonzero, 0);
      for (j = 1; j <= 6; j++) {
        pr = 0;
        for (in = 19; in >= firstnonzero; in--) {
          pr = pr * 10 + thenums[j][in];
        }
        printf("%I64d", pr);
        if (j != 6) printf(" ");
      }
      printf("\n");
    }
  }
  return 0;
}
