#include <bits/stdc++.h>
using namespace std;
const int maxl = 128;
const int val[] = {0, 4, 7};
const int st[] = {1, 1 << 4, 1 << 8};
int dp[18][10], pre[18][10], t;
char str[maxl];
long long res[6];
void dfs(int pos, int deep, int sum, int state) {
  if (deep == 6) {
    for (int i = 0; i < 10; ++i) {
      if (dp[pos][i] == -1) continue;
      int tsum = sum + i;
      if (tsum % 10 != str[pos] - '0') continue;
      tsum /= 10;
      dp[pos + 1][tsum] = state;
      pre[pos + 1][tsum] = i;
    }
    return;
  }
  for (int i = 0; i < 3; ++i) {
    dfs(pos, deep + 1, sum + val[i], state + st[i]);
  }
}
void GetResult(int pos, int s, long long p10) {
  if (pos == 0) return;
  int ret = dp[pos][s] >> 4;
  int offset = ret & 0xf;
  for (int i = 0; i < offset; ++i) res[i] += p10 * 4;
  ret >>= 4;
  for (int i = 0; i < (ret & 0xf); ++i) res[i + offset] += p10 * 7;
  GetResult(pos - 1, pre[pos][s], p10 / 10);
}
int main() {
  cin >> t;
  for (int nt = 0; nt < t; ++nt) {
    scanf("%s", str);
    int len = strlen(str);
    reverse(str, str + len);
    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    for (int i = 0; i < len; ++i) {
      dfs(i, 0, 0, 0);
    }
    if (dp[len][0] == -1) {
      puts("-1");
    } else {
      memset(res, 0, sizeof(res));
      long long p10 = 1;
      for (int i = 0; i < len; ++i) p10 *= 10;
      GetResult(len, 0, p10 / 10);
      for (int i = 0; i < 6; ++i) {
        if (i) putchar(' ');
        printf("%I64d", res[i]);
      }
      puts("");
    }
  }
  return 0;
}
