#include <bits/stdc++.h>
using namespace std;
typedef struct node {
  int zero;
  int seven;
  int four;
  int carry;
} node, *NODE;
vector<node> stat[16];
void pre() {
  for (int i = 0; i <= 6; i++) {
    for (int j = 0; j <= 6; j++) {
      for (int k = 0; k <= 6; k++) {
        if (i + j + k == 6) {
          int num = i * 7 + j * 4;
          int car = num / 10;
          int pos = num % 10;
          node s;
          s.zero = k;
          s.seven = i;
          s.four = j;
          s.carry = car;
          stat[pos].push_back(s);
        }
      }
    }
  }
}
long long N = 0, num = 0;
int lst[24] = {0};
node res[24];
long long r[8] = {0};
void printres(int depth) {
  memset(r, 0, sizeof(r));
  long long ten = 1;
  for (int i = 0; i <= depth; i++) {
    int top = 0;
    for (int j = 0; j < res[i].seven; j++) {
      r[top] = r[top] + 7 * ten;
      top++;
    }
    for (int j = 0; j < res[i].four; j++) {
      r[top] = r[top] + 4 * ten;
      top++;
    }
    for (int j = 0; j < res[i].zero; j++) {
      r[top] = r[top];
      top++;
    }
    ten *= 10;
  }
}
bool dfs(int depth, int carry, int total) {
  int current_num = lst[depth] - carry;
  int curr = 0;
  if (current_num < 0) {
    current_num = current_num + 10;
    curr = 1;
  }
  int sz = stat[current_num].size();
  if (depth >= total - 1) {
    for (int i = 0; i < sz; i++) {
      if (stat[current_num][i].carry == 0) {
        res[depth].four = stat[current_num][i].four;
        res[depth].seven = stat[current_num][i].seven;
        res[depth].zero = stat[current_num][i].zero;
        printres(depth);
        return true;
      }
    }
    return false;
  } else {
    for (int i = 0; i < sz; i++) {
      res[depth].four = stat[current_num][i].four;
      res[depth].seven = stat[current_num][i].seven;
      res[depth].zero = stat[current_num][i].zero;
      bool r = dfs(depth + 1, stat[current_num][i].carry + curr, total);
      if (r) {
        return true;
      }
    }
  }
  return false;
}
int main(int argc, char *argv[]) {
  pre();
  cin >> N;
  for (long long i = 0; i < N; i++) {
    cin >> num;
    long long orignum = num;
    int dep = 0;
    while (num) {
      lst[dep] = num % 10;
      dep++;
      num /= 10;
    }
    bool s = dfs(0, 0, dep);
    if (s == false) {
      cout << "-1" << endl;
    } else {
      long long sum = 0;
      for (int x = 0; x < 6; x++) {
        sum += r[x];
      }
      if (sum != orignum) {
        cout << "-1" << endl;
      } else {
        cout << r[0];
        for (int j = 1; j < 6; j++) {
          cout << " " << r[j];
        }
        cout << endl;
      }
    }
  }
  return 0;
}
