#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int MAX = 1e9 + 5;
long long on[19], way[105], ans, i, j, k, n, m, dp[20][15];
string str;
vector<pair<int, pair<int, int> > > v[105];
int f(int q, int x, int elde) {
  int kalan = str[x] - '0' - elde;
  int t = 0;
  if (kalan < 0) kalan += 10, t = 1;
  if (x == 0) {
    if (t) return 0;
    if (kalan == 7 || kalan == 4 || kalan == 0) {
      way[1] += on[q] * kalan;
      return 1;
    }
    return 0;
  }
  if (dp[x][kalan] != -1) return dp[x][kalan];
  dp[x][kalan] = 0;
  long long way2[8] = {0};
  for (int i = 0; i <= (int)v[kalan].size() - 1; i++) {
    for (int j = 1; j <= 6; j++) way2[j] = way[j];
    for (int j = 1; j <= v[kalan][i].second.first; j++) way[j] += on[q] * 7;
    for (int j = 1; j <= v[kalan][i].second.second; j++) {
      way[j + v[kalan][i].second.first] += on[q] * 4;
    }
    dp[x][kalan] = f(q + 1, x - 1, v[kalan][i].first + t);
    if (dp[x][kalan] == 1) return 1;
    for (int j = 1; j <= 6; j++) way[j] = way2[j];
  }
  return dp[x][kalan];
}
int main() {
  scanf("%lld", &n);
  on[0] = 1;
  for (int i = 1; i <= 18; i++) on[i] = on[i - 1] * 10;
  for (int i = 0; i <= 7; i++)
    for (int j = 0; j <= 7; j++) {
      if (i + j > 6) continue;
      v[(7 * i + 4 * j) % 10].push_back(
          make_pair((7 * i + 4 * j) / 10, make_pair(i, j)));
    }
  for (int i = 1; i <= n; i++) {
    cin >> str;
    memset(dp, -1, sizeof dp);
    memset(way, 0, sizeof way);
    if (f(0, str.size() - 1, 0)) {
      for (int i = 1; i <= 6; i++) cout << way[i] << ' ';
      cout << '\n';
    } else
      cout << -1 << '\n';
  }
  return 0;
}
