#include <bits/stdc++.h>
using namespace std;
bool dp[20][15];
int A[] = {0, 4, 7};
int B[15];
string n;
bool rec(int idx, int rem) {
  if (idx == n.size()) return !rem;
  bool &temp = dp[idx][rem];
  if (temp) return false;
  temp = true;
  for (int a = 0; a < 3; ++a)
    for (int b = 0; b < 3; ++b)
      for (int c = 0; c < 3; ++c)
        for (int d = 0; d < 3; ++d)
          for (int e = 0; e < 3; ++e)
            for (int f = 0; f < 3; ++f) {
              int k = rem + A[a] + A[b] + A[c] + A[d] + A[e] + A[f];
              if (k % 10 == n[idx] - '0')
                if (rec(idx + 1, k / 10)) {
                  B[0] = B[0] * 10 + A[a];
                  B[1] = B[1] * 10 + A[b];
                  B[2] = B[2] * 10 + A[c];
                  B[3] = B[3] * 10 + A[d];
                  B[4] = B[4] * 10 + A[e];
                  B[5] = B[5] * 10 + A[f];
                  return true;
                }
            }
  return false;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    reverse(n.begin(), n.end());
    if (!rec(0, 0))
      cout << "-1";
    else
      for (int i = 0; i < 6; ++i) cout << B[i] << " ";
    cout << "\n";
    memset(B, 0, sizeof(B));
    memset(dp, 0, sizeof(dp));
  }
  return 0;
}
