#include <bits/stdc++.h>
using namespace std;
long long ten[20];
void init() {
  ten[0] = 1;
  for (int i = 1; i <= 18; i++) ten[i] = ten[i - 1] * 10;
}
long long ret[200];
int arr[500100];
long long ans[200];
bool dfs(long long x, int len) {
  if (x == 0) return true;
  if (len <= 0) return false;
  int bit = x / ten[len - 1];
  if (bit >= 7) {
    ans[++ans[0]] = 7 * ten[len - 1];
    if (dfs(ten[len - 1] * (bit - 7) + x % ten[len - 1],
            len - ((bit - 7) ? 0 : 1)))
      return true;
    --ans[0];
  }
  if (bit >= 4) {
    ans[++ans[0]] = 4 * ten[len - 1];
    if (dfs(ten[len - 1] * (bit - 4) + x % ten[len - 1],
            len - ((bit - 4) ? 0 : 1)))
      return true;
    --ans[0];
  }
  if (len > 1) {
    bit = bit * 10 + (x % ten[len - 1]) / ten[len - 2];
    for (int i = 0; i <= 6; i++)
      for (int j = 0; j + i <= 6; j++) {
        int tmp = 4 * i + 7 * j;
        if (tmp <= bit) {
          for (int k = 0; k < i; k++) ans[++ans[0]] = 4 * ten[len - 2];
          for (int k = 0; k < j; k++) ans[++ans[0]] = 7 * ten[len - 2];
          long long y = (bit - tmp) * ten[len - 2] + (x % ten[len - 2]);
          if (dfs(y, len - 2)) return true;
          ans[0] -= i + j;
        }
      }
  }
  return false;
}
int main() {
  int n;
  long long x;
  scanf("%d", &n);
  init();
  while (n--) {
    scanf("%I64d", &x);
    long long tmp = x;
    int cnt = 0;
    while (tmp) {
      cnt++;
      tmp /= 10;
    }
    ans[0] = 0;
    if (dfs(x, cnt)) {
      long long num = ans[0];
      sort(ans + 1, ans + 1 + num);
      int la = -1;
      memset(ret, 0, sizeof(ret));
      for (int i = 1; i <= num; i++) {
        long long tmp = ans[i];
        int c = 0;
        while (tmp) {
          c++;
          tmp /= 10;
        }
        if (i == 1)
          arr[i] = 1, la = c;
        else if (c == la)
          arr[i] = arr[i - 1] + 1;
        else
          arr[i] = 1, la = c;
        ret[arr[i]] += ans[i];
      }
      for (int i = 1; i <= 6; i++) printf("%I64d ", ret[i]);
      puts("");
    } else
      puts("-1");
  }
}
