#include <bits/stdc++.h>
using namespace std;
const int l = 4;
int num[256], cnt, ncnt;
int get[10000];
long long pow4[18], pow7[18];
long long ans[6];
int main() {
  pow4[0] = 4LL;
  pow7[0] = 7LL;
  for (int i = 1; i < 18; i++) {
    pow4[i] = pow4[i - 1] * 10LL;
    pow7[i] = pow7[i - 1] * 10LL;
  }
  num[0] = 0;
  cnt = 1;
  for (int i = 0; i < l; i++) {
    int ncnt = cnt;
    for (int j = 0; j < cnt; j++) {
      num[ncnt++] = num[j] + pow4[i];
      num[ncnt++] = num[j] + pow7[i];
    }
    cnt = ncnt;
  }
  memset(get, -1, sizeof(get));
  get[0] = 0;
  for (int v = 0; v < 6; v++)
    for (int j = 9999; j >= 0; j--)
      if (get[j] == -1)
        for (int i = 1; i < cnt; i++)
          if (j - num[i] >= 0 && get[j - num[i]] != -1) get[j] = num[i];
  int T;
  scanf("%d", &T);
  while (T--) {
    long long n;
    scanf("%lld", &n);
    if (n < 10000LL) {
      int nn = int(n);
      if (get[nn] == -1)
        printf("-1\n");
      else {
        for (int j = 0; j < 6; j++) {
          printf(" %d" + !j, get[nn]);
          nn -= get[nn];
        }
        printf("\n");
      }
    } else {
      for (int i = 0; i < 6; i++) ans[i] = 0LL;
      int st = 0;
      for (int j = 17; j >= 3; j--) {
        for (int i = 0; i < 6; i++) {
          if (n > pow7[j]) {
            n -= pow7[j];
            ans[i] += pow7[j];
            st = i + 1;
          } else if (n > pow4[j]) {
            n -= pow4[j];
            ans[i] += pow4[j];
            st = i + 1;
          }
        }
      }
      assert(n < 10000LL);
      int nn = int(n);
      for (int j = 0; j < 6; j++) {
        ans[(j + st) % 6] += long long(get[nn]);
        nn -= get[nn];
      }
      for (int j = 0; j < 6; j++) printf(" %lld" + !j, ans[j]);
      printf("\n");
    }
  }
  return 0;
}
