#include <bits/stdc++.h>
using namespace std;
map<long long, pair<int, int> > nxt;
pair<int, int> memo(const long long n) {
  if (n == 0LL) {
    return {0, 0};
  }
  auto it = nxt.find(n);
  if (it != nxt.end()) {
    return it->second;
  }
  pair<int, int> &ans = nxt[n];
  for (int x = 0; x <= 6; x++) {
    for (int y = 0; x + y <= 6 && x * 4 + y * 7 <= n; y++) {
      if ((x * 4 + y * 7) % 10 == n % 10 &&
          memo((n - x * 4 - y * 7) / 10) != make_pair(-1, -1)) {
        return ans = {x, y};
      }
    }
  }
  return ans = {-1, -1};
}
void testCase(long long n) {
  nxt.clear();
  if (memo(n) == make_pair(-1, -1)) {
    printf("-1\n");
    return;
  }
  long long ans[] = {0, 0, 0, 0, 0, 0};
  long long pot = 1;
  auto pr = nxt[n];
  while (pr.first || pr.second) {
    int a = pr.first;
    int b = pr.second;
    for (int i = 0; i < a; i++) {
      ans[i] += pot * 4;
    }
    for (int i = 0; i < b; i++) {
      ans[i + a] += pot * 7;
    }
    n = (n - a * 4 - b * 7) / 10;
    pr = nxt[n];
    pot *= 10;
  }
  for (int i = 0; i < 6; i++) printf("%lld ", ans[i]);
  printf("\n");
}
int main() {
  int tc;
  long long a;
  scanf("%d", &tc);
  for (int i = 0; i < tc; i++) {
    scanf("%lld", &a);
    testCase(a);
  }
}
