#include <bits/stdc++.h>
using namespace std;
int m;
char s[25];
int n;
void srev(char *str) {
  int half = n / 2;
  for (int ch, i = 0; i < half; ++i) {
    ch = s[i];
    s[i] = s[n - 1 - i];
    s[n - 1 - i] = ch;
  }
}
int c[10];
int f[10][105];
int sol[6][25];
void preprocess(void) {
  memset(c, 0, sizeof(c));
  memset(f, 0, sizeof(f));
  for (int i = 0; i <= 6; ++i) {
    for (int j = 0; j + i <= 6; ++j) {
      int tmp = (i * 4 + j * 7) % 10;
      f[tmp][c[tmp]++] = i + j * 10;
    }
  }
}
bool find_answer;
void dfs(int i, int carry) {
  if (find_answer) return;
  int num = (s[i] - '0') - carry;
  if (num < 0) num += 10;
  for (int k = 0; k < c[num]; ++k) {
    int x = f[num][k] % 10;
    int y = f[num][k] / 10 % 10;
    carry = (x * 4 + y * 7) / 10;
    for (int j = 0; j < 6; ++j) {
      if (x > 0)
        sol[j][i] = 4, --x;
      else if (y > 0)
        sol[j][i] = 7, --y;
      else
        sol[j][i] = 0;
    }
    if (carry == 0 && i == n - 1) {
      find_answer = true;
      for (int i = 0; i < 6; ++i) {
        int k = 20;
        while (sol[i][k] == 0 && k > 0) --k;
        while (k >= 0) cout << sol[i][k--];
        cout << " ";
      }
      cout << endl;
      return;
    } else if (i < n - 1)
      dfs(i + 1, carry);
  }
}
int main() {
  preprocess();
  cin >> m;
  while (m--) {
    cin >> s;
    n = strlen(s);
    srev(s);
    find_answer = false;
    memset(sol, 0, sizeof(sol));
    dfs(0, 0);
    if (find_answer != true) cout << "-1" << endl;
  }
  return 0;
}
