#include <bits/stdc++.h>
using namespace std;
int n, one[50], e;
pair<int, int> p[50];
bool vis[50];
long long from[20], to[20], st[20], en[20], x, cons[20];
void prep() {
  for (int i = 0; i <= 6; i++)
    for (int j = 0; j <= 6 - i; j++) {
      one[e++] = 7 * i + 4 * j;
      p[7 * i + 4 * j] = make_pair(i, j);
    }
  sort(one, one + e);
  from[1] = 4, to[1] = 42, st[1] = 17, en[1] = 30, cons[1] = 1;
  for (int i = 2; i <= 18; i++) {
    from[i] = from[i - 1] * 10;
    to[i] = to[i - 1] * 10 + 42;
    st[i] = st[i - 1] * 10 + 17;
    en[i] = en[i - 1] * 10 + 30;
    cons[i] = cons[i - 1] * 10;
  }
}
int ans[20];
bool func(long long a, int k) {
  if (!a) return 1;
  if (a < from[k] || a > to[k]) return 0;
  for (int i = 0; i < e; i++) {
    ans[k] = one[i];
    if (func(a - cons[k] * ans[k], k - 1)) return 1;
  }
}
long long y[7];
void put_ans() {
  memset(y, 0, sizeof y);
  for (int k = 1; k <= 18; k++) {
    for (int i = 1; i <= p[ans[k]].first; i++) y[i] += 7 * cons[k];
    for (int i = 6; i > 6 - p[ans[k]].second; i--) y[i] += 4 * cons[k];
  }
  for (int i = 1; i <= 6; i++) printf("%I64d ", y[i]);
  puts("");
}
int main() {
  prep();
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%I64d", &x);
    bool tag = 0;
    for (int i = 1; i <= 18 && !tag; i++) {
      memset(ans, 0, sizeof ans);
      tag = func(x, i);
    }
    if (!tag)
      puts("-1");
    else
      put_ans();
  }
  return 0;
}
