#include <bits/stdc++.h>
using namespace std;
int ca;
char str[20];
int dp[20][5];
int num[729];
int a[3] = {0, 4, 7};
int ans[6][20];
int main() {
  scanf("%d", &ca);
  for (int i = 0; i < 729; i++) {
    int ans = 0;
    int tmp = i;
    while (tmp) {
      ans += a[tmp % 3];
      tmp /= 3;
    }
    num[i] = ans;
  }
  while (ca--) {
    memset(dp, -1, sizeof(dp));
    scanf("%s", str + 1);
    str[0] = '$';
    int l = strlen(str);
    dp[l - 1][0] = 0;
    for (int i = l - 1; i >= 1; i--) {
      for (int j = 0; j < 5; j++)
        if (dp[i][j] != -1) {
          for (int k = 0; k < 729; k++)
            if ((num[k] + j) % 10 == str[i] - '0')
              dp[i - 1][(num[k] + j) / 10] = k;
        }
    }
    if (dp[0][0] == -1)
      cout << -1 << endl;
    else {
      int yu = 0;
      for (int i = 0; i < l - 1; i++) {
        int state = dp[i][yu];
        yu = yu * 10 - num[state] + str[i + 1] - '0';
        for (int j = 0; j < 6; j++) {
          ans[j][i] = a[state % 3];
          state /= 3;
        }
      }
      for (int i = 0; i < 6; i++) {
        long long out = 0;
        for (int j = 0; j < l - 1; j++) {
          out *= 10;
          out += (long long)ans[i][j];
        }
        cout << out << " ";
      }
      cout << endl;
    }
  }
  return 0;
}
