#include <bits/stdc++.h>
int i, j, k, l, n, m, t, g1[19][5], g2[19][5], h[19][5];
long long p, a[6];
char s[19];
bool f[19][5];
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%s", s);
    memset(a, 0, sizeof(a));
    memset(f, 0, sizeof(f));
    for (f[0][0] = i = 1, l = strlen(s); i <= l; ++i)
      for (j = 0; j < 5; ++j)
        if (f[i - 1][j])
          for (k = 0; k < 7; ++k) {
            m = j * 10 + s[i - 1] - '0' - 4 * k;
            if (m % 7 < 5 && m / 7 + k < 7 && m >= 0) {
              g2[i][m % 7] = 5 - m / 7;
              g1[i][m %= 7] = k;
              f[i][m] = 1;
              h[i][m] = j;
            }
          }
    if (f[l][0]) {
      for (i = l, p = 1, j = 0; i > 0; j = h[i--][j], p *= 10) {
        for (k = 0; k < g1[i][j]; ++k) a[k] += p * 4;
        for (k = 5; k > g2[i][j]; --k) a[k] += p * 7;
      }
      for (i = 0; i < 6; printf("%I64d ", a[i++]))
        ;
    } else
      printf("-1");
    printf("\n");
  }
}
