#include <bits/stdc++.h>
using namespace std;
struct Node {
  int cnt1, cnt2;
  Node() {}
  Node(int cnt1, int cnt2) : cnt1(cnt1), cnt2(cnt2) {}
};
vector<Node> S[15][15];
char digit[20], ans[7][20];
void prepare() {
  for (int i = 0; i <= 6; ++i)
    for (int j = 0; j <= 6 - i; ++j)
      for (int k = 0; k <= 4; ++k)
        S[(i * 4 + j * 7 + k) % 10][k].push_back(Node(i, j));
}
bool DFS(int p, int d) {
  if (p < 1) return d == 0;
  int v = digit[p] - '0';
  for (vector<Node>::iterator i = S[v][d].begin(); i != S[v][d].end(); ++i)
    if (DFS(p - 1, (i->cnt1 * 4 + i->cnt2 * 7 + d) / 10)) {
      for (int j = 1; j <= i->cnt1; ++j) ans[j][p] = '4';
      for (int j = i->cnt1 + 1; j <= i->cnt1 + i->cnt2; ++j) ans[j][p] = '7';
      for (int j = i->cnt1 + i->cnt2 + 1; j <= 6; ++j) ans[j][p] = '0';
      return true;
    }
  return false;
}
void read() {
  int test;
  for (scanf("%d", &test); test; --test) {
    scanf("%s", digit + 1);
    int n = strlen(digit + 1);
    if (DFS(n, 0) == false)
      printf("-1\n");
    else
      for (int i = 1; i <= 6; ++i) {
        int j = 1;
        for (; j <= n && ans[i][j] == '0'; ++j)
          ;
        if (j <= n) {
          for (; j <= n; ++j) printf("%c", ans[i][j]);
        } else
          printf("0");
        printf("%c", i < 6 ? ' ' : '\n');
      }
  }
}
int main() {
  prepare();
  read();
  return 0;
}
