#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    string a;
    bool b[21][10] = {1};
    pair<pair<int, int>, pair<int, int> > c[21][10] = {};
    cin >> a;
    reverse(a.begin(), a.end());
    a += "000000000000000000000000";
    for (int i = 0; i <= 19; i++) {
      for (int j = 0; j <= 9; j++)
        if (b[i][j]) {
          for (int k = 0; k <= 6; k++) {
            for (int l = 0; l <= 6 - k; l++) {
              if ((j + k * 4 + l * 7) % 10 == a[i] - '0') {
                b[i + 1][(j + k * 4 + l * 7) / 10] = 1;
                c[i + 1][(j + k * 4 + l * 7) / 10] = {{i, j}, {k, l}};
              }
            }
          }
        }
    }
    if (b[19][0]) {
      int d[20] = {}, e[20] = {}, x = 19, y = 0;
      long long p[20] = {1}, z[6] = {};
      for (int i = 1; i <= 18; i++) p[i] = p[i - 1] * 10;
      while (x) {
        pair<pair<int, int>, pair<int, int> > f = c[x][y];
        x = f.first.first;
        y = f.first.second;
        d[x] = f.second.first;
        e[x] = f.second.second;
      }
      for (int i = 0; i <= 18; i++) {
        for (int j = 0; j < d[i]; j++) z[j] += p[i] * 4;
        for (int j = d[i]; j < d[i] + e[i]; j++) z[j] += p[i] * 7;
      }
      cout << z[0] << ' ' << z[1] << ' ' << z[2] << ' ' << z[3] << ' ' << z[4]
           << ' ' << z[5] << '\n';
    } else
      cout << -1 << '\n';
  }
}
