#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ar array

using namespace std;
using namespace __gnu_pbds;
using ll = long long;

vector<vector<int>> can(42+1);

gp_hash_table<ll, int> memo;

int solve(ll x) {
  if (x <= 42 && can[x].size()) return (int)x;

  auto it = memo.find(x);
  if (it != memo.end()) return it->second;

  int last = int(x%10);

  for (int p = 0; p <= 4; ++p) {
    int v = p*10 + last;
    if (v <= 42 && x-v >= 0) {
      if (can[v].size()) {
        int prv = solve((x - v)/10);
        if (prv != -1) {
          memo[x] = v;
          return v;
        }
      }
    }
  }

  memo[x] = -1;
  return -1;
}

int main() {
  cin.tie(0)->sync_with_stdio(0);

  int recipe = 0, s;
  do {

    vector<int> here;

    int r = recipe;
    s = 0;
    do {
      int d = "047"[r%3]-'0';
      here.push_back(d);
      s += d;
    } while (r /= 3);
    ++recipe;

    while (here.size() < 6) here.push_back(0);

    sort(here.begin(), here.end());
    can[s] = move(here);
  } while (s != 42);

  for (int x = 0; x <= 42; ++x) {
    cerr << x << ": ";
    for (auto y : can[x])
      cerr << y << ' ';
    cerr << '\n';
  }
  cerr << '\n';

  int T; cin >> T; while (T--) {
    
    ll n; cin >> n;

    auto res = solve(n);

    if (res == -1) {
      cout << "-1\n";
      continue;
    }

    vector<string> ans(6);

    while (n != 0) {
      for (int i = 0; i < 6; ++i) {
        ans[i] += can[res][i]+'0';
      }
      n -= res;
      n /= 10;
      res = solve(n);
    }

    for (string s : ans) {
      reverse(s.begin(), s.end());
      cout << s << ' ';
    }
    cout << '\n';

  }

}
