#include <bits/stdc++.h>
using namespace std;
template <class T>
T __sqr(const T x) {
  return x * x;
}
template <class T, class X>
inline T __pow(T a, X y) {
  T z = 1;
  for (int i = 1; i <= y; i++) {
    z *= a;
  }
  return z;
}
template <class T>
inline T gcd(T a, T b) {
  a = abs(a);
  b = abs(b);
  if (!b) return a;
  return __gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / __gcd(a, b)) * b;
}
inline bool ispow2(int x) { return (x != 0 && (x & (x - 1)) == 0); }
template <class T>
void UpdateMin(T &x, T y) {
  if (y < x) {
    x = y;
  }
}
template <class T>
void UpdateMax(T &x, T y) {
  if (x < y) {
    x = y;
  }
}
template <class T, class X, class Y>
inline T bigmod(T n, X m, Y mod) {
  unsigned long long ret = 1, a = n % mod;
  while (m) {
    if (m & 1) ret = (ret * a) % mod;
    m >>= 1;
    a = (a * a) % mod;
  }
  ret %= mod;
  return (T)ret;
}
template <class T, class Y>
inline T modinv(T n, Y mod) {
  return bigmod(n, mod - 2, mod);
}
template <class T, class X>
int getbit(T s, X i) {
  return (s >> i) & 1;
}
template <class T, class X>
T onbit(T s, X i) {
  return s | (T(1) << i);
}
template <class T, class X>
T offbit(T s, X i) {
  return s & (~(T(1) << i));
}
template <class T>
inline void read(T &n) {
  char c;
  for (c = getchar(); !(c >= '0' && c <= '9'); c = getchar())
    ;
  n = c - '0';
  for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) n = n * 10 + c - '0';
}
void extended_euclid(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1, y = 0;
    return;
  }
  long long first, second;
  extended_euclid(b, a % b, first, second);
  x = second;
  y = first - (a / b) * second;
}
pair<long long, pair<long long, long long> > extendedEuclid(long long a,
                                                            long long b) {
  long long x = 1, y = 0;
  long long xLast = 0, yLast = 1;
  long long q, r, m, n;
  while (a != 0) {
    q = b / a;
    r = b % a;
    m = xLast - q * x;
    n = yLast - q * y;
    xLast = x, yLast = y;
    x = m, y = n;
    b = a, a = r;
  }
  return make_pair(b, make_pair(xLast, yLast));
}
const long long mod[] = {0,          1000000007, 1000000009,
                         1000000021, 1000000033, 1000000097,
                         1000000093, 1000000097, 1000000103};
const long long base[] = {0,       1000003, 1000033, 1000037, 1000039,
                          1000081, 1000099, 1000117, 1000121};
int vis[3][3][3][3][3][3];
vector<int> v[15];
int a[] = {0, 4, 7};
int b[7];
void precal() {
  for (int i = 0; i <= 2; i++) {
    for (int j = 0; j <= 2; j++) {
      for (int k = 0; k <= 2; k++) {
        for (int l = 0; l <= 2; l++) {
          for (int m = 0; m <= 2; m++) {
            for (int n = 0; n <= 2; n++) {
              int tot = a[i] + a[j] + a[k] + a[l] + a[m] + a[n];
              b[0] = i, b[1] = j, b[2] = k, b[3] = l, b[4] = m, b[5] = n;
              sort(b, b + 6);
              if (vis[b[0]][b[1]][b[2]][b[3]][b[4]][b[5]]) {
                continue;
              }
              vis[b[0]][b[1]][b[2]][b[3]][b[4]][b[5]] = 1;
              int d = tot % 10;
              int carry = tot / 10;
              v[d].push_back(carry);
              v[d].push_back(b[0]);
              v[d].push_back(b[1]);
              v[d].push_back(b[2]);
              v[d].push_back(b[3]);
              v[d].push_back(b[4]);
              v[d].push_back(b[5]);
            }
          }
        }
      }
    }
  }
}
long long num[20];
int func(long long x, int carry) {
  if (0 <= x && x <= 9) {
    if (x == carry) return 1;
  }
  if (x == 0) return 0;
  int d = (x % 10) - carry;
  if (d < 0) d = 10 - d;
  int len = v[d].size();
  long long nxt = x / 10;
  for (int i = 0; i < len; i += 7) {
    if (func(nxt, v[d][i])) {
      int p = 1;
      for (int j = i + 1; j <= i + 6; j++) {
        num[p] = num[p] * 10 + a[v[d][j]];
        p++;
      }
      return 1;
    }
  }
  return 0;
}
int main() {
  precal();
  int ts;
  long long n;
  scanf("%d", &ts);
  while (ts--) {
    scanf("%lld", &n);
    memset(num, 0, sizeof num);
    if (func(n, 0)) {
      for (int i = 1; i <= 6; i++) {
        printf("%lld%c", num[i], i == 6 ? '\n' : ' ');
      }
    } else
      puts("-1");
  }
  return 0;
}
