#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;

ll construct(ll recipe) {
  static const char d[] = "047";

  string s;
  do {
    s += d[recipe%3];
  } while (recipe /= 3);

  reverse(s.begin(), s.end());

  ll x = 0;
  for (char c : s)
    x *= 10, x += c-'0';

  return x;
}

bool check(ll x) {
  do {
    if ((x % 10 != 0) && (x % 10 != 4) && (x % 10 != 7)) return false;
  } while (x /= 10);
  return true;
}

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

  ll mxv = 1;
  for (int i = 0; i < 18; ++i)
    mxv *= 3;

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

    ll n; cin >> n;
    ll on = n;

    vector<ll> ans;

    while (ans.size() < 6) {
      ll lo = 0, hi = mxv;

      while (lo != hi) {
        ll ce = lo + (hi-lo+1)/2;
        ll x = construct(ce);

        if (x > n) hi = ce-1;
        else lo = ce;
      }

      ans.push_back(construct(lo));
      n -= ans.back();

    }

    if (n == 0) {
      for (ll x : ans) cout << x << ' ';
      cout << '\n';
    } else {

      if (on%6 == 0 && check(on/6)) {
        for (int i = 0; i < 6; ++i)
          cout << on/6 << ' ';
        cout << '\n';
      } else {
        cout << "-1\n";
      }
    }

  }
}
