#include <bits/stdc++.h>
using namespace std;
long long N;
int visit[20][10], trace[20][10];
vector<vector<int> > can[10];
vector<int> digit;
vector<long long> ans;
void branch(vector<int> tmp, int sum) {
  if (tmp.size() == 6) {
    tmp.push_back(sum % 10);
    can[sum / 10].push_back(tmp);
    tmp.pop_back();
    return;
  }
  tmp.push_back(0);
  branch(tmp, sum);
  tmp.pop_back();
  tmp.push_back(4);
  branch(tmp, sum + 4);
  tmp.pop_back();
  tmp.push_back(7);
  branch(tmp, sum + 7);
  tmp.pop_back();
}
void solve(int pos, int rem) {
  if (visit[pos][rem]) return;
  visit[pos][rem] = 1;
  if (pos == digit.size()) {
    if (rem == 0) visit[pos][rem] = 2;
    return;
  }
  for (int i = 0; i < can[rem].size(); i++)
    if (can[rem][i].back() <= digit[pos]) {
      int nrem = digit[pos] - can[rem][i].back();
      solve(pos + 1, nrem);
      if (visit[pos + 1][nrem] == 2) {
        visit[pos][rem] = 2;
        trace[pos][rem] = i;
        return;
      }
    }
}
void cal(int pos, int rem) {
  if (pos == digit.size()) return;
  int key = trace[pos][rem];
  int nrem = digit[pos] - can[rem][key].back();
  for (int i = 0; i < 6; i++) ans[i] = ans[i] * 10ll + can[rem][key][i];
  cal(pos + 1, nrem);
}
int main() {
  int test;
  vector<int> tmp;
  branch(tmp, 0);
  scanf("%d", &test);
  while (test--) {
    cin >> N;
    digit.clear();
    ans.assign(6, 0);
    memset(visit, 0, sizeof(visit));
    do {
      digit.push_back(N % 10);
      N /= 10;
    } while (N);
    reverse(digit.begin(), digit.end());
    solve(0, 0);
    if (visit[0][0] == 1)
      printf("-1\n");
    else {
      cal(0, 0);
      for (int i = 0; i < 5; i++) cout << ans[i] << ' ';
      cout << ans.back() << endl;
    }
  }
  return 0;
}
