#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int opt[N][N], pre[N][N][3], a[N], len;
long long ans[N];
int main() {
  int T;
  cin >> T;
  while (T--) {
    long long n;
    cin >> n;
    len = 0;
    for (; n; n /= 10) a[++len] = n % 10;
    memset(opt, 0, sizeof opt);
    memset(ans, 0, sizeof ans);
    opt[0][0] = 1;
    for (int i = 0; i < len; ++i)
      for (int j = 0; j < 5; ++j)
        if (opt[i][j])
          for (int x = 0; x <= 6; ++x)
            for (int y = 0; x + y <= 6; ++y) {
              int sum = j + x * 4 + y * 7, nj = sum / 10;
              if (sum % 10 == a[i + 1])
                opt[i + 1][nj] = 1, pre[i + 1][nj][0] = j,
                        pre[i + 1][nj][1] = x, pre[i + 1][nj][2] = y;
            }
    if (opt[len][0]) {
      for (int i = len, j = 0; i > 0; --i) {
        int x = pre[i][j][1], y = pre[i][j][2];
        for (int k = 0; k < x; ++k) ans[k] = ans[k] * 10 + 4;
        for (int k = x; k < x + y; ++k) ans[k] = ans[k] * 10 + 7;
        for (int k = x + y; k < 6; ++k) ans[k] = ans[k] * 10;
        j = pre[i][j][0];
      }
      for (int k = 0; k < 6; ++k) printf(k == 5 ? "%I64d\n" : "%I64d ", ans[k]);
    } else
      puts("-1");
  }
  return 0;
}
