#include <bits/stdc++.h>
using namespace std;
long long n, mark[50], dp[50][50], say, d[50], o, x[50], bs, yaz[7];
void ekle(long long is, long long bas) {
  long long a, b;
  for (a = 0; a <= 6; a++) {
    for (b = 0; b <= 6 - a; b++) {
      if (7 * a + 4 * b == is) break;
    }
    if (7 * a + 4 * b == is) break;
  }
  for (long long i = 1; i <= a; i++) yaz[i] += 7 * bas;
  for (long long i = a + 1; i <= a + b; i++) yaz[i] += 4 * bas;
}
long long us(long long a, long long b) {
  long long cev = 1;
  for (long long i = 0; i < b; i++) cev *= a;
  return cev;
}
long long fon(long long k, long long elde) {
  while (elde > 6)
    ;
  if (bs + 2 <= k && elde == 0) return 1;
  if (bs + 2 <= k) return 0;
  if (dp[k][elde] != -1) return dp[k][elde];
  long long t = x[k], yelde = 0;
  if (t < elde) {
    yelde++;
    t = 10 + t - elde;
  } else
    t = t - elde;
  for (long long i = 27; i >= 0; i--)
    if (d[i] % 10 == t)
      if (fon(k + 1, yelde + d[i] / 10)) {
        ekle(d[i], us(10, k - 1));
        return 1;
      }
  return dp[k][elde] = 0;
}
int main() {
  for (long long a = 0; a <= 6; a++)
    for (long long b = 0; b <= 6 - a; b++) mark[7 * a + 4 * b] = 1;
  for (long long i = 0; i <= 42; i++) {
    if (mark[i]) {
      d[say] = i;
      say++;
    }
  }
  long long n;
  cin >> n;
  for (int qqq = 0; qqq < n; qqq++) {
    for (int i = 0; i < 7; i++) yaz[i] = 0;
    for (int i = 0; i < 50; i++)
      for (int j = 0; j < 50; j++) dp[i][j] = -1;
    for (int i = 0; i < 50; i++) x[i] = 0;
    bs = 0;
    cin >> o;
    while (o) {
      x[++bs] = o % 10;
      o = o / 10;
    }
    if (fon(1, 0) == 0) {
      cout << "-1" << endl;
      continue;
    }
    long long kont = 0;
    for (int i = 1; i < 7; i++) {
      kont += yaz[i];
      cout << yaz[i] << " ";
    }
    printf("\n");
  }
  return 0;
}
