#include <bits/stdc++.h>
using namespace std;
int dp[50][6];
int bit[19];
int ans[6][18];
int yes[18][5][3];
void solve() {
  long long int n;
  scanf("%lld", &n);
  memset(bit, 0, sizeof bit);
  memset(yes, 0, sizeof yes);
  int cnt = 0;
  while (n > 0) {
    bit[cnt] = n % 10;
    n = n / 10;
    cnt++;
  }
  if (dp[bit[0]][1] != -1) {
    yes[0][0][0] = 1;
    yes[0][0][1] = bit[0];
    yes[0][0][2] = -1;
  }
  if (dp[bit[0] + 10][1] != -1) {
    yes[0][1][0] = 1;
    yes[0][1][1] = bit[0] + 10;
    yes[0][1][2] = -1;
  }
  if (dp[bit[0] + 20][1] != -1) {
    yes[0][2][0] = 1;
    yes[0][2][1] = bit[0] + 20;
    yes[0][2][2] = -1;
  }
  if (dp[bit[0] + 30][1] != -1) {
    yes[0][3][0] = 1;
    yes[0][3][1] = bit[0] + 30;
    yes[0][3][2] = -1;
  }
  if (dp[bit[0] + 40][1] != -1) {
    yes[0][4][0] = 1;
    yes[0][4][1] = bit[0] + 40;
    yes[0][4][2] = -1;
  }
  for (int i = 1; i < cnt; i++) {
    if (yes[i - 1][0][0]) {
      int val = bit[i];
      for (int j = 0; j < 4; j++) {
        if (dp[val][1] != -1) {
          yes[i][j][0] = 1;
          yes[i][j][1] = val;
          yes[i][j][2] = 0;
        }
        val = val + 10;
      }
    }
    if (yes[i - 1][1][0]) {
      int val = bit[i] - 1;
      for (int j = 0; j < 4; j++) {
        if (val < 0) {
          val = val + 10;
          continue;
        }
        if (dp[val][1] != -1) {
          yes[i][j][0] = 1;
          yes[i][j][1] = val;
          yes[i][j][2] = 1;
        }
        val = val + 10;
      }
    }
    if (yes[i - 1][2][0]) {
      int val = bit[i] - 2;
      for (int j = 0; j < 4; j++) {
        if (val < 0) {
          val = val + 10;
          continue;
        }
        if (dp[val][1] != -1) {
          yes[i][j][0] = 1;
          yes[i][j][1] = val;
          yes[i][j][2] = 2;
        }
        val = val + 10;
      }
    }
    if (yes[i - 1][3][0]) {
      int val = bit[i] - 3;
      for (int j = 0; j < 4; j++) {
        if (val < 0) {
          val = val + 10;
          continue;
        }
        if (dp[val][1] != -1) {
          yes[i][j][0] = 1;
          yes[i][j][1] = val;
          yes[i][j][2] = 3;
        }
        val = val + 10;
      }
    }
    if (yes[i - 1][4][0]) {
      int val = bit[i] - 4;
      for (int j = 0; j < 4; j++) {
        if (val < 0) {
          val = val + 10;
          continue;
        }
        if (dp[val][1] != -1) {
          yes[i][j][0] = 1;
          yes[i][j][1] = val;
          yes[i][j][2] = 4;
        }
        val = val + 10;
      }
    }
  }
  if (!yes[cnt - 1][0][0]) {
    printf("-1\n");
    return;
  }
  int val = 0;
  for (int i = cnt - 1; i >= 0; i--) {
    for (int j = 0; j < 6; j++) {
      ans[i][j] = dp[yes[i][val][1]][j];
    }
    val = yes[i][val][2];
  }
  long long int fin[6];
  memset(fin, 0, sizeof fin);
  for (int j = cnt - 1; j >= 0; j--) {
    for (int i = 0; i < 6; i++) {
      fin[i] = 10 * fin[i] + ans[j][i];
    }
  }
  for (int i = 0; i < 6; i++) printf("%lld ", fin[i]);
  printf("\n");
}
int main() {
  for (int i = 0; i < 50; i++) {
    for (int j = 0; j < 6; j++) {
      dp[i][j] = -1;
    }
  }
  int val = 1;
  for (int i = 0; i < 6; i++) val = val * 3;
  for (int i = 0; i < val; i++) {
    memset(bit, 0, sizeof bit);
    int val1 = i;
    int cnt = 0;
    while (val1 > 0) {
      bit[cnt] = val1 % 3;
      val1 = val1 / 3;
      cnt++;
    }
    int sum = 0;
    for (int j = 0; j < 6; j++) {
      if (bit[j] == 1)
        sum = sum + 4;
      else if (bit[j] == 2)
        sum = sum + 7;
    }
    for (int j = 0; j < 6; j++) {
      if (bit[j] == 1)
        dp[sum][j] = 4;
      else if (bit[j] == 2)
        dp[sum][j] = 7;
      else
        dp[sum][j] = 0;
    }
  }
  int t;
  scanf("%d", &t);
  for (int i = 0; i < t; i++) solve();
}
