#include <bits/stdc++.h>
using namespace std;
bool ok[20][10];
vector<int> n4s[20][10];
vector<int> n7s[20][10];
long long res[6];
int main() {
  int T;
  cin >> T;
  for (; T; T--) {
    long long N;
    cin >> N;
    for (int i = (0); i < (20); i++)
      for (int o = (0); o < (10); o++) ok[i][o] = false;
    ok[0][0] = true;
    int rn = N;
    for (int i = (0); i < (19); i++) {
      for (int off = (0); off < (10); off++) {
        if (!ok[i][off]) continue;
        for (int n4 = 0; n4 <= 6; n4++) {
          for (int n7 = 0; n4 + n7 <= 6; n7++) {
            if ((off + 4 * n4 + 7 * n7) % 10 != rn % 10) continue;
            int newoff = (off + 4 * n4 + 7 * n7) / 10;
            if (!ok[i + 1][newoff]) {
              ok[i + 1][newoff] = true;
              n4s[i + 1][newoff] = n4s[i][off];
              n7s[i + 1][newoff] = n7s[i][off];
              n4s[i + 1][newoff].push_back(n4);
              n7s[i + 1][newoff].push_back(n7);
            }
          }
        }
      }
      rn /= 10;
    }
    if (ok[19][0]) {
      for (int i = (0); i < (6); i++) res[i] = 0;
      long long e = 1;
      for (int i = (0); i < (19); i++) {
        for (int s = (0); s < (n4s[19][0][i]); s++) res[s] += 4 * e;
        for (int s = (0); s < (n7s[19][0][i]); s++)
          res[s + n4s[19][0][i]] += 7 * e;
        e *= 10;
      }
      for (int i = (0); i < (6); i++) {
        if (i) cout << " ";
        cout << res[i];
      }
      cout << "\n";
    } else {
      cout << -1 << "\n";
    }
  }
  return 0;
}
