#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int dp[N][N];
string s;
void solve() {
  int q;
  cin >> q;
  while (q--) {
    cin >> s;
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        dp[i][j] = 0;
      }
    }
    dp[s.size()][0] = 1;
    for (int i = s.size() - 1; i > -1; --i) {
      for (int prev = 0; prev < 6; ++prev) {
        if (dp[i + 1][prev] == 0) continue;
        for (int x = 0; x <= 6; ++x) {
          for (int y = 0; y <= 6 - x; ++y) {
            int c = 4 * x + 7 * y + prev;
            if (c % 10 == s[i] - '0') {
              dp[i][c / 10] = 1;
            }
          }
        }
      }
    }
    if (dp[0][0] == 1) {
      string ans[6] = {"", "", "", "", "", ""};
      int cur = 0;
      for (int i = 0; i < s.size(); ++i) {
        for (int prev = 0; prev < 6; ++prev) {
          if (dp[i + 1][prev] == 0) continue;
          for (int x = 0; x <= 6; ++x) {
            for (int y = 0; y <= 6 - x; ++y) {
              int c = 4 * x + 7 * y + prev;
              if (c % 10 == s[i] - '0' && c / 10 == cur) {
                for (int v = 0; v < x; ++v) ans[v].push_back('4');
                for (int v = x; v < x + y; ++v) ans[v].push_back('7');
                cur = prev;
                goto next;
              }
            }
          }
        }
      next:;
      }
      for (int i = 0; i < 6; ++i) {
        if (ans[i].size() == 0) ans[i] = "0";
        cout << ans[i] << ' ';
      }
    } else {
      cout << -1;
    }
    cout << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
