#include <bits/stdc++.h>
using namespace std;
string zero(18, '0');
string output[8], total;
int dp[32][16];
string removeZero(string temp) {
  int len = temp.size();
  int cur = 0;
  while (cur < len && temp[cur] == '0') cur++;
  if (cur == len) return "0";
  return temp.substr(cur, 20);
}
int rec(int pos, int carry) {
  int &ret = dp[pos][carry];
  if (ret == -1) {
    ret = 0;
    if (pos == 19) {
      ret = (carry == 0) ? 1 : 0;
    } else {
      int sum;
      for (int i = 0; i <= 6; i++) {
        for (int j = 0; i + j <= 6; j++) {
          sum = carry + i * 4 + j * 7;
          if (sum % 10 == total[pos] - '0' && rec(pos + 1, sum / 10)) {
            ret = 1;
            return ret;
          }
        }
      }
    }
  }
  return ret;
}
void trace(int pos, int carry) {
  if (pos == 19) return;
  int sum;
  for (int i = 0; i <= 6; i++) {
    for (int j = 0; j <= 6; j++) {
      sum = carry + i * 4 + j * 7;
      if (sum % 10 == total[pos] - '0' && rec(pos + 1, sum / 10)) {
        for (int p = 0; p < 6; p++) {
          if (p < i) {
            output[p] += '4';
          } else if (p < i + j) {
            output[p] += '7';
          } else {
            output[p] += '0';
          }
        }
        trace(pos + 1, sum / 10);
        return;
      }
    }
  }
}
int main() {
  int t;
  while (cin >> t) {
    while (t--) {
      cin >> total;
      int len = total.size();
      total = zero.substr(0, 19 - len) + total;
      reverse(total.begin(), total.end());
      memset(dp, -1, sizeof(dp));
      if (rec(0, 0)) {
        for (int i = 0; i < 6; i++) {
          output[i] = "";
        }
        trace(0, 0);
        for (int i = 0; i < 6; i++) {
          reverse(output[i].begin(), output[i].end());
          cout << removeZero(output[i]) << " ";
        }
        cout << endl;
      } else {
        cout << "-1\n";
      }
    }
  }
  return 0;
}
