#include <bits/stdc++.h>
using namespace std;
int flag, f[1010][1010], i, top, stack[1010];
string ans[100010];
long long g[1010], n;
void dfs(int x, int y) {
  if (f[y / 10][y % 10]) return;
  f[y / 10][y % 10] = 1;
  if (x > 6) return;
  ans[y + 4] = ans[y];
  ans[y + 4][x - 1] = '4';
  dfs(x + 1, y + 4);
  ans[y + 7] = ans[y];
  ans[y + 7][x - 1] = '7';
  dfs(x + 1, y + 7);
}
void deal(long long n, int z) {
  int i, j, w;
  long long q, p;
  if ((n == 0) && (z == 0)) {
    q = 1;
    for (i = 1; i <= top; i++) {
      for (j = 0; j <= 5; j++) g[j] = g[j] + (ans[stack[i]][j] - 48) * q;
      q = q * 10;
    }
    flag = 1;
  }
  if (n == 0) return;
  p = (n % 10 - z + 10);
  if (p < 10)
    w = 1;
  else
    w = 0;
  p = p % 10;
  for (i = w; i <= 4; i++)
    if (f[i][p]) {
      top++;
      stack[top] = i * 10 + p;
      deal(n / 10, i);
      if (flag) return;
      top--;
    }
}
int main() {
  for (i = 0; i <= 42; i++) ans[i] = "000000";
  dfs(1, 0);
  int test;
  cin >> test;
  while (test) {
    test--;
    flag = 0;
    top = 0;
    for (i = 0; i < 6; i++) g[i] = 0;
    cin >> n;
    deal(n, 0);
    if (flag)
      for (i = 0; i <= 5; i++) cout << g[i] << " ";
    else
      cout << "-1";
    cout << endl;
  }
}
