#include <bits/stdc++.h>
using namespace std;
int TC;
long long N;
int resn, resx;
int A[25][2];
long long Res[25];
int F7[] = {0, 3, 6, 9, 2, 5, 8, 1, 4, 7};
void init() {
  resn = 0;
  resx = 0;
  memset(A, 0, sizeof A);
  memset(Res, 0, sizeof Res);
}
bool chk(int c, long long n, int x) {
  if (n == 0) {
    resx = x;
    return true;
  }
  for (A[x][0] = 9; A[x][0] >= 0; A[x][0]--) {
    A[x][1] = F7[(n - A[x][0] * 4 + 10000) % 10];
    if (A[x][0] + A[x][1] > c) continue;
    long long carry = (A[x][0] * 4 + A[x][1] * 7) / 10;
    if (carry > n / 10) continue;
    if (chk(A[x][0] + A[x][1], n / 10 - carry, x + 1)) return true;
  }
  return false;
}
bool solve() {
  init();
  bool exist = false;
  for (resn = 1; resn <= 6 && !exist; resn++) {
    resx = -1;
    if (chk(resn, N, 0)) {
      exist = true;
      break;
    }
  }
  if (!exist) return false;
  long long pow10 = 1;
  int s = 1;
  for (int i = 0; i < resx; i++) {
    int j;
    for (j = s; j < s + A[i][0]; j++) Res[j] += pow10 * 4;
    for (j = s + A[i][0]; j <= resn; j++) Res[j] += pow10 * 7;
    s += A[i][0] + A[i][1];
    s -= A[i + 1][0] + A[i + 1][1];
    pow10 *= 10;
  }
  return true;
}
int main() {
  freopen("E.in", "r", stdin);
  freopen("E.out", "w", stdout);
  int i, j, k;
  scanf("%d", &TC);
  while (TC--) {
    scanf("%I64d", &N);
    if (solve()) {
      long long sum = 0;
      for (i = 1; i <= resn; i++) printf("%I64d ", Res[i]), sum += Res[i];
      for (i = resn + 1; i <= 6; i++) printf("0 ");
      puts("");
      if (sum != N) assert(0);
    } else {
      puts("-1");
    }
  }
  return 0;
}
