#include <bits/stdc++.h>
using namespace std;
struct cell {
  int q0, q4, q7;
  int vai;
  cell() {}
  cell(int q0, int q4, int q7, int vai) : q0(q0), q4(q4), q7(q7), vai(vai) {}
};
vector<cell> v[20];
int num[20];
int sz;
int foi[20][20], rnd;
long long int ans[10];
bool solve(int d, int r) {
  if (d >= sz && r == 0) return true;
  if (r > num[d]) return false;
  if (foi[d][r] == rnd) return false;
  foi[d][r] = rnd;
  int p = num[d] - r;
  for (int i = 0; i < v[p].size(); i++) {
    if (solve(d + 1, v[p][i].vai)) {
      int q0 = v[p][i].q0;
      int q4 = v[p][i].q4;
      int q7 = v[p][i].q7;
      for (int j = 0; j < 6; j++) {
        if (q0) {
          ans[j] = (ans[j] * 10LL) + 0LL;
          q0--;
        } else if (q4) {
          ans[j] = (ans[j] * 10LL) + 4LL;
          q4--;
        } else {
          ans[j] = (ans[j] * 10LL) + 7LL;
          q7--;
        }
      }
      return true;
    }
  }
}
int main() {
  for (int i = 0; i < 10; i++) v[i].clear();
  for (int i0 = 0; i0 <= 6; i0++)
    for (int i4 = 0; i0 + i4 <= 6; i4++) {
      int i7 = 6 - i0 - i4;
      int x = (4 * i4) + (7 * i7);
      v[x % 10].push_back(cell(i0, i4, i7, x / 10));
    }
  int n;
  scanf(" %d", &n);
  for (int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    sz = 0;
    rnd = i + 1;
    memset(ans, 0LL, sizeof(ans));
    memset(num, 0LL, sizeof(num));
    while (x > 0) {
      num[sz] = x % 10;
      x /= 10;
      sz++;
    }
    if (solve(0, 0)) {
      cout << ans[0];
      for (int i = 1; i < 6; i++) cout << " " << ans[i];
      cout << endl;
    } else {
      printf("-1\n");
    }
  }
  return 0;
}
