#include <bits/stdc++.h>
using namespace std;
int len, a[3] = {0, 4, 7}, c[100][6], d[6], e[20], an[6][20];
bool b[100];
char n[20];
void precalc(int i, int sum) {
  if (i == 6) {
    if (!b[sum]) {
      b[sum] = 1;
      for (int j = 0; j < 6; j++) {
        c[sum][j] = d[j];
      }
    }
    return;
  }
  for (int j = 0; j < 3; j++) {
    d[i] = a[j];
    sum += a[j];
    precalc(i + 1, sum);
    sum = sum - a[j];
  }
}
bool ans(int i, int carry) {
  int f;
  if (i < 0) {
    if (carry == 0)
      return 1;
    else
      return 0;
  } else {
    int k = n[i] - '0';
    for (int j = 0; j < 100; j++) {
      f = j + carry;
      if (f % 10 == k && b[j]) {
        e[i] = j;
        if (ans(i - 1, f / 10)) return 1;
      }
    }
    return 0;
  }
}
int main() {
  precalc(0, 0);
  int tot;
  scanf("%d", &tot);
  long long int an;
  while (tot--) {
    scanf("%s", n);
    len = strlen(n);
    int res = ans(len - 1, 0);
    if (!res)
      printf("-1\n");
    else {
      for (int i = 0; i < 6; i++) {
        an = 0;
        for (int j = 0; j < len; j++) {
          an = 10 * an + (long long int)(c[e[j]][i]);
        }
        cout << an << " ";
      }
      cout << endl;
    }
  }
  return 0;
}
