#include <bits/stdc++.h>
using namespace std;
vector<int> save[12][12][12];
char in[100];
int vis[21][12];
int mem[21][12];
int get(int pos, int carry) {
  if (pos == -1) {
    if (carry == 0)
      return 1;
    else
      return 0;
  }
  if (vis[pos][carry]) return mem[pos][carry];
  int ret = 0;
  int i;
  for (i = 0; i <= 9; i++) {
    if (save[i][in[pos] - '0'][carry].size()) {
      ret |= get(pos - 1, i);
    }
  }
  vis[pos][carry] = 1;
  mem[pos][carry] = ret;
  return ret;
}
vector<vector<int> > ans;
void rec(int pos, int carry) {
  if (pos == -1) return;
  int i, ret = 0;
  for (i = 0; i <= 9; i++) {
    if (save[i][in[pos] - '0'][carry].size()) {
      if (get(pos - 1, i)) {
        ans.push_back(save[i][in[pos] - '0'][carry]);
        rec(pos - 1, i);
        break;
      }
    }
  }
}
int I[60];
void dfs(int pos, int sum, int bc) {
  if (pos == 6) {
    if (save[sum / 10][sum % 10][bc].size() == 0) {
      vector<int> vc;
      int i;
      for (i = 0; i < 6; i++) {
        vc.push_back(I[i]);
      }
      save[sum / 10][sum % 10][bc] = vc;
    }
    return;
  }
  I[pos] = 0;
  dfs(pos + 1, sum, bc);
  I[pos] = 4;
  dfs(pos + 1, sum + 4, bc);
  I[pos] = 7;
  dfs(pos + 1, sum + 7, bc);
}
void PRE() {
  int i, j;
  for (i = 0; i <= 6; i++) {
    dfs(0, i, i);
  }
}
int main() {
  int T, i, j, k, n;
  PRE();
  scanf("%d", &T);
  int out[10];
  while (T--) {
    scanf("%s", in);
    n = strlen(in);
    memset(vis, 0, sizeof(vis));
    if (get(n - 1, 0)) {
      ans.clear();
      rec(n - 1, 0);
      reverse(ans.begin(), ans.end());
      for (i = 0; i < 6; i++) out[i] = 0;
      for (i = 0; i < ans.size(); i++) {
        for (j = 0; j < 6; j++) {
          out[j] *= 10;
          out[j] += ans[i][j];
        }
      }
      for (i = 0; i < 6; i++) {
        if (i) printf(" ");
        printf("%d", out[i]);
      }
      printf("\n");
    } else {
      printf("-1\n");
    }
  }
  return 0;
}
