#include <bits/stdc++.h>
using namespace std;
int move[8][2] = {{-1, 0}, {0, 1}, {1, 0},  {0, -1},
                  {-1, 1}, {1, 1}, {1, -1}, {-1, -1}};
char ch[25];
int arr[6], num[3] = {0, 4, 7}, len;
bool vis[20][10];
struct Sum {
  int a[6];
  bool vis;
} s[50];
void dfsInit(int depth, int sum) {
  if (depth >= 6) {
    for (int i = 0; i < 6; i++) s[sum].a[i] = arr[i];
    s[sum].vis = 1;
    return;
  }
  for (int j = 0; j < 3; j++) {
    arr[depth] = num[j];
    dfsInit(depth + 1, sum + num[j]);
  }
}
long long ans[6];
bool flag;
void dfsans(int i, int jw) {
  if (i < 0) {
    if (jw == 0) flag = 1;
    return;
  }
  int j, f, t, k = ch[i] - '0';
  if (jw > k || vis[i][jw]) return;
  for (j = 0; j < 5; ++j) {
    t = j * 10 + k - jw;
    if (s[t].vis) {
      dfsans(i - 1, j);
      if (flag) {
        for (f = 0; f < 6; ++f) ans[f] = ans[f] * 10 + s[t].a[f];
        return;
      }
    }
  }
  vis[i][jw] = 1;
}
int main() {
  int t;
  dfsInit(0, 0);
  scanf("%d", &t);
  while (t--) {
    memset(vis, 0, sizeof(vis));
    memset(ans, 0, sizeof(ans));
    scanf("%s", ch);
    flag = 0;
    dfsans(strlen(ch) - 1, 0);
    if (flag)
      for (int i = 0; i < 6; i++)
        printf("%I64d%c", ans[i], i == 5 ? '\n' : ' ');
    else
      puts("-1");
  }
  return 0;
}
