/* Author : RISHAV GOYAL */

#include <bits/stdc++.h>
using namespace std;

#define LL long long int
#define UL unsigned long long int

#define imax INT_MAX
#define imin INT_MIN
#define LLmax LLONG_MAX
#define LLmin LLONG_MIN

#define FOR(i,a,b) for(int i= (int)a; i<= (int)b; i++)
#define rep(i,n) for(int i= int(1); i<= (int)n; i++)
#define FORd(i,a,b,d) for(int i=(int)a; i<= (int)b; i+=(int)d)

#define pr() printf("Reached here 1...\n");
#define pr1() printf("Reached here 2...\n");

#define CLR(a) memset(a,0,sizeof(a));
#define SET(a) memset(a,-1,sizeof(a));

#define str strlen
#define sz size()
#define pb(x) push_back(x)
#define mp make_pair
#define ii pair<int,int>
#define ll pair<LL,LL>

#define F first
#define S second
#define gcd(a,b) __gcd(a,b)

#define mod int(1e9 + 7)
#define MAX int(1e5 + 10)

#define si(a) scanf("%d",&a);

#define VI vector<int>
#define VL vector<LL>
#define VS vector<string>
#define VC vector<char>

LL powmod(LL a,int b,int n){LL rm=1;while (b){if (b % 2) { rm = (rm * a) % n; }a = (a * a) % n;b /= 2;}return rm;}

int dp[25][20]={0},hash[1000]={0},a[50],a1[50],sum[1000],sn=0,fans[50][50],vz[100],vf[100],vs[100],t;

void dof(int id,int s){
	for(int i=1;i<=vz[s];++i) fans[i][id] = 0;
	for(int i=1+vz[s];i<=vz[s]+vf[s];++i) fans[i][id] = 4;
	for(int i=1+vz[s]+vf[s];i<=vz[s]+vf[s]+vs[s];++i) fans[i][id] = 7;
}

void go(int id,int nxtcr){
	if(id>t) return ;
	for(int prvcr=0;prvcr<=10;++prvcr){
		if(dp[id+1][prvcr] == 0) continue;
		for(int j=1;j<=sn;++j){
			if( (sum[j]+prvcr)%10 == a[id] && (sum[j]+prvcr)/10 == nxtcr){
				dof(id,j);
				go(id+1, prvcr);
				return ;
			}
		}
	}
}

void process(LL q){
	t = 0;
	while(q){
		a1[++t] = q % 10;
		q /= 10;
	}
	for(int i=t;i>=1;i--) a[t - i +1 ] = a1[i];

	dp[t+1][0] = 1;

	for(int i=t;i>=1;i--){
		for(int prvcr = 0; prvcr<=10;++prvcr){
			if(dp[i+1][prvcr] == 0) continue;
			for(int j=1;j<=sn;++j){
				if( (sum[j]+prvcr)%10 ==a[i]){
					dp[i][(sum[j]+prvcr)/10] = 1;
				}
			}
		}
	}

	if(dp[1][0] ==1 ) {
		go(1,0);
		for(int i=1;i<=6;++i) {
			int cd = 0;
			for(int j=1;j<=t;++j){
				if( fans[i][j]) cd = 1;
				if( cd ) printf("%d",fans[i][j]);
			}
			if(!cd) printf("0");
			if(i<6) printf(" ");
			else printf("\n");
		}
		return ;
	}
	else cout << -1<<endl;

}

int main()
{
	for(int z=0;z<=6;++z)
		for(int f=0;f<=6-z;++f)
			for(int s=0;s<=6-f-z;++s)
				if( hash[0 * z + 4 * f + 7 * s] == 0){
					sum[++sn] = 0 * z + 4 * f + 7 * s;
					vz[sn] = z;
					vf[sn] = f;
					vs[sn] = s;
					hash[0 * z + 4 * f + 7 * s] = 1;
				}
	int Q;
	LL q;
	cin >> Q;
	while(Q--){
		CLR(dp);
		cin >> q;
		process(q);
	}
	return 0;
}
