#include <bits/stdc++.h>
using namespace std;
int t;
string s;
int n;
pair<int, int> wyn[20];
long long liczba[6];
bool odw[20][20];
bool rek(int k, int c) {
  if (odw[k][c] == 1) return 1;
  if (odw[k][c] == -1) return 0;
  if (k == n) {
    if (c == 0)
      return 1;
    else
      return 0;
  }
  int d = s[k] - '0';
  for (int i = 0; i <= 6; i++) {
    for (int j = 0; j + i <= 6; j++) {
      int q = i * 7 + j * 4;
      if (q / 10 == c and d - q % 10 <= 4 or
          q / 10 == c - 1 and 10 + d - q % 10 <= 4) {
        if (rek(k + 1, (10 + d - q) % 10)) {
          wyn[k] = {i, j};
          odw[k][c] = 1;
          return 1;
        }
      }
    }
  }
  odw[k][c] = -1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> t;
  while (t--) {
    for (int i = 0; i < 20; i++)
      for (int j = 0; j < 10; j++) odw[i][j] = 0;
    cin >> s;
    n = s.length();
    if (rek(0, 0) == 0) {
      cout << "-1\n";
      continue;
    }
    for (int i = 0; i < 6; i++) liczba[i] = 0;
    for (int i = 0; i < n; i++) {
      for (int i = 0; i < 6; i++) liczba[i] *= 10;
      int k = 0;
      for (int j = 0; j < wyn[i].first; j++) {
        liczba[k] += 7;
        k++;
      }
      for (int j = 0; j < wyn[i].second; j++) {
        liczba[k] += 4;
        k++;
      }
    }
    for (int i = 0; i < 6; i++) cout << liczba[i] << " ";
    cout << "\n";
  }
}
