#include <bits/stdc++.h>
using namespace std;
int T;
bool f[20][5];
long long n, m, a[20], ans[20][5][7], b[7], ten[18];
void dfs(int i, int t, int S) {
  int k, p;
  if (t > 6) {
    p = a[i] - S % 10;
    if (p < 0) p += 10;
    if (p <= 4 && f[i - 1][p]) {
      f[i][(S + p) / 10] = 1;
      for (k = 1; k <= 6; k++)
        ans[i][(S + p) / 10][k] = ans[i - 1][p][k] + ten[i - 1] * b[k];
    }
    return;
  }
  b[t] = 0, dfs(i, t + 1, S);
  b[t] = 7, dfs(i, t + 1, S + 7);
  b[t] = 4, dfs(i, t + 1, S + 4);
  b[t] = 0;
}
void work() {
  int i;
  scanf("%I64d", &n), m = 0;
  while (n) a[++m] = n % 10, n /= 10;
  memset(f, 0, sizeof(f));
  f[0][0] = 1;
  for (i = 1; i <= m; i++) dfs(i, 1, 0);
  if (!f[m][0])
    printf("-1\n");
  else {
    for (i = 1; i <= 6; i++)
      printf(
          "%I64d"
          " ",
          ans[m][0][i]);
    printf("\n");
  }
}
int main() {
  int i;
  cin >> T;
  ten[0] = 1;
  for (i = 1; i <= 19; i++) ten[i] = ten[i - 1] * 10;
  while (T--) work();
  return 0;
}
