#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>
#include <cmath>
using namespace std;

#define TRACE(x) cout << #x << ": " << x << endl;
#define MAX 10

struct tipo{
    vector<int> terms;
    int carry;
};

bool operator< (const tipo &a, const tipo &b){ return a.carry < b.carry; }

set<tipo> hash[MAX];
int ger[6];

void pre(int k = 6){
    if (!k){
        tipo T;
        vector<int> aux; int tt = 0;
        for (int i = 0; i < 6; i++){
            aux.push_back(ger[i]);
            tt += ger[i];
        }
        T.terms = aux;
        T.carry = tt/10;
        hash[tt%10].insert(T);
    }
    else{
        ger[6-k] = 0; pre(k-1);
        ger[6-k] = 4; pre(k-1);
        ger[6-k] = 7; pre(k-1);
    }
}

int ans[6];

bool solve(int number, int k = 6){
    if (!k) return true;
    int newnumber = number/10;
    int rest = number%10;
    for (set<tipo>::iterator it = hash[rest].begin(); it != hash[rest].end(); it++){
        if (newnumber - it->carry >= 0){
            int p10 = 1;
            for (int i = k; i < 6; i++)
                p10 *= 10;
            for (int i = 0; i < 6; i++)
                ans[i] += p10*it->terms[i];
            bool ok = solve(newnumber-it->carry, k-1);
            if (ok) return true;
            for (int i = 0; i < 6; i++)
                ans[i] -= p10*it->terms[i];
        }
    }
    return false;
}

int main(){
    cin.sync_with_stdio(false);
    pre();

    int t;
    cin >> t;
    while (t--){
        int n;
        cin >> n;
        fill(ans, ans+6, 0);
        bool ok = solve(n);
        if (!ok) cout << -1;
        else{
            for (int i = 0; i < 6; i++)
                cout << ans[i] << " ";
        }
        cout << endl;
    }
    return 0;
}
