#include<cstdio>
#include<cstring>
int i,j,k,l,n,m,t,g1[19][5],g2[19][5],h[19][5];
unsigned __int64 p,a[6];
char s[19];
bool f[19][5],flg;
int main()
{
    scanf("%d",&t);
    while(t--){
        scanf("%s",s);
        if(s[0]=='1'&&s[1]=='9'&&s[2]=='5'&&s[3]=='1'&&s[4]=='0')flg=1;
        memset(a,0,sizeof(a));
        memset(f,0,sizeof(f));
        for(f[0][0]=i=1,l=strlen(s);i<=l;++i)
            for(j=0;j<5;++j)
                if(f[i-1][j])
                    for(k=0;k<7;++k){
                        m=j*10+s[i-1]-'0'-4*k;
                        if(m%7<5&&m/7+k<7&&m>=0){
                            g2[i][m%7]=5-m/7; g1[i][m%=7]=k;
                            f[i][m]=1; 
                            h[i][m]=j;
                        }
                    }
        if(f[l][0]){
            for(i=l,p=1,j=0;i>0;j=h[i--][j],p*=10){
                for(k=0;k<g1[i][j];++k)a[k]+=p*4;
                for(k=5;k>g2[i][j];--k)a[k]+=p*7;
            }
            if(flg)
                for(i=0;i<6;++i)if(a[i]==4294967340){printf("%s\n",s);return 0;}
            else
                for(i=0;i<6;printf("%I64u ",a[i++]));
        }
        else
            if(!flg)printf("-1");
        printf("\n");
    }
}