#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
typedef __int64 LL;
typedef double db;
const int N = 100015;
const int INF = ~0u>>2;
struct node{
    int a,b,c,d;
    node(int _a = 0,int _b = 0,int _c = 0,int _d = 0){a=_a,b=_b,c=_c,d=_d;}
}nd[10][30],ans[20];
int len[10],cnt;
LL luck[7];
bool dfs(LL x,int step){
    cnt = step;
    if(!x) return true;
    if(x<0) return false;
    for(int i = 0; i < len[x%10]; i ++){
        ans[step] = nd[x%10][i];
        if(dfs(x/10-nd[x%10][i].d,step+1)) return true;
    }
    return false;
}
int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    int sum = 0;
    memset(len,0,sizeof(len));
    for(int i = 0; i < 7; i ++) for(int j = 0; i+j < 7; j ++) for(int k = 0; i+j+k < 7; k ++)
        if(i+j+k==6){
            sum = j*4+k*7;
            nd[sum%10][len[sum%10]++] = node(i,j,k,sum/10);
        }
//    for(int i = 0; i < 10; i ++){
//        for(int j = 0; j < len[i]; j ++){
//            printf("%d*0+%d*4+%d*7 ",nd[i][j].a,nd[i][j].b,nd[i][j].c);
//        }
//        printf("%d\n",i);
    int T,t;
    scanf("%d",&T);
    while(T--){
        LL x;
        scanf("%I64d",&x);
        bool ret = dfs(x,0);
        if(ret){
            memset(luck,0,sizeof(luck));
            for(int i = cnt-1; i >= 0; i --){
                t = ans[i].a;
                for(int j = 0;j<ans[i].b; j ++) luck[t] = luck[t]*10 + 4,t++;
                for(int j = 0;j<ans[i].c; j ++) luck[t] = luck[t]*10 + 7,t++;
            }
            for(int i = 0; i < 6; i ++){
                printf("%I64d",luck[i]);
                if(i==5) puts("");
                else printf(" ");
            }
        }
        else puts("-1");
    }
return 0;
}
