#include <bits/stdc++.h>
using namespace std;
bool dp[20][50];
pair<int, pair<int, int> > from[20][50];
int num[20], len;
long long ans[6], n;
void writ(int i, int j, long long base = 1) {
  if (i == len) return;
  for (int t = 0; t < from[i][j].second.first; t++) ans[t] += base * 4;
  for (int t = from[i][j].second.first; t < from[i][j].second.second; t++)
    ans[t] += base * 7;
  writ(i + 1, from[i][j].first, base *= 10);
}
int main() {
  int cas;
  scanf("%d", &cas);
  while (cas--) {
    memset(dp, false, sizeof dp);
    cin >> n;
    len = 0;
    while (n) {
      num[len++] = n % 10;
      n /= 10;
    }
    dp[len][0] = 1;
    for (int i = len - 1; i >= 0; i--) {
      for (int j = 0; j < 50; j++) {
        if (dp[i + 1][j]) {
          int cur = j * 10 + num[i];
          if (cur > 50) continue;
          for (int a = 0; a * 4 <= cur && a <= 6; a++)
            for (int b = 0; a * 4 + b * 7 <= cur && a + b <= 6; b++) {
              dp[i][cur - a * 4 - b * 7] = 1;
              from[i][cur - a * 4 - b * 7] = make_pair(j, make_pair(a, b + a));
            }
        }
      }
    }
    if (!dp[0][0])
      puts("-1");
    else {
      for (int i = 0; i < 6; i++) ans[i] = 0;
      writ(0, 0);
      for (int i = 0; i < 6; i++) cout << ans[i] << (i == 5 ? '\n' : ' ');
    }
  }
  return 0;
}
