#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  vector<long long> ten(30, 0);
  ten[0] = 1;
  for (int i = 1; i <= 18; ++i) ten[i] = ten[i - 1] * 10;
  for (; t--;) {
    long long x;
    cin >> x;
    vector<int> digits(25, 0);
    vector<long long> ans(6, 0);
    for (int i = 0; i <= 19; ++i) {
      digits[i] = x % 10;
      x /= 10;
    }
    vector<vector<int> > dp(30, vector<int>(30, 0));
    vector<vector<int> > plist(30, vector<int>(30, 0));
    vector<vector<int> > qlist(30, vector<int>(30, 0));
    dp[20][0] = true;
    for (int i = 19; i >= 0; --i)
      for (int scarry = 0; scarry <= 4; ++scarry)
        for (int p = 0; p <= 6; ++p)
          for (int q = 0; q <= 6 - p; ++q) {
            if ((p * 7 + q * 4 + scarry) % 10 != digits[i]) continue;
            int carry = (p * 7 + q * 4 + scarry) / 10;
            if (dp[i + 1][carry]) {
              dp[i][scarry] = 1;
              plist[i][scarry] = p;
              qlist[i][scarry] = q;
            }
          }
    if (dp[0][0] == 0) {
      cout << "-1\n";
      continue;
    }
    int carry = 0;
    for (int i = 0; i <= 19; ++i) {
      int p = plist[i][carry];
      int q = qlist[i][carry];
      for (int j = 1; j <= p; ++j) ans[j - 1] += ten[i] * 7;
      for (int j = 1; j <= q; ++j) ans[j - 1 + p] += ten[i] * 4;
      carry = (p * 7 + q * 4) / 10;
    }
    for (int j = 0; j < 6; ++j) cout << ans[j] << " ";
    cout << "\n";
  }
  return 0;
}
