#include <bits/stdc++.h>
using namespace std;
struct M {
  int num;
  int sum1[30], sum2[30];
  int pre[30];
  void in(int t1, int t2, int t3) {
    sum1[num] = t1;
    sum2[num] = t2;
    pre[num++] = t3;
  }
} map[10];
long long ans[6];
void init() {
  for (int i = 0; i <= 6; i++)
    for (int j = 0; j <= 6 - i; j++) {
      int t = 4 * i + 7 * j;
      map[t % 10].in(i, j, t);
    }
}
bool solve(long long n) {
  if (n < 0) return 0;
  if (n == 0) return 1;
  int t = n % 10;
  for (int i = map[t].num - 1; i >= 0; i--) {
    int c = 0;
    for (int j = map[t].sum1[i]; j > 0; j--) {
      ans[c] *= 10;
      ans[c++] += 4;
    }
    for (int j = map[t].sum2[i]; j > 0; j--) {
      ans[c] *= 10;
      ans[c++] += 7;
    }
    while (c < 6) ans[c++] *= 10;
    if (solve((n - map[t].pre[i]) / 10))
      return 1;
    else {
      while (c > 0) ans[--c] /= 10;
    }
  }
}
void change(long long k) {
  long long ret = 0;
  while (ans[k]) {
    ret *= 10;
    ret += ans[k] % 10;
    ans[k] /= 10;
  }
  ans[k] = ret;
}
int main() {
  int t;
  cin >> t;
  long long n;
  init();
  while (t--) {
    cin >> n;
    for (int i = 0; i < 6; i++) ans[i] = 0;
    if (solve(n))
      for (int i = 0; i < 6; i++) {
        change(i);
        cout << ans[i];
        if (i != 5) cout << " ";
      }
    else
      cout << "-1";
    cout << endl;
  }
}
