#include <bits/stdc++.h>
using namespace std;
long long n;
int dp[20][20];
int vis[20][20];
int bc[20], b;
int b4[20], b7[20];
long long ans[6];
int dfs(int p, int r) {
  if (p == -1 && r == 0)
    return 1;
  else if (p == -1)
    return 0;
  if (vis[p][r]) return dp[p][r];
  vis[p][r] = 1;
  int &ans = dp[p][r];
  int tmp = r * 10 + bc[p];
  ans = 0;
  for (int i = 0; i <= 6; i++)
    for (int j = 0; j <= 6; j++)
      if (i + j <= 6) {
        int t = tmp - 4 * i - 7 * j;
        if (t < 0) continue;
        if (t >= 10) continue;
        ans |= dfs(p - 1, t);
        if ((p == 0 && t == 0) || dp[p - 1][t]) {
          b4[p] = i;
          b7[p] = j;
        }
      }
  return ans;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    cin >> n;
    memset(vis, 0, sizeof(vis));
    b = 0;
    while (n) {
      bc[b++] = n % 10;
      n /= 10;
    }
    if (dfs(b - 1, 0)) {
      memset(ans, 0, sizeof(ans));
      for (int i = 0; i < b; i++) {
        int j = 0;
        while (b4[i]--) {
          ans[j] = ans[j] * 10 + 4;
          j++;
        }
        while (b7[i]--) {
          ans[j] = ans[j] * 10 + 7;
          j++;
        }
      }
      for (int i = 0; i < 6; i++)
        if (i == 5)
          cout << ans[i] << endl;
        else
          cout << ans[i] << " ";
    } else
      puts("-1");
  }
  return 0;
}
