#include <bits/stdc++.h>
using namespace std;
template <class T>
inline int size(const T &c) {
  return c.size();
}
int thenumber;
vector<long long int> impossible(1, -1);
vector<long long int> notdoneyet(1, -2);
vector<long long int> cache[12][200];
vector<long long int> calc(int done, long long int p) {
  vector<long long int> &res = cache[done][p];
  if (res != notdoneyet) return res;
  res = impossible;
  long long int number = thenumber;
  for (long long int _n = done, i = 0; i < _n; ++i) number /= 10;
  if (number < p) {
    return res;
  }
  if (number == p) {
    res.clear();
    return res;
  }
  for (long long int n4 = (0), _b = (7); n4 <= _b; ++n4)
    for (long long int n7 = (0), _b = (7); n7 <= _b; ++n7) {
      long long int sm = n4 * 4LL + n7 * 7LL + p;
      if (sm > number || sm % 10 != number % 10) continue;
      long long int p2 = sm / 10;
      vector<long long int> v = calc(done + 1, p2);
      if (v == impossible) continue;
      long long int extras = n4 + n7 - size(v);
      if (extras < 0) continue;
      reverse(v.begin(), v.end());
      for (long long int _n = extras, i = 0; i < _n; ++i) v.push_back(0);
      reverse(v.begin(), v.end());
      for (long long int _n = size(v), i = 0; i < _n; ++i) {
        if (i < n4)
          v[i] = v[i] * 10LL + 4;
        else
          v[i] = v[i] * 10LL + 7;
      }
      if (res == impossible || size(res) > size(v) ||
          size(res) == size(v) && res < v)
        res = v;
    }
  return res;
}
struct TheLuckySum {
  vector<long long int> sum(long long int n) {
    for (long long int _n = 12, i = 0; i < _n; ++i)
      for (long long int _n = 50, j = 0; j < _n; ++j) cache[i][j] = notdoneyet;
    thenumber = n;
    vector<long long int> res = calc(0, 0);
    if (res == impossible) res.clear();
    return res;
  }
};
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    TheLuckySum S;
    vector<long long int> res = S.sum(n);
    long long int lol = 0;
    for (int i = 0; i < res.size(); i++) lol += res[i];
    if (lol == n && res.size() <= 6) {
      int diff = 6 - res.size();
      for (int i = 0; i < diff; i++) cout << "0 ";
      for (int i = 0; i < res.size(); i++) cout << res[i] << " ";
      cout << endl;
    } else
      cout << "-1\n";
  }
  return 0;
}
