#include <bits/stdc++.h>
using namespace std;
vector<int> digs;
int dp[20][10];
void init(long long n) {
  digs.clear();
  while (n) {
    digs.push_back(n % 10);
    n /= 10;
  }
  memset(dp, -1, sizeof(dp));
}
int solve(int idx, int carry) {
  if (idx == (int)digs.size())
    return (carry == 0);
  else if (dp[idx][carry] != -1)
    return dp[idx][carry];
  int ret = 0;
  for (int fours = 0; fours <= 6; fours++) {
    for (int seven = 0; seven <= (6 - fours); seven++) {
      int v = 4 * fours + 7 * (seven) + carry;
      int nc = v / 10;
      if (v % 10 != digs[idx]) continue;
      ret |= solve(idx + 1, nc);
    }
  }
  return (dp[idx][carry] = ret);
}
long long pw[100];
vector<int> ans(6, 0);
void trace(int idx, int carry) {
  if (idx == (int)digs.size()) return;
  for (int fours = 0; fours <= 6; fours++) {
    for (int seven = 0; seven <= (6 - fours); seven++) {
      int v = 4 * fours + 7 * seven + carry;
      int nc = v / 10;
      if (v % 10 != digs[idx]) continue;
      if (!solve(idx + 1, nc)) continue;
      for (int i = 0; i < fours; i++) ans[i] += 4 * pw[idx];
      for (int i = fours; i < (fours + seven); i++) ans[i] += 7 * pw[idx];
      trace(idx + 1, nc);
      return;
    }
  }
}
int main() {
  pw[0] = 1;
  for (int i = 1; i < 20; i++) pw[i] = pw[i - 1] * 10;
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    init(n);
    int poss = solve(0, 0);
    if (!poss) {
      cout << "-1\n";
      continue;
    }
    for (auto &i : ans) i = 0;
    trace(0, 0);
    for (auto i : ans) cout << i << " ";
    cout << "\n";
  }
  return 0;
}
