#include <bits/stdc++.h>
struct node {
  int val, a, b;
  node(int i = 0, int j = 0, int k = 0) : a(i), b(j), val(k) {}
};
std::vector<node> the[10];
long long ten[19];
long long ans[6];
bool dfs(long long now, int bit) {
  if (!now) return true;
  if (now < 0ll) return false;
  int v = now % 10;
  for (int i(0); i < the[v].size(); ++i) {
    int a(the[v][i].a), b(a + the[v][i].b), j(0);
    for (; j < a; ++j) ans[j] = ans[j] % ten[bit] + 4ll * ten[bit];
    for (; j < b; ++j) ans[j] = ans[j] % ten[bit] + 7ll * ten[bit];
    for (; j < 6; ++j) ans[j] %= ten[bit];
    if (dfs((now - the[v][i].val) / 10, bit + 1)) return true;
  }
  return false;
}
int T;
int i, j, k;
long long n;
int main() {
  for (i = 0; i <= 6; ++i)
    for (j = 0; i + j <= 6; ++j) {
      k = i * 4 + j * 7;
      the[k % 10].push_back(node(i, j, k));
    }
  ten[0] = 1ll;
  for (i = 1; i < 19; ++i) ten[i] = ten[i - 1] * 10ll;
  scanf("%d", &T);
  while (T--) {
    scanf("%I64d", &n);
    if (dfs(n, 0))
      for (i = 0; i < 6; ++i) printf("%I64d%c", ans[i], " \n"[i == 5]);
    else
      puts("-1");
  }
  return 0;
}
