#include <bits/stdc++.h>
using namespace std;
vector<long long int> d;
long long int memo[20][40];
vector<pair<long long int, long long int> > v[10];
pair<long long int, long long int> ans[40];
bool dp(long long int pos, long long int carry) {
  if (pos == d.size()) {
    if (carry == 0)
      return 1;
    else
      return 0;
  }
  long long int req = d[pos] - carry;
  if (memo[pos][carry] != -1) {
    return memo[pos][carry];
  }
  if (req < 0) {
    req += 10;
  }
  long long int n;
  for (auto x : v[req]) {
    n = x.first * 4 + x.second * 7;
    if (dp(pos + 1, n / 10)) {
      ans[pos] = x;
      return 1;
    }
  }
  return 0;
}
long long int pw[20];
int main() {
  pw[0] = 1;
  for (int i = 1; i <= 18; i++) {
    pw[i] = 10 * pw[i - 1];
  }
  long long int n, q;
  cin >> q;
  for (int i = 0; i <= 6; i++) {
    for (int j = 0; j <= 6; j++) {
      if (i + j <= 6) {
        v[(4 * i + 7 * j) % 10].emplace_back(make_pair(i, j));
      }
    }
  }
  while (q--) {
    d.clear();
    cin >> n;
    while (n > 0) {
      d.emplace_back(n % 10);
      n /= 10;
    }
    for (int i = 0; i < 20; i++) {
      for (int j = 0; j < 40; j++) {
        memo[i][j] = -1;
      }
    }
    if (!dp(0, 0)) {
      cout << -1 << "\n";
      continue;
    }
    long long int j;
    long long int p[6] = {0};
    for (int i = 0; i < d.size(); i++) {
      j = 0;
      while (ans[i].first > 0) {
        p[j] += pw[i] * 4;
        j++;
        ans[i].first--;
      }
      while (ans[i].second > 0) {
        p[j] += pw[i] * 7;
        j++;
        ans[i].second--;
      }
    }
    for (int i = 0; i < 6; i++) cout << p[i] << " ";
    cout << "\n";
  }
}
