#include <bits/stdc++.h>
using namespace std;
bool first[22][11];
int fj[22][11], fx[22][11], fy[22][11], a[20], n;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    memset(first, 0, sizeof(first));
    first[0][0] = 1;
    scanf("%d", &n);
    int l = 0;
    while (n) a[l++] = n % 10, n /= 10;
    for (int i = 0; i < l; i++) {
      for (int j = 0; j < 10; j++) {
        if (first[i][j]) {
          for (int x = 0; x <= 6; x++)
            for (int y = 0; y + x <= 6; y++) {
              int nj = (x * 4 + y * 7 + j);
              if (nj % 10 == a[i]) {
                nj /= 10;
                first[i + 1][nj] = 1;
                fj[i + 1][nj] = j;
                fx[i + 1][nj] = x;
                fy[i + 1][nj] = y;
              }
            }
        }
      }
    }
    long long res[6] = {0};
    if (first[l][0]) {
      for (int i = l, j = 0; i > 0; i--) {
        for (int p = 0; p < 6; p++) res[p] *= 10;
        int x = fx[i][j];
        int y = fy[i][j];
        for (int p = 0; p < x; p++) res[p] += 4;
        for (int p = x; p < x + y; p++) res[p] += 7;
        j = fj[i][j];
      }
      for (int i = 0; i < 6; i++) printf("%I64d ", res[i]);
      printf("\n");
    } else
      puts("-1");
  }
  return 0;
}
