#include <bits/stdc++.h>
using namespace std;
struct State {
  unsigned long long have[6];
  int ok;
} dp[20][20];
unsigned long long T, N, M, num, ps, ng, cl;
unsigned long long ten[20];
void fail() { printf("no solution\n"); }
void Work(State& to, State fr, int p1, int p2, int x) {
  int i;
  to.ok = cl;
  for (i = 0; i < p1; i++) to.have[i] = fr.have[i] + 7LL * ten[x];
  for (i = p1; i < p1 + p2; i++) to.have[i] = fr.have[i] + 4LL * ten[x];
  for (i = p1 + p2; i <= 5; i++) to.have[i] = fr.have[i];
}
void Dfs(int x, int ad) {
  int i, j, t, s;
  unsigned long long sum, tmp;
  State fr = dp[x][ad];
  dp[x][ad].ok = cl;
  if (x == M) return;
  for (i = 0; i <= ps; i++)
    for (t = 0; t <= ps - i; t++) {
      sum = 7 * i + 4 * t + ad;
      if ((sum + 100) % 10 == N / ten[x] % 10) {
        tmp = sum - (sum + 100) % 10;
        tmp /= 10;
        State& to = dp[x + 1][tmp];
        if (to.ok != cl) {
          Work(to, fr, i, j, x);
          Dfs(x + 1, tmp);
        }
      }
    }
}
int main() {
  unsigned long long i, j, t, x;
  scanf("%I64d", &T);
  for (i = 1, ten[0] = 1; i <= 18; i++) ten[i] = ten[i - 1] * 10;
  while (T--) {
    scanf("%I64d", &N);
    cl++, M = 18;
    if (N == 0) {
      printf("0 0 0 0 0 0\n");
      continue;
    }
    for (ps = 6; ps <= 6; ps++) {
      ng = 6 - ps;
      memset(dp[0][0].have, 0, sizeof(unsigned long long) * 6);
      Dfs(0, 0);
      if (dp[M][0].ok == cl) break;
    }
    if (dp[M][0].ok != cl)
      printf("-1");
    else
      for (i = 0; i < 6; i++) printf("%I64d ", dp[M][0].have[i]);
    printf("\n");
  }
  return 0;
}
