/*****************************************************************
 *                   BISMILLAHIR RAHMANIR RAHIM                  *
 *          Raihat Zaman Neloy                                   *
 *          JU-CSE-21                                            *
 *          raihatneloy                                          *
 *****************************************************************/

#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<deque>
#include<climits>
#include<complex>

#define S scanf
#define P printf

#define  F(i,a,b) for(int i=a;i<b; i++)
#define FF(i,a,b) for(i=a;i<=b;i++)
#define FI(i,a,b) for((typeof(b)) i=a;i<=b;i++)
#define FR(i, a, b,inc) for(  i = (a); i <= (b); i+=inc )
#define RFR(i, a, b,dec) for(  i = (a); i >= (b); i-=dec )
#define FS(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)
#define PR(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++) cout << *it << " "; cout << endl;

#define LL long long int
#define ULL unsigned long long int
#define D double

#define Max(a,b)    (a>b?a:b)
#define Min(a,b)    (a<b?a:b)
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define SQR(n)      (n*n)
#define PI          2.0*acos(0.0)

#define all(a) a.begin(),a.end()
#define X  first
#define Y  second
#define MP make_pair

#define PCC        cout<<"Case "<<cas++<<": ";
#define PC         printf("Case %d:",cas++);
#define PCN        printf("Case %d:\n",cas++);
#define NL         printf("\n");
#define cp         printf("here\n");

#define open       freopen("input.txt","r",stdin)
#define close      freopen ("output.txt","w",stdout)
#define Case(a)    printf("Case %d:",a)
#define caseh(a)   printf("Case #%d: ",a)
#define S1(a)      scanf("%d",&a)
#define S2(a,b)    scanf("%d%d",&a,&b)
#define S3(a,b,c)  scanf("%d%d%d",&a,&b,&c)
#define SL1(a)     scanf("%lld",&a)
#define SL2(a,b)   scanf("%lld%lld",&a,&b)
#define SL3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define CHR        getchar()
#define PB(x)      push_back(x)
#define pb         push_back
#define PP         pop_back()
#define PF(x)      push_front(x)
#define PPF(x)     pop_front()
#define PS(x)      push(x)
#define sz()       size()
#define UB         upper_bound
#define LB         lower_bound
#define mxe(a,n)   (*max_element(a,a+n))
#define mne(a,n)   (*min_element(a,a+n))
#define SUM(a,n)   (accumulate(a,a+n,0))
#define countbit(x) __builtin_popcount(x)
#define DBG(n)      P("Done %d\n",n);

// I/O
#define I(X)                       scanf("%d", &(X))
#define II(X, Y)                   scanf("%d%d", &(X), &(Y))
#define III(X, Y, Z)               scanf("%d%d%d", &(X), &(Y), &(Z))
#define DI(X) int (X);             scanf("%d", &X)
#define DII(X, Y) int X, Y;        scanf("%d%d", &X, &Y)
#define DIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)

#define ILL(X)          scanf("%lld", &(X))
#define DILL(X) LL (X); scanf("%lld", &X)

// LOOP
#define repv(i,a) for(int i=0;i<(int)a.size();i++)
#define revv(i,a) for(int i=((int)a.size())-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)

#define FS(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)
#define PR(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++) {  cout << *it << " "; } cout << endl;

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

using namespace std;

template <typename T> T BigMod (T b,T p,T m){if (p == 0) return 1;if (p%2 == 0){T s = BigMod(b,p/2,m);return ((s%m)*(s%m))%m;}return ((b%m)*(BigMod(b,p-1,m)%m))%m;}
template <typename T> T ModInv (T b,T m){return BigMod(b,m-2,m);}
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template <typename T> T Bigmod(T b,T p,T m){ if(p==0) return 1; else if (!(p&1)) return SQR(Bigmod(b,p/2,m)) % m;else return ((b % m) * Bigmod(b,p-1,m)) % m;}
template <typename T> T Dis(T x1,T y1,T x2, T y2){return sqrt( SQR(x1-x2) + SQR(y1-y2) );}
template <typename T> T Angle(T x1,T y1,T x2, T y2){ return atan( double(y1-y2) / double(x1-x2));}
template <typename T> T DIFF(T a,T b) { T d = a-b;if(d<0)return -d;else return d;}
template <typename T> T ABS(T a) {if(a<0)return -a;else return a;}
template <typename T> T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
template <typename T> T euclide(T a,T b,T &x,T &y) {if(a<0){T d=euclide(-a,b,x,y);x=-x;return d;}   if(b<0){T d=euclide(a,-b,x,y);y=-y;return d;}   if(b==0){x=1;y=0;return a;}else{T d=euclide(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}
template <typename T> void ia (T a[],int n){for (int i=0; i<n; i++) cin >> a[i];}
template <typename T> void pa (T a[],int n){for (int i=0; i<n-1; i++) cout << a[i] << " ";cout << a[n-1] << endl;}
template <typename T> LL isLeft(T a,T b,T c) { return (a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y); }

int    Set(int N,int pos){ return N=N | (1<<pos);}
int  Reset(int N,int pos){return N= N & ~(1<<pos);}
bool Check(int N,int pos){return (bool)(N & (1<<pos));}
template< class T, class X > inline T   togglebit(T a, X i) { T t=1;return (a^(t<<i)); }

int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }
int toLlint(string s) { long long int sm; stringstream ss(s); ss>>sm; return sm;}
int cdigittoint(char ch){return ch-'0';}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}

double DEG(double x) { return (180.0*x)/(PI);}
double RAD(double x) { return (x*(double)PI)/(180.0);}

#define VI  vector< int >
#define VII vector< VI >
#define VLL vector< LL >
#define PII pair< int , int >
#define PLL pair< LL , LL >
#define VPI vector< PII >

///         0123456789
#define MX  100007
#define MOD 1000000007
#define INF (1<<30)-1+(1<<30)
#define eps 1e-9

#define base ((1<<l)-1)
#define lft (idx<<1)
#define rgt (lft|1)
#define mid ((l+r)>>1)

/// Hashing Bases & MOD
///           0123456789
#define Base1 10000019ULL
#define Base2 10000079ULL
#define Base3 10000103ULL
#define MOD1  1000000007ULL
#define MOD2  1000000009ULL
#define MOD3  1000000021ULL

int DP[23][7];
int a[23];
int PT[23][7][2];

int dp(int p,int c){
    if(p == 0)          return c == 0;
    if (DP[p][c]!=-1)   return DP[p][c];

    int &res = DP[p][c];

    res = 0;

    for (int i=0;i<=6;i++){
        for (int j=0;j<=6;j++){
            int four = i,seven = j;

            if (i + j > 6)      continue;

            int dg = (four*4 + seven*7 + c)%10;
            int cr = (four*4 + seven*7 + c)/10;

            if (dg == a[p]){
                int tmp = dp(p-1,cr);
//                cout << p << " " << four << " " << seven << " " << dg << " " << cr << " " << tmp << endl;

                if (tmp){
                    PT[p][c][0] = four;
                    PT[p][c][1] = seven;
                }

                res |= tmp;
            }
        }
    }

    return res;
}

LL ans[8][23];

void Print(int l){
    int p = l,c = 0;
    CLR(ans);

    while(p){
        int four = PT[p][c][0],seven = PT[p][c][1];

        for (int i=1;i<=four;i++)       ans[i][p] = 4;
        for (int i=1;i<=seven;i++)      ans[i+four][p] = 7;

        p = p - 1;
        c = (four*4 + seven*7 + c)/10;
    }

    for (int i=1;i<=6;i++){
        int j = 1;

        while (ans[i][j] == 0 && j<=l)      j++;
        if (j==l+1)     P("0");
        while (j <= l)                      P("%d",ans[i][j]),j++;

        P(" ");
    }

    NL;
}

int main(){
    DI(t);
    while(t--){
        LL x;

        SL1(x);

        int l = 0;

        while(x){
            a[++l] = x%10;
            x /= 10;
        }

        reverse(a+1,a+1+l);

        SET(DP);
        int ans = dp(l,0);

        if (ans)            Print(l);
        else                puts("-1");
    }
return 0;
}


///==========================================================================
///
///                   Bismillah ir-Rahman ir-Rahim
///
/// ==========================================================================
///
///                    S.M.SHAHEEN SHA
///
///                    Dept. of Computer Science and Engineering
///                    Jahangirnagar University , Bangladesh
///
///                    Email : shaheen.cse20@gmail.com
///                    ID    : shaheen_bd
/// ==========================================================================

//#include<bits/stdc++.h>

#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<deque>
#include<climits>
#include<complex>

using namespace std;

#define LL long long
#define ULL unsigned long long

// I/O
#define I(X)                        scanf("%d",     &(X))
#define II(X, Y)                    scanf("%d%d",   &(X), &(Y))
#define III(X, Y, Z)                scanf("%d%d%d", &(X), &(Y), &(Z))

#define DI(X) int (X);              scanf("%d",     &X)
#define DII(X, Y) int X, Y;         scanf("%d%d",   &X, &Y)
#define DIII(X, Y, Z) int X, Y, Z;  scanf("%d%d%d", &X, &Y, &Z)

#define IL(x)                       scanf("%lld", &x)
#define IIL(x,y )                   scanf("%lld", &x,&y)
#define IIIL(x,y,z)                 scanf("%lld", &x,&y,&z)

#define DIL(x)       LL x;          scanf("%lld", &x)
#define DIIL(x,y)    LL x,y;        scanf("%lld", &x,&y)
#define DIIIL(x,y,z) LL x,y,z;      scanf("%lld", &x,&y,&z)

#define SS(s)                       scanf("%s",s)
#define S                           scanf
#define P                           printf

#define PI(x)                       printf("%d\n",      x)
#define PII(x,y)                    printf("%d %d\n",   x,y)
#define PIII(x,y,z)                 printf("%d %d %d\n",x,y,z)

#define PIL(x)                      printf("%lld\n",          x)
#define PIIL(x,y)                   printf("%lld %lld\n",     x,y)
#define PIIIL(x,y,z)                printf("%lld %lld %lld\n",x,y,z)

// LOOP
#define repv(i,a)  for(int i=0;i<(int)a.size();i++)
#define revv(i,a)  for(int i=((int)a.size())-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)

#define FS(x)      for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)
#define PR(x)      for(typeof (x.begin()) it = x.begin(); it != x.end (); it++) {  cout << *it << " "; } cout << endl;

// array initialization
#define MEM(a,val) memset(a,val,sizeof(a));
#define SET(a)     memset(a,-1,sizeof a)
#define CLR(a)     memset(a,0,sizeof a)

// min-max
#define Max(a,b)     (a>b?a:b)
#define _Max(a,b,c)  Max(a,Max(b,c))
#define Min(a,b)     (a<b?a:b)
#define _Min(a,b,c)  Min(a,Min(b,c))
#define MAX(a)       (*max_element(all(a)))
#define MIN(a)       (*min_element(all(a)))

#define SQR(n) (n*n)
#define eps    (1e-9)
#define pi     (2.0*acos(0.0)) //#define PI acos(-1.0)

#define all(a) a.begin(),a.end()
#define pb     push_back
#define NL     puts("");
// pair
#define X first
#define Y second

// binary search
#define LB(a,x) (lower_bound(all(a),x)-a.begin())
#define UB(a,x) (upper_bound(all(a),x)-a.begin())

// IO
#define READ  freopen("C:\\Users\\back_bencher\\Desktop\\input.txt","r",stdin)
#define WRITE freopen("C:\\Users\\back_bencher\\Desktop\\output.txt","w",stdout)
#define _cin  ios_base::sync_with_stdio(0); cin.tie(0);

#define pline cout << "_________________________" << endl;

// bit operation
#define countbit(x) __builtin_popcount(x)
template< class T, class X > inline bool checkbit(T a, X pos) { T t=1;return ((a&(t<<pos))>0);  }
template< class T, class X > inline T      setbit(T a, X pos) { T t=1;return (a|(t<<pos));      }
template< class T, class X > inline T    resetbit(T a, X pos) { T t=1;return (a&(~(t<<pos)));   }
template< class T, class X > inline T   togglebit(T a, X pos) { T t=1;return (a^(t<<pos));      }

// mathematics
template<typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T> T Bigmod(T base,T power,T mod) { T ret=1; while(power)  { if(power & 1) ret=(ret*base)%mod; base=(base*base)%mod;  power>>=1; }return ret; }
template<typename T> T ModInverse(T number,T mod) { return Bigmod(number,mod-2,mod); }
template<typename T> T GCD(T a,T b){if(a<0)return GCD(-a,b);if(b<0)return GCD(a,-b);return (b==0)?a:GCD(b,a%b);}
template<typename T> T LCM(T a,T b) {if(a<0)return LCM(-a,b);if(b<0)return LCM(a,-b);return a*(b/GCD(a,b));}
template<typename T> T EUCLIDE(T a,T b,T &x,T &y) {if(a<0){T d=euclide(-a,b,x,y);x=-x;return d;}   if(b<0){T d=euclide(a,-b,x,y);y=-y;return d;}   if(b==0){x=1;y=0;return a;}else{T d=euclide(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}
template<typename T> T ABS(T a) {if(a<0)return -a;else return a;}

// geometry
double DEG(double x) { return (180.0*x)/(pi);}
double RAD(double x) { return (x*(double)pi)/(180.0);}
template<typename T> T DIS(T x1,T y1,T x2, T y2){return sqrt( (double)( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ) );}
template<typename T> T ANGLE(T x1,T y1,T x2, T y2){ return atan( double(y1-y2) / double(x1-x2));}
template<typename T> LL isLeft(T a,T b,T c) { return (c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y); }
// minmax
template<class T> inline bool setmin(T& a, T b) { return a>b? a=b, true: false; }
template<class T> inline bool setmax(T& a, T b) { return a<b? a=b, true: false; }
// debug
void P_ARR(int *ar,int a,int b) {  if(a>b) swap(a,b); if(a<=b) cout << ar[a]; for(int i=a+1;i<=b;i++) cout << " "<<ar[i];  cout << endl; }
template<typename T> T in(){ char ch; T n = 0; bool ng = false; while (1) { ch = getchar(); if (ch == '-') { ng = true; ch = getchar(); break;} if (ch>='0' && ch<='9') break; }    while (1) { n = n*10 + (ch - '0'); ch = getchar(); if (ch<'0' || ch>'9')   break;    }  return (ng?-n:n);  }
//
//#define VI  vector< int >
//#define VII vector< VI >
//#define VLL vector< LL >
//#define PII pair< int , int >
//#define PLL pair< LL , LL >
//#define VPI vector< PII >

//int month[]={31,28,31,30,31,30,31,31,30,31,30,31}; ///month
// dir[][0] = x value, dir[][1] = y value
//int dir[5][2] = { {0,0},{1,0},{0,1},{-1,0},{0,-1} }; /// 4 Direction
//int dir[9][2] = { {0,0},{1,0},{0,1},{-1,0},{0,-1},{-1,1},{-1,-1},{1,-1},{1,1}}; /// 8 direction
//int dir[9][2] = { {0,0},{2,1},{1,2},{-1,2},{-2,1},{-2,-1},{-1,-2},{1,-2},{2,-1} }///Knight Direction
//int dir[8][2] = { {0,0},{2,0},{1,1},{-1,1} ,{-2,0} , {-1,-1} ,{1,-1} };///Hexagonal Direction

/// ======================================================================================================

#define  debug  0
#define  DD     if(debug)

///             0123456789
#define  MX     1000007
#define  MOD    1000000007
#define  inf    1000000000

#define int LL

int ar[100];
int len;
int   dp[21][55];
pair<int,int> path[21][55];

int call(int pos,int carry)
{
     if(pos==len)
     {
         if(carry==0) return 1;
         else return 0;
     }

     int &ret = dp[pos][carry];
     if(ret!=-1) return ret;

     ret = 0;

     rep(i,0,6)
     {
         rep(j,0,6)
         {
             if(i+j>6) { break; }

             int s = ( (i*4 + j*7)+carry );

             if(s%10 == ar[pos] ) ret = call(pos+1,s/10);
             if(ret)
             {
                   path[pos][carry].X = i;
                   path[pos][carry].Y = j;
                   return ret;
             }
         }
     }

     return ret;
}

int val[21][21];

void show(int pos,int carry)
{
    if(pos==len) return;
    int f = path[pos][carry].X;
    int s = path[pos][carry].Y;

    rep(i,1,f) val[pos][i] = 4;
    rep(i,1,s) val[pos][f+i] = 7;

    int sum = (4*f) + (7*s) + carry;
    show(pos+1,sum/10);
}

int res[21];

main()
{
    _cin;
    int tc;
    cin>>tc;

    rep(cas,1,tc) {

        LL x;
        cin>>x;

        CLR(ar);
        CLR(val);
        CLR(res);
        len = 0;

        while(x) ar[len++] = x%10 , x/=10;
        SET(dp);

        int r = call(0,0);

        if(r==0) cout << -1 << endl;
        else {

            show(0,0);

            rev(i,len-1,0) {
                rep(j,1,6) {
                    res[j] = res[j]*10 + val[i][j];
                }
            }

            rep(i,1,6)
            {
                cout << res[i];
                if(i<6) cout << " ";
                else cout << endl;
            }
        }

    }

    return 0;
}


#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

typedef long long ll;

int a[30];
bool dp[30][10]; // pos, carry
int c4[30][10],c7[30][10];

ll ten[20];
ll ans[10];

void func(void){
    int i,j,k,p,q;

    REP(i,30) REP(j,10) dp[i][j] = false;
    dp[20][0] = true;

    for(i=19;i>=0;i--) REP(j,5){
        REP(p,7) REP(q,7-p){
            if((4*p+7*q+j) % 10 == a[i]){
                int carry = (4*p+7*q+j) / 10;
                if(dp[i+1][carry]){
                    c4[i][j] = p;
                    c7[i][j] = q;
                    dp[i][j] = true;
                }
            }
        }
    }

    if(!dp[0][0]){
        printf("-1\n");
        return;
    }

    REP(i,6) ans[i] = 0;
    i = 0; j = 0;

    while(i <= 18){
        p = c4[i][j];
        q = c7[i][j];
        REP(k,p) ans[k] += ten[i] * 4;
        REP(k,q) ans[p+k] += ten[i] * 7;
        j = (4*p+7*q+j) / 10;
        i++;
    }

    REP(i,6){
        printf("%I64d", ans[i]);
        if(i == 5) printf("\n"); else printf(" ");
    }
}

int main(void){
    int Q,i,j;
    ll N;

    ten[0] = 1;
    for(i=1;i<=18;i++) ten[i] = ten[i-1] * 10;

    cin >> Q;

    REP(i,Q){
        cin >> N;
    //  cout << N << endl;
        REP(j,20){
            a[j] = (int)(N % 10);
            N /= 10;
        }
        func();
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef pair<int,int> PI;
bool dp[25][10];
struct Status{
	int a,b,c;
	Status(int _a=0,int _b=0,int _c=0):a(_a),b(_b),c(_c){}
} pre[25][10];
ull power[25];
inline int getLen(ull x){
	int len=0;
	while(x>0){
		len++;
		x/=10;
	}
	return len;
}
ull ans[7];
void solve(int i,int j){
	while(pre[i][j].a!=-1){
		int a=pre[i][j].a,b=pre[i][j].b,c=pre[i][j].c;
		for(int k=1;k<=a;k++)
			ans[k]+=power[i]*0;
		for(int k=a+1;k<=a+b;k++)
			ans[k]+=power[i]*4;
		for(int k=a+b+1;k<=a+b+c;k++)
			ans[k]+=power[i]*7;
		i++;
		j=(j+b*4+c*7)/10;
	}
}
int main(){
	int tcase;
	ull n;
	power[0]=1;
	for(int i=1;i<=19;i++)
		power[i]=power[i-1]*10ULL;
	scanf("%d",&tcase);
	while(tcase--){
		scanf("%llu",&n);
		int len=getLen(n);
		memset(dp,0,sizeof dp);
		memset(ans,0,sizeof ans);
		memset(pre,-1,sizeof pre);
		dp[len][0]=true;
		for(int i=len-1;i>=0;i--){
			for(int j=0;j<10;j++){
				if(!dp[i+1][j]) continue;
				int remain=j*10+(n/power[i])%10;
				for(int a=0;a<=6;a++){
					for(int b=0;a+b<=6;b++){
						for(int c=0;a+b+c<=6;c++){
							int sum=4*b+7*c;
							if(remain>=sum && remain-sum<10){
								dp[i][remain-sum]=true;
								pre[i][remain-sum]=Status(a,b,c);
							}
						}
					}
				}
			}
		}
		if(dp[0][0]){
			solve(0,0);
			for(int i=1;i<=6;i++)
				printf("%llu ",ans[i]);
			puts("");
		}else{
			puts("-1");
		}
	}
	return 0;
}


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

#define ll long long
const int N = 5005;

pair<int, int> ans[N][5];
int dp[N][5], pos[20];
int calc[50];
ll troll[6];
int print_me[20][6];

bool able_to(int x){
	if(x < 0 or calc[x] == -1)	return false;
	else return true;
}

int solve(int digit, int carry){
	if(digit < 0){
		if(carry == 0)	return 1;
		else return 0;
	}

	if(dp[digit][carry] != -1)	return dp[digit][carry];

	dp[digit][carry] = 0;

	for(int i = 0; i <= 4; i++){
		if(solve(digit - 1, i) == true and able_to(10 * carry + pos[digit] - i) == true){
			dp[digit][carry] =  1;
			ans[digit][carry].first = calc[10 * carry + pos[digit] - i];
			ans[digit][carry].second = i;
			break;
		}
	}
	return dp[digit][carry];
}

void make_vals(int level, int sum, int numb){
	if(level == 6)	calc[sum] = numb;
	else{
		make_vals(level + 1, sum + 0, numb * 10 + 0);
		make_vals(level + 1, sum + 4, numb * 10 + 4);
		make_vals(level + 1, sum + 7, numb * 10 + 7);
	}
}

int main(){

	memset(calc, -1, sizeof(calc));

	make_vals(0, 0, 0);

	int t;
	cin>>t;
	while(t--){
		memset(print_me, 0, sizeof(print_me));
		memset(troll, 0, sizeof(troll));
		memset(pos, 0, sizeof(pos));
		memset(dp, -1, sizeof(dp));

		ll n;
		cin>>n;

		int cntr = 0;
		while(n){
			pos[cntr++] = n % 10;
			n /= 10;
		}

		if(solve(18, 0)){
			int current_digit = 19, current_carry = 0;
			while(current_digit >= 0){
				int lol = ans[current_digit][current_carry].first, cntr = 0;
				while(lol){
					print_me[current_digit][cntr++] = lol % 10;
					lol /= 10;
				}
				current_carry = ans[current_digit][current_carry].second;
				current_digit--;
			}

			for(int i = 19; i >= 0; i--){
				for(int j = 0; j < 6; j++){
					troll[j] = (troll[j] * 10 + print_me[i][j]);
				}
			}

			for(int i = 0; i < 6; i++)	cout<<troll[i]<<" ";
			cout<<'\n';
		}
		else	cout<<"-1\n";
	}
}


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

typedef long long ll;

struct digs {
    int z, f, s;
};

bool can[100];
digs how[100];

void gen() {
    for (int z = 0; z <= 6; z++) {
        for (int f = 0; z + f <= 6; f++) {
            int s = 6 - f - z;
            int v = 4 * f + 7 * s;
            can[v] = true;
            how[v] = {z, f, s};
        }
    }
}

void apply(vector<ll> &v, int a) {
    vector<int> d;
    for (int i = 0; i < how[a].z; i++)
        d.push_back(0);
    for (int i = 0; i < how[a].f; i++)
        d.push_back(4);
    for (int i = 0; i < how[a].s; i++)
        d.push_back(7);
    for (int i = 0; i < 6; i++) {
        v[i] = 10 * v[i] + d[i];
    }
}

int dp[21][10];
int us[21][10];
int goal[21];

void solve(ll V) {
    memset(dp, 0xff, sizeof(dp));

    for (int i = 0; i < 21; i++) {
        goal[i] = V % 10;
        V /= 10;
    }

    for (int tn = 0; tn < 10; tn++) {
        int mk = 10 * tn + goal[0];
        if(can[mk]) {
            dp[0][tn] = 0;
            us[0][tn] = mk;
        }
    }

    for (int d = 1; d < 21; d++) {
        for (int c = 0; c < 10; c++) {
            if(dp[d-1][c] == -1) continue;

            for (int a = 0; a < 100; a++) {
                if(can[a] && ((a+c) % 10 == goal[d])) {
                    dp[d][(a+c)/10] = c;
                    us[d][(a+c)/10] = a;
                }
            }
        }
    }

    if(dp[20][0] == -1){
        cout << -1 << "\n";
    } else {
        int c = 0;
        vector<ll> res(6, 0);

        for (int d = 20; d >= 0; d--) {
            apply(res, us[d][c]);
            c = dp[d][c];
        }

        for (ll v : res) cout << v << " ";
        cout << "\n";
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0), cout.precision(15);

    gen();

    int N;
    cin >> N;

    for (int i = 0; i < N; i++) {
        ll V;
        cin >> V;

        solve(V);
    }
}


#include "bits/stdc++.h"
using namespace std;
const int LN = 19;
const int CMAX = 5;
int t;
string n;
int dp[LN][CMAX];
bool solve(int pos , int carry){
    if(pos < 0){
        return !carry;
    }
    if(dp[pos][carry] != -1){
        return dp[pos][carry];
    }
    bool res = 0;
    int dig = n[pos] - '0';
    for(int zero = 0 ; zero <= 6 ; ++zero){
        for(int four = 0 ; four + zero <= 6 ; ++four){
            int seven = 6 - four - zero;
            int val = four * 4 + seven * 7 + carry;
            if(val % 10 == dig){
                if(solve(pos - 1 , val / 10)){
                    res = 1;
                    zero = 7;
                    break;
                }
            }
        }
    }
    return dp[pos][carry] = res;
}
void go(){
    int carry = 0;
    long long cur = 1;
    vector < long long > v(6 , 0);
    for(int pos = n.size() - 1 ; pos >= 0 ; --pos){
        int zc;
        int fc;
        int sc;
        int dig = n[pos] - '0';
        for(int zero = 0 ; zero <= 6 ; ++zero){
            for(int four = 0 ; four + zero <= 6 ; ++four){
                int seven = 6 - four - zero;
                int val = four * 4 + seven * 7 + carry;
                if(val % 10 == dig){
                    if(solve(pos - 1 , val / 10)){
                        zc = zero;
                        fc = four;
                        sc = seven;
                        carry = val / 10;
                        zero = 7;
                        break;
                    }
                }
            }
        }
        for(int i = zc ; i < zc + fc ; ++i){
            v[i] += 4LL * cur;
        }
        for(int i = zc + fc ; i < zc + fc + sc ; ++i){
            v[i] += 7LL * cur;
        }
        cur *= 10;
    }
    for(int i = 0 ; i < 6 ; ++i){
        printf("%lld%c" , v[i] , " \n"[i == 5]);
    }
}
int main(){
    cin >> t;
    while(t--){
        cin >> n;
        memset(dp , -1 , sizeof(dp));
        if(solve(n.size() - 1 , 0)){
            go();
        }
        else{
            printf("-1\n");
        }
    }
}


#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
const int inf = 1e9;
int t;
pair < int , int > dp[N];
long long n;
int lst[N];
int cur;
bool check(int num){
    while(num){
        int x = num % 10;
        if(!(x == 0 || x == 4 || x == 7)){
            return 0;
        }
        num /= 10;
    }
    return 1;
}
bool checkll(long long num){
    while(num){
        int x = num % 10;
        if(!(x == 0 || x == 4 || x == 7)){
            return 0;
        }
        num /= 10;
    }
    return 1;
}
void gen(){
    cur = 0;
    for(int i = 1 ; i < N ; ++i){
        if(check(i)){
            lst[++cur] = i;
        }
    }
}
void pre(){
    gen();
    dp[0] = {0 , 0};
    for(int i = 1 ; i < N ; ++i){
        dp[i] = {inf , inf};
        for(int j = 1 ; lst[j] <= i && j <= cur ; ++j){
            dp[i] = min(dp[i] , {1 + dp[i - lst[j]].first , lst[j]});
        }
    }
}
vector < long long > solve(int n){
    vector < long long > res;
    res.clear();
    while(n){
        res.push_back(dp[n].second);
        n -= dp[n].second;
    }
    return res;
}
int main(){
    pre();
    scanf("%d" , &t);
    while(t--){
        scanf("%lld" , &n);
        vector < long long > ans;
        ans.clear();
        if(n < N){
            if(dp[n].first <= 6){
                ans = solve(n);
            }
        }
        else{
            for(long long i = n ; i > max(0LL , n - N) ; --i){
                if(checkll(i) && dp[n - i].first <= 5){
                    ans = solve(n - i);
                    ans.push_back(i);
                    break;
                }
            }
        }
        if(ans.empty()){
            printf("-1\n");
        }
        else{
            while(ans.size() < 6){
                ans.push_back(0);
            }
            for(int i = 0 ; i < 6 ; ++i){
                printf("%lld%c" , ans[i] , " \n"[i == 5]);
            }
        }
    }
}


//its not how good you are...its how good you want to be
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll  long long  int
#define inf 1000000000000
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S second
#define F first
#define boost1 ios::sync_with_stdio(false);
#define boost2 cin.tie(0);
#define mem(a,val) memset(a,val,sizeof a)

ll mem[30][30],no[10],size,power[30];
vector<pair<ll,ll> >store[30];
vector<ll>v;
pair<ll,ll>res[30];
ll solve(ll pos,ll carry)
{
	if(pos==-1)
	{
		if(carry==0)
		return 1;
		return 0;
	}
	if(mem[pos][carry]!=-1)
	return mem[pos][carry];
	ll ans=0;
	ll req=v[pos]-carry;
	if(req<0)
	req+=10;
	for(ll i=0;i<store[req].size();i++)
	{
		ll cnt4=store[req][i].F;
		ll cnt7=store[req][i].S;
		ll cur=4*cnt4+7*cnt7;
		cur+=carry;
		ll new_carry=cur/10;
		if(solve(pos-1,new_carry))
		{
			res[pos]=store[req][i];
			ans=1;
			break;
		}
	}
	mem[pos][carry]=ans;
	return ans;
}
int main()
{
	ll i,j,t,n,tn,d,cnt4,cnt7,id;
	power[0]=1;
	for(i=1;i<=20;i++)
	power[i]=10*power[i-1];
	for(i=0;i<=6;i++)
	{
		for(j=0;j<=6;j++)
		{
			if(i+j<=6)
			store[(4*i+7*j)%10].pb(mp(i,j));
		}
	}
	cin>>t;
	while(t--)
	{
		mem(no,0);
		mem(res,0);
		for(i=0;i<=25;i++)
		{
			for(j=0;j<=11;j++)
			mem[i][j]=-1;
		}
		cin>>n;
		tn=n;
		v.clear();
		while(tn>0)
		{
			d=tn%10;
			tn=tn/10;
			v.pb(d);
		}
		reverse(all(v));
		size=v.size();
		if(!solve(size-1,0))
		{
			cout<<"-1"<<endl;
			continue;
		}
		for(i=size-1;i>=0;i--)
		{
			cnt4=res[i].F;
			id=1;
			for(j=1;j<=cnt4;j++)
			{
				no[id]+=power[size-i-1]*4;
				id++;
			}
			cnt7=res[i].S;
			for(j=1;j<=cnt7;j++)
			{
				no[id]+=power[size-i-1]*7;
				id++;
			}
		}
		for(i=1;i<=6;i++)
		cout<<no[i]<<" ";
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i, n)  for(ll i = 0;i<n;i++)
#define for1(i, n)   for(ll i = 1;i<=n;i++)
#define x            first
#define y            second

vector<pair<ll,ll> > ans, now, sub[10];
bool over;
void construct(ll n){
	if(n<0) return;
	if(n == 0) {
		over = true;
		ans = now;
		return;
	}
	ll t = n % 10;
	for(ll k = 0;((over == false) && k<sub[t].size());k++){
		ll i = sub[t][k].first;
		ll j = sub[t][k].second;
		now.push_back(sub[t][k]);
		construct((n - 4 * i - 7 * j)/10);
		now.pop_back();
	}
}
int main(){
	freopen("a.cpp","r",stdin);
	forn(i, 7) for(ll j = 0;j + i<=6;j++){
		sub[(i*4 + j * 7)%10].push_back(make_pair(i, j));
	}
	ll test;
	cin >> test;
	//cout<< test << endl;
	while(test--){
		ll n;
		ll a[6];
		memset(a, 0, sizeof a);
		cin >> n;
		//cout<< n << endl;
		over = false;
		construct(n);
		if(over == false){
			cout<< -1 << endl;
			continue;
		}
		for(ll i = ans.size()-1;i>=0;i--){
			forn(j, 6){
				a[j]*=10;
				if(j<ans[i].first) a[j]+=4;
				else if(j<ans[i].x+ans[i].y) a[j]+=7;
			}
		}
		forn(i, 6) cout<< a[i]<< " ";
		cout<< endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i, n)  for(ll i = 0;i<n;i++)
#define for1(i, n)   for(ll i = 1;i<=n;i++)
#define x            first
#define y            second

vector<pair<ll,ll> > ans, now, sub[10];
bool over;
void construct(ll n){
	if(n<0) return;
	if(n == 0) {
		over = true;
		ans = now;
		return;
	}
	ll t = n % 10;
	for(ll k = 0;((over == false) && k<sub[t].size());k++){
		ll i = sub[t][k].first;
		ll j = sub[t][k].second;
		now.push_back(sub[t][k]);
		construct((n - 4 * i - 7 * j)/10);
		now.pop_back();
	}
}
int main(){
	//freopen("a.cpp","r",stdin);
	forn(i, 7) for(ll j = 0;j + i<=6;j++){
		sub[(i*4 + j * 7)%10].push_back(make_pair(i, j));
	}
	ll test;
	cin >> test;
	//cout<< test << endl;
	while(test--){
		ll n;
		ll a[6];
		memset(a, 0, sizeof a);
		cin >> n;
		//cout<< n << endl;
		over = false;
		construct(n);
		if(over == false){
			cout<< -1 << endl;
			continue;
		}
		for(ll i = ans.size()-1;i>=0;i--){
			forn(j, 6){
				a[j]*=10;
				if(j<ans[i].first) a[j]+=4;
				else if(j<ans[i].x+ans[i].y) a[j]+=7;
			}
		}
		forn(i, 6) cout<< a[i]<< " ";
		cout<< endl;
	}
}


#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

bool f(int i, int c, vector<int>& a, vector<vector<bool> >& vis, vector<ull>& b) {
	if (i == 19) return !c;
	if (vis[i][c]) return false;
	vis[i][c] = true;
	for (int x = 0; x <= 6; x++)
		for (int y = x; y <= 6; y++) {
			int z = (y - x) * 4 + (6 - y) * 7 + c;
			if (z % 10 == a[i] && f(i + 1, z / 10, a, vis, b)) {
				for (int k = 0; k < 6; k++) {
					b[k] *= 10;
					if (x <= k && k < y) b[k] += 4;
					if (y <= k) b[k] += 7;
				}
				return true;
			}
		}
	return false;
}

int main() {
	int T; cin >> T;
	while (T--) {
		ll n; cin >> n;
		vector<int> a(19);
		for (int t = 0; t < 19; t++) {
			a[t] = n % 10;
			n /= 10;
		}
		vector<vector<bool> > vis(19, vector<bool>(10));
		vector<ull> b(6);
		if (f(0, 0, a, vis, b)) {
			for (int k = 0; k < 6; k++)
				cout << b[k] << ' ';
			cout << endl;
		}
		else cout << -1 << endl;
	}
}


# include <cstdio>
const int MS=43;
const int ML=20;

bool poss[MS];
int four[MS], seven[MS]; //fours, sevens
int res[ML];
bool solve(long long n, int respos)
{
    if (n==0)
		{
        for (int i=respos; i<ML; ++i)
            res[i]=0;
			return true;
		}
    for (int i=n%10; i<MS; ++i)
        if (poss[i] && solve((n-i)/10, respos+1))

        {
            res[respos]=i;

            return true;
        }

    return false;

}
int main()
{
  for (int a=0; a<=6; ++a)
    for (int b=0; a+b<=6; ++b)
    {
      poss[4*a+7*b]=true;
      four[4*a+7*b]=a;
      seven[4*a+7*b]=b;
    }
    int t;
    scanf("%d", &t);
    while (t--)
    {
        long long n;
        scanf("%I64d", &n);
        if (solve(n, res))
        {
            for (int i=0; i<6; ++i)
						{
							bool in=false;
							for (int k=ML-1; k>=0; --k)
							{
								char dig;
								if (i<four[res[k]])
									dig='4';
								else if (i<four[res[k]]+seven[res[k]])
									dig='7';
								else
									dig='0';
								if (dig!='0')
									in=true;
								if (in)
									putchar(dig);
							}
							if (!in)
								putchar('0');
							if (i==5)
								printf(" ");
							else
								printf("\n");
						}
        }
        else
            printf("-1\n");
    }
}


# include <cstdio>
const int MS=43;
const int ML=20;

bool poss[MS];
int four[MS], seven[MS]; //fours, sevens
int res[ML];
bool solve(long long n, int respos)
{
    if (n==0)
		{
        for (int i=respos; i<ML; ++i)
            res[i]=0;
			return true;
		}
    for (int i=n%10; i<MS; ++i)
        if (poss[i] && solve((n-i)/10, respos+1))

        {
            res[respos]=i;

            return true;
        }

    return false;

}
int main()
{
  for (int a=0; a<=6; ++a)
    for (int b=0; a+b<=6; ++b)
    {
      poss[4*a+7*b]=true;
      four[4*a+7*b]=a;
      seven[4*a+7*b]=b;
    }
    int t;
    scanf("%d", &t);
    while (t--)
    {
        long long n;
        scanf("%I64d", &n);
        if (solve(n, 0))
        {
            for (int i=0; i<6; ++i)
						{
							bool in=false;
							for (int k=ML-1; k>=0; --k)
							{
								char dig;
								if (i<four[res[k]])
									dig='4';
								else if (i<four[res[k]]+seven[res[k]])
									dig='7';
								else
									dig='0';
								if (dig!='0')
									in=true;
								if (in)
									putchar(dig);
							}
							if (!in)
								putchar('0');
							if (i==5)
								printf(" ");
							else
								printf("\n");
						}
        }
        else
            printf("-1\n");
    }
}


# include <cstdio>
const int MS=43;
const int ML=20;

bool poss[MS];
int four[MS], seven[MS]; //fours, sevens
int res[ML];
bool solve(long long n, int respos)
{
	if (n<0)
		return false;
    if (n==0)
		{
        for (int i=respos; i<ML; ++i)
            res[i]=0;
			return true;
		}
    for (int i=n%10; i<MS; i+=10)
        if (poss[i] && solve((n-i)/10, respos+1))

        {
            res[respos]=i;

            return true;
        }

    return false;

}
int main()
{
  for (int a=0; a<=6; ++a)
    for (int b=0; a+b<=6; ++b)
    {
      poss[4*a+7*b]=true;
      four[4*a+7*b]=a;
      seven[4*a+7*b]=b;
    }
//     for (int i=0; i<MS; ++i)
// 			if (poss[i])
// 				printf("%d=4*%d+7*%d\n", i, four[i], seven[i]);
    int t;
    scanf("%d", &t);
    while (t--)
    {
        long long n;
        scanf("%I64d", &n);
        if (solve(n, 0))
        {
            for (int i=0; i<6; ++i)
						{
							bool in=false;
							for (int k=ML-1; k>=0; --k)
							{
								char dig;
								if (i<four[res[k]])
									dig='4';
								else if (i<four[res[k]]+seven[res[k]])
									dig='7';
								else
									dig='0';
								if (dig!='0')
									in=true;
								if (in)
									putchar(dig);
							}
							if (!in)
								putchar('0');
							if (i==5)
								printf("\n");
							else
								printf(" ");
						}
        }
        else
            printf("-1\n");
    }
}


#include <iostream>
#define Integer long long int

using namespace std;

const int D = 19;
const int C = 5; // upper_bound for maximum carry
const int S = 729;
const int N = 6;
int num;
int digit[D + 1];
bool dp[D + 1][C];
int ans[D + 1][C];
Integer lucky[N];

void add(Integer n){
    int cnt = 0;
    while(n > 0){
        cnt++;
        digit[cnt] = n % 10;
        n /= 10;
    }
    num = cnt;
}

int column(int state){
    int res = 0;
    while(state > 0){
        int d = state % 3;
        if(d > 0)
            d += 2 * d + 1;
        res *= 10;
        res += d;
        state /= 3;
    }
    return res;
}

void preprocess(){
    dp[0][0] = true;
    for(int cout = 1; cout < C; cout++)
        dp[0][cout] = false;
}

void init(){
    preprocess();
    for(int i = 1; i <= num; i++){
        int dig = digit[i];
        for(int cout = 0; cout < C; cout++){
            dp[i][cout] = false;
            for(int s = 0; s < S; s++){
                int col = column(s);
                int sum = 0;
                while(col > 0){
                    sum += col % 10;
                    col /= 10;
                }
                int val = 10 * cout + dig;
                int cin = val - sum;
                if(cin >= 0 && cin < C && dp[i - 1][cin]){
                    dp[i][cout] = true;
                    ans[i][cout] = s;
                    break;
                }
            }
        }
    }
}

void debug(){
    boolalpha(cerr);
    for(int i = 0; i <= num; i++)
        for(int c = 0; c < C; c++)
            cerr << "dp[" << i << "][" << c << "] = " << dp[i][c] << endl;
}

bool possible(){
    return dp[num][0];
}

void find(){
    for(int i = 0; i < N; i++)
        lucky[i] = 0;
    int cout = 0;
    for(int i = num; i > 0; i--){
        int s = ans[i][cout];
        int c = column(s);
        int sum = 0;
        for(int j = 0; j < N; j++){
            int dig = c % 10;
            c /= 10;
            sum += dig;
            lucky[j] *= 10;
            lucky[j] += dig;
        }
        cout = 10 * cout + digit[i] - sum;
    }
}

void print(){
    for(int i = 0; i < N; i++){
        if(i > 0)
            cout << ' ';
        cout << lucky[i];
    }
    cout << endl;
}

int main(){
    int test;
    cin >> test;
    for(int i = 0; i < test; i++){
        Integer n;
        cin >> n;
        add(n);
        init();
        //debug();
        if(possible()){
            find();
            print();
        }
        else
            cout << -1 << endl;
    }
    return 0;
}

//hello


#include<bits/stdc++.h>
using namespace std;
char beau[3]={'0','4','7'};
string s;
string s1,s2,s3,s4,s5,s6;
bool chk[20][20];

void fix(string r) {
    while(r[0]=='0' && r.size()>1) r.erase(0,1);
    for(int i=0;i<r.size();i++) cout<<r[i];
    cout<<' ';
}

bool f(int n,int carry) {
    if(n==s.size()) {
        if(carry==0) return true;
        else return false;
    }
    if(chk[n][carry]) return false;
    chk[n][carry]=1;
    for(int i=0;i<3;i++)
        for(int j=0;j<3;j++)
            for(int k=0;k<3;k++)
                for(int q=0;q<3;q++)
                    for(int w=0;w<3;w++)
                        for(int e=0;e<3;e++) {
                            int z=beau[i]-'0'+beau[j]-'0'+beau[k]-'0'+beau[q]-'0'+beau[w]-'0'+beau[e]-'0'+carry;
                            if(s[n]-'0'==z%10 && f(n+1,z/10)) {
                                s1+=beau[i];
                                s2+=beau[j];
                                s3+=beau[k];
                                s4+=beau[q];
                                s5+=beau[w];
                                s6+=beau[e];
                                return true;
                            }
                        }
    return false;
}

int main() {
    int t; cin>>t;
    for(int i=1;i<=t;i++) {
        memset(chk,0,sizeof(chk));
        cin>>s;
        reverse(s.begin(),s.end());
        s1=s2=s3=s4=s5=s6="";
        if(!f(0,0)) { cout<<-1<<endl; continue; }
        else {
            fix(s1); fix(s2); fix(s3); fix(s4); fix(s5); fix(s6);
            cout<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
char beau[3]={'0','4','7'};
string s;
string s1,s2,s3,s4,s5,s6;
bool chk[20][20];

bool f(int n,int carry) {
    if(n==s.size()) {
        if(carry==0) return true;
        else return false;
    }
    if(chk[n][carry]) return false;
    chk[n][carry]=1;
    for(int i=0;i<3;i++)
        for(int j=0;j<3;j++)
            for(int k=0;k<3;k++)
                for(int q=0;q<3;q++)
                    for(int w=0;w<3;w++)
                        for(int e=0;e<3;e++) {
                            int z=beau[i]-'0'+beau[j]-'0'+beau[k]-'0'+beau[q]-'0'+beau[w]-'0'+beau[e]-'0'+carry;
                            if(s[n]-'0'==z%10 && f(n+1,z/10)) {
                                s1+=beau[i];
                                s2+=beau[j];
                                s3+=beau[k];
                                s4+=beau[q];
                                s5+=beau[w];
                                s6+=beau[e];
                                return true;
                            }
                        }
    return false;
}

int main() {
    int t; cin>>t;
    for(int i=1;i<=t;i++) {
        memset(chk,0,sizeof(chk));
        cin>>s;
        reverse(s.begin(),s.end());
        s1=s2=s3=s4=s5=s6="";
        if(!f(0,0)) { cout<<-1<<endl; continue; }
        else {
            cout<<s1<<' '<<s2<<' '<<s3<<' '<<s4<<' '<<s5<<' '<<s6<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int t;
bool vis[20][10];
vector<int>v;
int l;
long long n;
vector<int>ans[6];
void add(int s,int f)
{
    for(int i=0;i<6;++i)ans[i].push_back(0);
    for(int i=0;i<s;++i)ans[i].back()+=7;
    for(int i=s;i<s+f;++i)ans[i].back()+=4;
}
void print()
{
    for(int i=0;i<6;++i)
    {
        for(int j=ans[i].size()-1;j>=0;--j)
            printf("%d",ans[i][j]);
        printf(" ");
    }
    printf("\n");
}
bool check(int i,int ex)
{
    if(vis[i][ex])return false;
    vis[i][ex]=true;
    if(i==0)
    {
        for(int s=0;s<=6;++s)
            for(int f=0;s+f<=6;++f)
            {
                int num=(s*7)+(f*4);
                if(num%10==v[0]&&num/10==ex)
                {
                    add(s,f);
                    return true;
                }
            }
        return false;
    }
    for(int s=0;s<=6;++s)
            for(int f=0;s+f<=6;++f)
            {
                for(int prev=0;prev<=9;++prev)
                {
                    int num=(s*7)+(f*4)+prev;
                    if(num%10==v[i]&&num/10==ex)
                    {
                        bool x=check(i-1,prev);
                        if(x)
                        {
                            add(s,f);
                            return true;
                        }
                    }
                }
            }
    return false;
}
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%I64d",&n);
        memset(vis,0,sizeof vis);
        for(int i=0;i<6;++i)ans[i].clear();
        v.clear();
        long long x=n;
        while(x)
        {
            v.push_back(x%10);
            x/=10;
        }
        l=v.size();
        x=false;
        x=check(l-1,0);
        if(x)
        {
            print();
            continue;
        }
        if(l>=2)
        {
            x=check(l-2,v[l-1]);
            if(x)
            {
                print();
                continue;
            }
        }
        puts("-1");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t;
bool vis[20][10];
vector<int>v;
int l;
long long n;
vector<int>ans[6];
void add(int s,int f)
{
    for(int i=0;i<6;++i)ans[i].push_back(0);
    for(int i=0;i<s;++i)ans[i].back()+=7;
    for(int i=s;i<s+f;++i)ans[i].back()+=4;
}
void print()
{
    for(int i=0;i<6;++i)
    {
        long long x=0;
        for(int j=ans[i].size()-1;j>=0;--j)
            x=(x*10)+ans[i][j];
        printf("%I64d ",x);
    }
    printf("\n");
}
bool check(int i,int ex)
{
    if(vis[i][ex])return false;
    vis[i][ex]=true;
    if(i==0)
    {
        for(int s=0;s<=6;++s)
            for(int f=0;s+f<=6;++f)
            {
                int num=(s*7)+(f*4);
                if(num%10==v[0]&&num/10==ex)
                {
                    add(s,f);
                    return true;
                }
            }
        return false;
    }
    for(int s=0;s<=6;++s)
            for(int f=0;s+f<=6;++f)
            {
                for(int prev=0;prev<=9;++prev)
                {
                    int num=(s*7)+(f*4)+prev;
                    if(num%10==v[i]&&num/10==ex)
                    {
                        bool x=check(i-1,prev);
                        if(x)
                        {
                            add(s,f);
                            return true;
                        }
                    }
                }
            }
    return false;
}
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%I64d",&n);
        memset(vis,0,sizeof vis);
        for(int i=0;i<6;++i)ans[i].clear();
        v.clear();
        long long x=n;
        while(x)
        {
            v.push_back(x%10);
            x/=10;
        }
        l=v.size();
        x=false;
        x=check(l-1,0);
        if(x)
        {
            print();
            continue;
        }
        if(l>=2)
        {
            x=check(l-2,v[l-1]);
            if(x)
            {
                print();
                continue;
            }
        }
        puts("-1");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t;
bool vis[20][10];
vector<int>v;
int l;
long long n;
long long ans[6];
long long rev(long long x)
{
    long long ans=0;
    while(x)
    {
        ans*=10;
        ans+=(x%10);
        x/=10;
    }
    return ans;
}
void add(int s,int f)
{
    for(int i=0;i<6;++i)ans[i]*=10;
    for(int i=0;i<s;++i)ans[i]+=7;
    for(int i=s;i<s+f;++i)ans[i]+=4;
}
bool check(int i,int ex)
{
    if(vis[i][ex])return false;
    vis[i][ex]=true;
    if(i==0)
    {
        for(int s=0;s<=6;++s)
            for(int f=0;s+f<=6;++f)
            {
                int num=(s*7)+(f*4);
                if(num%10==v[0]&&num/10==ex)
                {
                    add(s,f);
                    return true;
                }
            }
        return false;
    }
    for(int s=0;s<=6;++s)
            for(int f=0;s+f<=6;++f)
            {
                for(int prev=0;prev<=9;++prev)
                {
                    int num=(s*7)+(f*4)+prev;
                    if(num%10==v[i]&&num/10==ex)
                    {
                        bool x=check(i-1,prev);
                        if(x)
                        {
                            add(s,f);
                            return true;
                        }
                    }
                }
            }
    return false;
}
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%I64d",&n);
        memset(vis,0,sizeof vis);
        memset(ans,0,sizeof ans);
        v.clear();
        long long x=n;
        while(x)
        {
            v.push_back(x%10);
            x/=10;
        }
        l=v.size();
        x=false;
        x=check(l-1,0);
        if(x)
        {
            for(int i=0;i<6;++i)printf("%I64d ",rev(ans[i]));
            printf("\n");
            continue;
        }
        if(l>=2)
        {
            x=check(l-2,v[l-1]);
            if(x)
            {
                for(int i=0;i<6;++i)printf("%I64d ",rev(ans[i]));
                printf("\n");
                continue;
            }
        }
        puts("-1");
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <map>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
using namespace std;

vector<int> carry[10];
vector<string> column[10];

int lucky[] = { 0, 4, 7};

string number;

vector<string> answerColumns;

void init(int i, string s, int sum)
{
	if (i == 6)
	{
		carry[sum%10].push_back(sum / 10);
		column[sum%10].push_back(string(s));
		return;
	}

	for (int j = 0; j < 3; j++)
	{
		s[i] = '0' + lucky[j];
		if((i == 0) || ((i - 1) >= 0 && s[i - 1] <= s[i]))
			init(i + 1, s, sum + lucky[j]);
	}
}

bool solve(int i, int mem)
{
	if (i == -1)
	{
		if(mem == 0)
		{
			return true;
		}
		return false;
	}

	int x = number[i] - '0' - mem;
	if(x < 0)
	{
		x += 10;
		mem = 1;
	}
	else
		mem = 0;

	for (int j = 0; j < carry[x].size(); j++)
	{
		answerColumns[i] = column[x][j];
		if(solve(i - 1, carry[x][j] + mem))
		{
			return true;
		}
	}

	return false;
}

int main()
{
#if _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int n;

	string s = "000000";

	init(0, s, 0);

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> number;
		answerColumns.resize(number.length());
		if(solve(number.size() - 1, 0))
		{
			for (int i = 0; i < 6; i++)
			{
				long long x = 0;
				for (int j = 0; j < number.size(); j++)
				{
					x = x * 10 + answerColumns[j][i] - '0';
				}
				cout << x << " ";
			}
			cout << endl;
		}
		else
			cout << "-1" << endl;
	}
}


#include <iostream>
#include <fstream>
#include <map>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
using namespace std;

vector<int> carry[10];
vector<string> column[10];

int lucky[] = { 0, 4, 7};

string number;

vector<string> answerColumns;

void init(int i, string s, int sum)
{
	if (i == 6)
	{
		carry[sum%10].push_back(sum / 10);
		column[sum%10].push_back(string(s));
		return;
	}

	for (int j = 0; j < 3; j++)
	{
		s[i] = '0' + lucky[j];
		if((i == 0) || ((i - 1) >= 0 && s[i - 1] <= s[i]))
			init(i + 1, s, sum + lucky[j]);
	}
}

bool solve(int i, int mem)
{
	if (i == -1)
	{
		if(mem == 0)
		{
			return true;
		}
		return false;
	}

	int x = number[i] - '0' - mem;
	if(x < 0)
	{
		x += 10;
		mem = 1;
	}
	else
		mem = 0;

	for (int j = 0; j < carry[x].size(); j++)
	{
		answerColumns[i] = column[x][j];
		if(solve(i - 1, carry[x][j] + mem))
		{
			return true;
		}
	}

	return false;
}

int main()
{
#if _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int n;

	string s = "000000";

	init(0, s, 0);

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> number;
		answerColumns.resize(number.length());
		if(solve(number.size() - 1, 0))
		{
			for (int i = 0; i < 6; i++)
			{
				int x = 0;
				for (int j = 0; j < number.size(); j++)
				{
					x = x * 10 + answerColumns[j][i] - '0';
				}
				cout << x << " ";
			}
			cout << endl;
		}
		else
			cout << "-1" << endl;
	}
}


#include <iostream>
#define Integer long long int

using namespace std;

const int D = 19;
const int C = 5; // upper_bound for maximum carry
const int S = 729;
const int N = 6;
int num;
int digit[D + 1];
bool dp[D + 1][C];
int ans[D + 1][C];
Integer lucky[N];

void add(Integer n){
    int cnt = 0;
    while(n > 0){
        cnt++;
        digit[cnt] = n % 10;
        n /= 10;
    }
    num = cnt;
}

int column(int state){
    int res = 0;
    while(state > 0){
        int d = state % 3;
        if(d > 0)
            d += 2 * d + 1;
        res *= 10;
        res += d;
        state /= 3;
    }
    return res;
}

void preprocess(){
    dp[0][0] = true;
    for(int cout = 1; cout < C; cout++)
        dp[0][cout] = false;
}

void init(){
    preprocess();
    for(int i = 1; i <= num; i++){
        int dig = digit[i];
        for(int cout = 0; cout < C; cout++){
            dp[i][cout] = false;
            for(int s = 0; s < S; s++){
                int col = column(s);
                int sum = 0;
                while(col > 0){
                    sum += col % 10;
                    col /= 10;
                }
                int val = 10 * cout + dig;
                int cin = val - sum;
                if(cin >= 0 && cin < C && dp[i - 1][cin]){
                    dp[i][cout] = true;
                    ans[i][cout] = s;
                    break;
                }
            }
        }
    }
}

void debug(){
    boolalpha(cerr);
    for(int i = 0; i <= num; i++)
        for(int c = 0; c < C; c++)
            cerr << "dp[" << i << "][" << c << "] = " << dp[i][c] << endl;
}

bool possible(){
    return dp[num][0];
}

void find(){
    for(int i = 0; i < N; i++)
        lucky[i] = 0;
    int cout = 0;
    for(int i = num; i > 0; i--){
        int s = ans[i][cout];
        int c = column(s);
        int sum = 0;
        for(int j = 0; j < N; j++){
            int dig = c % 10;
            c /= 10;
            sum += dig;
            lucky[j] *= 10;
            lucky[j] += dig;
        }
        cout = 10 * cout + digit[i] - sum;
    }
}

void print(){
    for(int i = 0; i < N; i++){
        if(i > 0)
            cout << ' ';
        cout << lucky[i];
    }
    cout << endl;
}

int main(){
    int test;
    cin >> test;
    for(int i = 0; i < test; i++){
        Integer n;
        cin >> n;
        add(n);
        init();
        //debug();
        if(possible()){
            find();
            print();
        }
        else
            cout << -1 << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define lol long long
#define fi first
#define se second
#define pb push_back
#define sz(s) (lol)s.size()
#define must ios_base::sync_with_stdio(0)

#define inp(s) freopen(s, "r", stdin)
#define out(s) freopen(s, "w", stdout)

int a[50];
int r[50][10];
int dd[] = {0, 4, 7};
lol ans[7];
int d[20][5];
int p[20][5];

void rec() {
    int i, j, k, ii, jj, kk;
    for(i = 0; i < 3; i++)
        for(j = 0; j  < 3; j++)
            for(k = 0; k  < 3; k++)
                for(ii= 0; ii < 3;ii++)
                    for(jj= 0; jj < 3;jj++)
                        for(kk= 0; kk < 3;kk++) {
                            lol sum = dd[i] + dd[j] + dd[k] + dd[ii] + dd[jj] + dd[kk];
                            a[sum] = 1;
                            r[sum][0] = dd[i];
                            r[sum][1] = dd[j];
                            r[sum][2] = dd[k];
                            r[sum][3] = dd[ii];
                            r[sum][4] = dd[jj];
                            r[sum][5] = dd[kk];
                        }
//    for(i = 0; i <= 45; i++) {
//        cout << i << "=";
//        for(j = 0; j <= 5; j++)
//            cout << r[i][j] << ' ';
//        cout << "\n";
//    }
}

int main() {
//    freopen("input.txt", "r", stdin);
    rec();
    lol n, it, i, t, dt, j, cur;
    cin >> n;
    for(it = 1; it <= n; it++) {
        cin >> t;
        dt = 0;
        memset(d, 0, sizeof(d));
        d[1][0] = 1;
        cur = 1;
        while(t) {
            for(i = 0; i <= 4; i++) {
                if(!d[cur][i])
                    continue;
                for(j = 0; j <= 4; j++) {
                    if(j * 10 + t % 10 - i >= 0 && a[j * 10 + t % 10 - i])
                        d[cur + 1][j] = 1, p[cur + 1][j] = i;
                }
            }
            dt = dt * 10 + t % 10;
            t /= 10;
            cur++;

        }
//        for(i = 1; i <= cur; i++, cout << "\n")
//            for(j = 0; j <= 4; j++)
//                cout << d[i][j] << "\t";
//        cout << "END\n";
//        for(i = 1; i <= cur; i++, cout << "\n")
//            for(j = 0; j <= 4; j++)
//                cout << p[i][j] << "\t";
//        cout << "\n";
        if(!d[cur][0])
            cout << "-1\n";
        else {
            memset(ans, 0, sizeof(ans));
            j = 0;
            while(cur > 1) {
                t = dt % 10;
                dt /= 10;
//                cout << cur << ' ' << j << ' ' << p[cur][j] << "\n\t";
                lol gt = j * 10 + t - p[cur][j];
//                cout << "gt= " << gt << "\n";
                for(i = 0; i < 6; i++)
                    ans[i] = ans[i] * 10 + r[gt][i];
                cur--;
                j = p[cur + 1][j];
            }
            for(i = 0; i < 6; i++)
                cout << ans[i] << ' ';
            cout << "\n";
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef long long ll;

int ar[19];
int pre[19][10];
int comb[19][10];
bool DP[19][10];
int digit[6][19];

ll get(int idx) {
  ll res = 0;
  ll cpow = 1;
  for (int i = 0; i < 19; ++i) {
    res += cpow * digit[idx][i];
    cpow *= 10;
  }
  return res;
}

int getdigit(int x) {
  if (x == 0) return 0;
  if (x == 1) return 4;
  if (x == 2) return 7;
  return -1;
}

bool solve(ll N) {
  memset(DP, false, sizeof(DP));
  memset(ar, 0, sizeof(ar));
  memset(pre, 0, sizeof(pre));
  memset(comb, 0, sizeof(comb));
  memset(digit, 0, sizeof(digit));
  for (int i = 0; i < 19; ++i) {
    ar[i] = N % 10;
    N /= 10;
  }

  for (int i = 0; i < 729; ++i) {
    int tmp = i;
    int sum = 0;
    for (int k = 0; k < 6; ++k) {
      sum += getdigit(tmp % 3);
      tmp /= 3;
    }
    if (sum % 10 == ar[0]) {
      DP[0][sum / 10] = true;
      comb[0][sum / 10] = i;
    }
  }

  for (int i = 0; i < 18; ++i) {
    for (int k = 0; k < 10; ++k) {
      if (DP[i][k]) {
        for (int a = 0; a < 729; ++a) {
          int tmp = a;
          int sum = 0;
          for (int b = 0; b < 6; ++b) {
            sum += getdigit(tmp % 3);
            tmp /= 3;
          }
          sum += k;
          if (sum % 10 == ar[i + 1]) {
            DP[i + 1][sum / 10] = true;
            comb[i + 1][sum / 10] = a;
            pre[i + 1][sum / 10] = k;
          }
        }
      }
    }
  }

  if (DP[18][0]) {
    int carry = 0;
    for (int i = 18; i >= 0; --i) {
      int cur = comb[i][carry];
      for (int k = 0; k < 6; ++k) {
        digit[k][i] = getdigit(cur % 3);
        cur /= 3;
      }
      carry = pre[i][carry];
    }
  } else {
    return false;
  }
  return true;
}

int main() {
  int T; cin >> T;
  for (int i = 0; i < T; ++i) {
    ll N; cin >> N;
    if (solve(N)) {
      for (int k = 0; k < 6; ++k) {
        cout << get(k) << ' ';
      }
    } else {
      cout << "-1";
    }
    cout << '\n';
  }
  return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef long long ll;

int ar[19];
int pre[19][10];
int comb[19][10];
bool DP[19][10];
int digit[6][19];

ll get(int idx) {
  ll res = 0;
  ll cpow = 1;
  for (int i = 0; i < 19; ++i) {
    res += cpow * digit[idx][i];
    cpow *= 10;
  }
  return res;
}

int getdigit(int x) {
  if (x == 0) return 0;
  if (x == 1) return 4;
  if (x == 2) return 7;
  return -1;
}

bool solve(ll N) {
  memset(DP, false, sizeof(DP));
  memset(ar, 0, sizeof(ar));
  for (int i = 0; i < 19; ++i) {
    ar[i] = N % 10;
    N /= 10;
  }

  for (int i = 0; i < 729; ++i) {
    int tmp = i;
    int sum = 0;
    for (int k = 0; k < 6; ++k) {
      sum += getdigit(tmp % 3);
      tmp /= 3;
    }
    if (sum % 10 == ar[0]) {
      DP[0][sum / 10] = true;
      comb[0][sum / 10] = i;
    }
  }

  for (int i = 0; i < 18; ++i) {
    for (int k = 0; k < 10; ++k) {
      if (DP[i][k]) {
        for (int a = 0; a < 729; ++a) {
          int tmp = a;
          int sum = 0;
          for (int b = 0; b < 6; ++b) {
            sum += getdigit(tmp % 3);
            tmp /= 3;
          }
          sum += k;
          if (sum % 10 == ar[i + 1]) {
            DP[i + 1][sum / 10] = true;
            comb[i + 1][sum / 10] = a;
            pre[i + 1][sum / 10] = k;
            break;
          }
        }
      }
    }
  }

  if (DP[18][0]) {
    int carry = 0;
    for (int i = 18; i >= 0; --i) {
      int cur = comb[i][carry];
      for (int b = 0; b < 6; ++b) {
        digit[b][i] = getdigit(cur % 3);
        cur /= 3;
      }
      carry = pre[i][carry];
    }
  } else {
    return false;
  }
  return true;
}

int main() {
  int T; cin >> T;
  for (int i = 0; i < T; ++i) {
    ll N; cin >> N;
    if (solve(N)) {
      for (int i = 0; i < 6; ++i) {
        cout << get(i) << ' ';
      }
    } else {
      cout << "-1";
    }
    cout << '\n';
  }
  return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef long long ll;

int ar[19];
int pre[19][10];
int comb[19][10];
bool DP[19][10];
int digit[6][19];

ll get(int idx) {
  ll res = 0;
  ll cpow = 1;
  for (int i = 0; i < 19; ++i) {
    res += cpow * digit[idx][i];
    cpow *= 10;
  }
  return res;
}

int getdigit(int x) {
  if (x == 0) return 0;
  if (x == 1) return 4;
  if (x == 2) return 7;
  return -1;
}

bool solve(ll N) {
  memset(DP, false, sizeof(DP));
  memset(ar, 0, sizeof(ar));
  memset(pre, 0, sizeof(pre));
  memset(comb, 0, sizeof(comb));
  memset(digit, 0, sizeof(digit));
  for (int i = 0; i < 19; ++i) {
    ar[i] = N % 10;
    N /= 10;
  }

  for (int i = 0; i <= 6; ++i) {
    for (int k = 0; k <= 6 - i; ++k) {
      int sum = i * 7 + k * 4;
      if (sum % 10 == ar[0]) {
        DP[0][sum / 10] = true;
        comb[0][sum / 10] = i * 10 + k;
      }
    }
  }

  for (int i = 0; i < 18; ++i) {
    for (int k = 0; k < 10; ++k) {
      if (DP[i][k]) {
        for (int a = 0; a <= 6; ++a) {
          for (int b = 0; b <= 6 - a; ++b) {
            int sum = a * 7 + b * 4 + k;
            if (sum % 10 == ar[i + 1]) {
              DP[i + 1][sum / 10] = true;
              comb[i + 1][sum / 10] = a * 10 + b;
              pre[i + 1][sum / 10] = k;
            }
          }
        }
      }
    }
  }

  if (DP[18][0]) {
    int carry = 0;
    for (int i = 18; i >= 0; --i) {
      int num = comb[i][carry];
      int cur = 0;
      for (int k = 0; k < num / 10; ++k) {
        digit[cur][i] = 7;
        ++cur;
      }
      for (int k = 0; k < num % 10; ++k) {
        digit[cur][i] = 4;
        ++cur;
      }
      for (int k = cur; k < 6; ++k) {
        digit[k][i] = 0;
      }
      carry = pre[i][carry];
    }
  } else {
    return false;
  }
  return true;
}

int main() {
  int T; cin >> T;
  for (int i = 0; i < T; ++i) {
    ll N; cin >> N;
    if (solve(N)) {
      for (int k = 0; k < 6; ++k) {
        cout << get(k) << ' ';
      }
    } else {
      cout << "-1";
    }
    cout << '\n';
  }
  return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef long long ll;

int ar[19];
int pre[19][10];
int comb[19][10];
bool DP[19][10];
int digit[6][19];

ll get(int idx) {
  ll res = 0;
  ll cpow = 1;
  for (int i = 0; i < 19; ++i) {
    res += cpow * digit[idx][i];
    cpow *= 10;
  }
  return res;
}

int getdigit(int x) {
  if (x == 0) return 0;
  if (x == 1) return 4;
  if (x == 2) return 7;
  return -1;
}

bool solve(ll N) {
  memset(DP, false, sizeof(DP));
  memset(ar, 0, sizeof(ar));
  memset(pre, 0, sizeof(pre));
  memset(comb, 0, sizeof(comb));
  memset(digit, 0, sizeof(digit));
  for (int i = 0; i < 19; ++i) {
    ar[i] = N % 10;
    N /= 10;
  }

  for (int i = 0; i < 729; ++i) {
    int tmp = i;
    int sum = 0;
    for (int k = 0; k < 6; ++k) {
      sum += getdigit(tmp % 3);
      tmp /= 3;
    }
    if (sum % 10 == ar[0]) {
      DP[0][sum / 10] = true;
      comb[0][sum / 10] = i;
    }
  }

  for (int i = 0; i < 18; ++i) {
    for (int k = 0; k < 10; ++k) {
      if (DP[i][k]) {
        for (int a = 0; a < 729; ++a) {
          int tmp = a;
          int sum = 0;
          for (int b = 0; b < 6; ++b) {
            sum += getdigit(tmp % 3);
            tmp /= 3;
          }
          sum += k;
          if (sum % 10 == ar[i + 1]) {
            DP[i + 1][sum / 10] = true;
            comb[i + 1][sum / 10] = a;
            pre[i + 1][sum / 10] = k;
            break;
          }
        }
      }
    }
  }

  if (DP[18][0]) {
    int carry = 0;
    for (int i = 18; i >= 0; --i) {
      int cur = comb[i][carry];
      for (int b = 0; b < 6; ++b) {
        digit[b][i] = getdigit(cur % 3);
        cur /= 3;
      }
      carry = pre[i][carry];
    }
  } else {
    return false;
  }
  return true;
}

int main() {
  int T; cin >> T;
  for (int i = 0; i < T; ++i) {
    ll N; cin >> N;
    if (solve(N)) {
      for (int k = 0; k < 6; ++k) {
        cout << get(k) << ' ';
      }
    } else {
      cout << "-1";
    }
    cout << '\n';
  }
  return 0;
}


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

typedef long long LL;

#define PII       pair<int,int>
#define all(c)    c.begin(),c.end()
#define sz(c)     (int)c.size()
#define clr(c)    c.clear()
#define pb        push_back
#define mp        make_pair
#define cin(x)    scanf("%d",&x)
#define MOD		1000000007
#define EPS		1E-10

vector<int> digs;
int dp[20][10];

void init(long long n)
{
	clr(digs);
	while(n)
	{
		digs.pb(n%10);
		n /= 10;
	}
	memset(dp,-1,sizeof(dp));
}

int solve(int idx, int carry)
{
	if(idx == sz(digs)) return (carry == 0);
	else if(dp[idx][carry] != -1) return dp[idx][carry];
	int ret = 0;
	for(int fours = 0; fours <= 6; fours++)
	{
		for(int seven = 0; seven <= (6 - fours); seven++)
		{
			int v = 4 * fours + 7 * (seven) + carry;
			int nc = v / 10;
			if(v%10 != digs[idx]) continue;
			ret |= solve(idx + 1, nc);
		}
	}
	return (dp[idx][carry] = ret);
}

long long pw[100];
vector<long long> ans(6,0);

void trace(int idx, int carry)
{
	if(idx == sz(digs)) return;

	for(int fours = 0; fours <= 6; fours++)
	{
		for(int seven = 0; seven <= (6 - fours); seven++)
		{
			int v = 4 * fours + 7 * seven + carry;
			int nc = v / 10;
			if(v%10 != digs[idx]) continue;
			if(!solve(idx + 1, nc)) continue;

			for(int i = 0; i < fours; i++)
				ans[i] += 4 * pw[idx];
			for(int i = fours; i < (fours + seven); i++)
				ans[i] += 7 * pw[idx];

			trace(idx + 1, nc);
			return;
		}
	}
}

int main()
{
	pw[0] = 1;
	for(int i = 1; i < 20; i++)
		pw[i] = pw[i - 1] * 10;
	int t;
	cin >> t;
	while(t--)
	{
		long long n;
		cin >> n;
		init(n);
		int poss = solve(0,0);
		if(!poss)
		{
			cout << "-1\n";
			continue;
		}
		for(auto &i: ans)
			i = 0;
		trace(0,0);
		for(auto i: ans)
			cout << i << " ";
		cout << "\n";
	}
	return 0;
}


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

typedef long long LL;

#define PII       pair<int,int>
#define all(c)    c.begin(),c.end()
#define sz(c)     (int)c.size()
#define clr(c)    c.clear()
#define pb        push_back
#define mp        make_pair
#define cin(x)    scanf("%d",&x)
#define MOD		1000000007
#define EPS		1E-10

vector<int> digs;
int dp[20][10];

void init(long long n)
{
	clr(digs);
	while(n)
	{
		digs.pb(n%10);
		n /= 10;
	}
	memset(dp,-1,sizeof(dp));
}

int solve(int idx, int carry)
{
	if(idx == sz(digs)) return (carry == 0);
	else if(dp[idx][carry] != -1) return dp[idx][carry];
	int ret = 0;
	for(int fours = 0; fours <= 6; fours++)
	{
		for(int seven = 0; seven <= (6 - fours); seven++)
		{
			int v = 4 * fours + 7 * (seven) + carry;
			int nc = v / 10;
			if(v%10 != digs[idx]) continue;
			ret |= solve(idx + 1, nc);
		}
	}
	return (dp[idx][carry] = ret);
}

long long pw[100];
vector<int> ans(6,0);

void trace(int idx, int carry)
{
	if(idx == sz(digs)) return;

	for(int fours = 0; fours <= 6; fours++)
	{
		for(int seven = 0; seven <= (6 - fours); seven++)
		{
			int v = 4 * fours + 7 * seven + carry;
			int nc = v / 10;
			if(v%10 != digs[idx]) continue;
			if(!solve(idx + 1, nc)) continue;

			for(int i = 0; i < fours; i++)
				ans[i] += 4 * pw[idx];
			for(int i = fours; i < (fours + seven); i++)
				ans[i] += 7 * pw[idx];

			trace(idx + 1, nc);
			return;
		}
	}
}

int main()
{
	pw[0] = 1;
	for(int i = 1; i < 20; i++)
		pw[i] = pw[i - 1] * 10;
	int t;
	cin >> t;
	while(t--)
	{
		long long n;
		cin >> n;
		init(n);
		int poss = solve(0,0);
		if(!poss)
		{
			cout << "-1\n";
			continue;
		}
		for(auto &i: ans)
			i = 0;
		trace(0,0);
		for(auto i: ans)
			cout << i << " ";
		cout << "\n";
	}
	return 0;
}


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

typedef long long LL;

#define PII       pair<int,int>
#define all(c)    c.begin(),c.end()
#define sz(c)     (int)c.size()
#define clr(c)    c.clear()
#define pb        push_back
#define mp        make_pair
#define cin(x)    scanf("%d",&x)
#define MOD		1000000007
#define EPS		1E-10

vector<int> digs;
int dp[20][10][7];

void init(long long n)
{
	clr(digs);
	while(n)
	{
		digs.pb(n%10);
		n /= 10;
	}
	memset(dp,-1,sizeof(dp));
}

int solve(int idx, int carry, int nums)
{
	if(nums < 0) return 0;
	else if(idx == sz(digs)) return (carry == 0);
	else if(dp[idx][carry][nums] != -1) return dp[idx][carry][nums];
	int ret = solve(idx, carry, nums - 1);
	for(int fours = 0; fours <= nums; fours++)
	{
		int v = 4 * fours + 7 * (nums - fours) + carry;
		int nc = v / 10;
		if(v%10 != digs[idx]) continue;
		ret |= solve(idx + 1, nc, nums);
	}
	return (dp[idx][carry][nums] = ret);
}

long long pw[100];
vector<int> ans(6,0);

void trace(int idx, int carry, int nums)
{
	if(idx == sz(digs)) return;
	if(solve(idx, carry, nums - 1))
	{
		trace(idx, carry, nums - 1);
		return;
	}

	for(int fours = 0; fours <= nums; fours++)
	{
		int v = 4 * fours + 7 * (nums - fours) + carry;
		int nc = v / 10;
		if(v%10 != digs[idx]) continue;
		if(solve(idx + 1, nc, nums))
		{
			for(int i = 0; i < fours; i++)
				ans[i] += pw[idx] * 4;
			for(int i = fours; i < nums; i++)
				ans[i] += pw[idx] * 7;
			trace(idx + 1, nc, nums);
			return;
		}
	}
}

int main()
{
	pw[0] = 1;
	for(int i = 1; i < 20; i++)
		pw[i] = pw[i - 1] * 10;
	int t;
	cin >> t;
	while(t--)
	{
		long long n;
		cin >> n;
		init(n);
		int poss = solve(0,0,6);
		if(!poss)
		{
			cout << "-1\n";
			continue;
		}
		for(auto &i: ans)
			i = 0;
		trace(0,0,6);
		for(auto i: ans)
			cout << i << " ";
		cout << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<pair<int, int> > ans, now, sub[10];
bool over;

void construct(long long n) {
  if (n < 0) return;
  if (n == 0) {
    over = 1;
    ans = now;
    return;
  }
  long long t = n % 10;
  for (int k = 0; !over && k < (int)sub[t].size(); ++k) {
    int i = sub[t][k].first, j = sub[t][k].second;
    now.push_back(sub[t][k]);
    construct((n - i * 4 - j * 7) / 10);
    now.pop_back();
  }
}

int main() {
  for (int i = 0; i <= 6; ++i) {
    for (int j = 0; i + j <= 6; ++j) {
      sub[(i * 4 + j * 7) % 10].push_back(make_pair(i, j));
    }
  }
  int t;
  scanf("%d", &t);
  while (t--) {
    long long n;
    scanf("%lld", &n);
    over = 0;
    construct(n);
    if (!over) {
      printf("-1\n");
    }
    else {
      long long a[6];
      memset(a, 0, sizeof(a));
      for (int i = (int)ans.size() - 1; i >= 0; --i) {
        for (int j = 0; j < 6; ++j) {
          a[j] *= 10;
          if (j < ans[i].first) {
            a[j] += 4;
          }
          else if (j < ans[i].first + ans[i].second) {
            a[j] += 7;
          }
        }
      }
      for (int i = 0; i < 6; ++i) {
        printf("%lld%c", a[i], " \n"[i == 5]);
      }
    }
  }
  return 0;
}


#include<bits/stdc++.h>
#define rep(i,k,n) for(int i= (int) k;i< (int) n;i++)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;
const int limit = 1048576;
using namespace std;

bool get_sol(ll carry, ll ans, const vector<pair<ll, ll> >& pos, map<pair<ll, ll>, vector<ll> >& acc)
{
//    cout << "AA " << carry << " " << ans << endl;
    if(acc.count({carry, ans}))
        return true;
    ll ten_pow = 1;
    while(10 <= ans / ten_pow)
        ten_pow *= 10;
    ll target = 10 * carry + ans / ten_pow;
//    cout << carry << " " << ans << " " << target << " " << ten_pow << endl;
    if(ten_pow == 1)
    {
        if(pos[target] != make_pair(-1ll, -1ll ))
        {
//            cout << "BB" << endl;
            vector<ll>sol(6);
            rep(j, 0, pos[target].ft)
                sol[j] = 4;
            rep(j, pos[target].ft, pos[target].ft + pos[target].sd)
                sol[j] = 7;
            acc[{carry, ans}] = sol;
            return true;
        }
    }
    else
        rep(i, 0, 5)
            if(get_sol(i, ans % ten_pow, pos, acc))
                if(target >= i and pos[target - i] != make_pair(-1ll, -1ll))
                {
                    vector<ll> sol = acc[{i, ans % ten_pow}];
                    rep(j, 0, pos[target - i].ft)
                        sol[j] += ten_pow * 4;
                    rep(j, pos[target - i].ft, pos[target - i].ft + pos[target - i].sd)
                        sol[j] += ten_pow * 7;
                    acc[{carry, ans}] = sol;
                    return true;
                }

    return false;
}

int main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
    vector<pair<ll, ll> > pos(102, {-1, -1});
    rep(i, 0, 6)
        rep(j, 0, 7 - i)
            pos[4  * i + 7 * j] = {i, j};
    int t; cin >> t;
    map<pair<ll, ll>, vector<ll> >acc;
    while(t--)
    {
        ll n; cin >> n;
        vector<ll> sol(6);
        if(get_sol(0, n, pos, acc))
        {
            for(auto i : acc[{0, n}])
                cout << i << " ";
            cout << "\n";
        }
        else
            cout << "-1\n";
    }
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,k,n) for(int i= (int) k;i< (int) n;i++)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;
const int limit = 1048576;
using namespace std;

bool get_sol(ll carry, ll ans, const vector<pair<ll, ll> >& pos, map<pair<ll, ll>, vector<ll> >& acc)
{
//    cout << "AA " << carry << " " << ans << endl;
    if(acc.count({carry, ans}))
        return true;
    ll ten_pow = 1;
    while(10 <= ans / ten_pow)
        ten_pow *= 10;
    ll target = 10 * carry + ans / ten_pow;
//    cout << carry << " " << ans << " " << target << " " << ten_pow << endl;
    if(ten_pow == 1)
    {
        if(pos[target] != make_pair(-1ll, -1ll ))
        {
//            cout << "BB" << endl;
            vector<ll>sol(6);
            rep(j, 0, pos[target].ft)
                sol[j] = 4;
            rep(j, pos[target].ft, pos[target].ft + pos[target].sd)
                sol[j] = 7;
            acc[{carry, ans}] = sol;
            return true;
        }
    }
    else
        rep(i, 0, 5)
            if(get_sol(i, ans % ten_pow, pos, acc))
                if(target >= i and pos[target - i] != make_pair(-1ll, -1ll))
                {
                    vector<ll> sol = acc[{i, ans % ten_pow}];
                    rep(j, 0, pos[target - i].ft)
                        sol[j] += ten_pow * 4;
                    rep(j, pos[target - i].ft, pos[target - i].ft + pos[target - i].sd)
                        sol[j] += ten_pow * 7;
                    acc[{carry, ans}] = sol;
                    return true;
                }

    return false;
}

int main()
{
    ios_base::sync_with_stdio(0);
//	cin.tie(0);
    vector<pair<ll, ll> > pos(102, {-1, -1});
    rep(i, 0, 7)
        rep(j, 0, 7 - i)
            pos[4  * i + 7 * j] = {i, j};
    int t; cin >> t;
    map<pair<ll, ll>, vector<ll> >acc;
    while(t--)
    {
        ll n; cin >> n;
        vector<ll> sol(6);
        if(get_sol(0, n, pos, acc))
        {
            for(auto i : acc[{0, n}])
                cout << i << " ";
            cout << "\n";
        }
        else
            cout << "-1\n";
    }
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,k,n) for(int i= (int) k;i< (int) n;i++)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;
const int limit = 1048576;
using namespace std;

bool get_sol(ll carry, ll ans, vector<ll>& sol, const vector<pair<ll, ll> >& pos)
{
//    cout << "AA " << carry << " " << ans << endl;
    ll ten_pow = 1;
    while(ten_pow * 10 <= ans)
        ten_pow *= 10;
    ll target = 10 * carry + ans / ten_pow;
//    cout << carry << " " << ans << " " << target << " " << ten_pow << endl;
    if(ten_pow == 1)
    {
        if(pos[target] != make_pair(-1ll, -1ll ))
        {
//            cout << "BB" << endl;
            rep(j, 0, pos[target].ft)
                sol[j] = 4;
            rep(j, pos[target].ft, pos[target].ft + pos[target].sd)
                sol[j] = 7;
            return true;
        }
    }
    else
    {
        rep(i, 0, 5)
        {
            vector<ll>pref(6);
            if(get_sol(i, ans % ten_pow, pref, pos))
            {
                if(target >= i and pos[target - i] != make_pair(-1ll, -1ll))
                {
                    rep(j, 0, pos[target - i].ft)
                        pref[j] += ten_pow * 4;
                    rep(j, pos[target - i].ft, pos[target - i].ft + pos[target - i].sd)
                        pref[j] += ten_pow * 7;
                    sol = pref;
                    return true;
                }
            }
        }
    }
    return false;
}

int main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
    vector<pair<ll, ll> > pos(102, {-1, -1});
    rep(i, 0, 6)
        rep(j, 0, 7 - i)
            pos[4  * i + 7 * j] = {i, j};
    int t; cin >> t;
    while(t--)
    {
        ll n; cin >> n;
        vector<ll> sol(6);
        if(get_sol(0, n, sol, pos))
        {
            for(auto i : sol)
                cout << i << " ";
            cout << "\n";
        }
        else
            cout << "-1\n";
    }
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,k,n) for(int i= (int) k;i< (int) n;i++)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;
const int limit = 1048576;
using namespace std;

bool get_sol(ll carry, ll ans, vector<ll>& sol, const vector<pair<ll, ll> >& pos)
{
//    cout << "AA " << carry << " " << ans << endl;
    ll ten_pow = 1;
    while(10 <= ans / ten_pow)
        ten_pow *= 10;
    ll target = 10 * carry + ans / ten_pow;
//    cout << carry << " " << ans << " " << target << " " << ten_pow << endl;
    if(ten_pow == 1)
    {
        if(pos[target] != make_pair(-1ll, -1ll ))
        {
//            cout << "BB" << endl;
            rep(j, 0, pos[target].ft)
                sol[j] = 4;
            rep(j, pos[target].ft, pos[target].ft + pos[target].sd)
                sol[j] = 7;
            return true;
        }
    }
    else
    {
        rep(i, 0, 5)
        {
            vector<ll>pref(6);
            if(get_sol(i, ans % ten_pow, pref, pos))
            {
                if(target >= i and pos[target - i] != make_pair(-1ll, -1ll))
                {
                    rep(j, 0, pos[target - i].ft)
                        pref[j] += ten_pow * 4;
                    rep(j, pos[target - i].ft, pos[target - i].ft + pos[target - i].sd)
                        pref[j] += ten_pow * 7;
                    sol = pref;
                    return true;
                }
            }
        }
    }
    return false;
}

int main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
    vector<pair<ll, ll> > pos(102, {-1, -1});
    rep(i, 0, 6)
        rep(j, 0, 7 - i)
            pos[4  * i + 7 * j] = {i, j};
    int t; cin >> t;
    while(t--)
    {
        ll n; cin >> n;
        vector<ll> sol(6);
        if(get_sol(0, n, sol, pos))
        {
            for(auto i : sol)
                cout << i << " ";
            cout << endl;
        }
        else
            cout << "-1" << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,k,n) for(int i= (int) k;i< (int) n;i++)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;
const int limit = 1048576;
using namespace std;

bool get_sol(ll carry, ll ans, ll ten_pow, const vector<pair<ll, ll> >& pos, map<pair<ll, ll>, vector<ll> >& acc)
{
//    cout << "AA " << carry << " " << ans << endl;
    if(acc.count({carry, ans}))
        return true;
    ll target = 10 * carry + ans / ten_pow;
//    cout << carry << " " << ans << " " << target << " " << ten_pow << endl;
    if(ten_pow == 1)
    {
        if(pos[target] != make_pair(-1ll, -1ll ))
        {
//            cout << "BB" << endl;
            vector<ll>sol(6);
            rep(j, 0, pos[target].ft)
                sol[j] = 4;
            rep(j, pos[target].ft, pos[target].ft + pos[target].sd)
                sol[j] = 7;
            acc[{carry, ans}] = sol;
            return true;
        }
    }
    else
        rep(i, 0, 5)
            if(get_sol(i, ans % ten_pow, ten_pow / 10, pos, acc))
                if(target >= i and pos[target - i] != make_pair(-1ll, -1ll))
                {
                    vector<ll> sol = acc[{i, ans % ten_pow}];
                    rep(j, 0, pos[target - i].ft)
                        sol[j] += ten_pow * 4;
                    rep(j, pos[target - i].ft, pos[target - i].ft + pos[target - i].sd)
                        sol[j] += ten_pow * 7;
                    acc[{carry, ans}] = sol;
                    return true;
                }

    return false;
}

int main()
{
    ios_base::sync_with_stdio(0);
//	cin.tie(0);
    vector<pair<ll, ll> > pos(102, {-1, -1});
    rep(i, 0, 7)
        rep(j, 0, 7 - i)
            pos[4  * i + 7 * j] = {i, j};
    int t; cin >> t;
    map<pair<ll, ll>, vector<ll> >acc;
    while(t--)
    {
        ll n; cin >> n;
        ll ten_pow = 1;
        while(10 <= n / ten_pow)
            ten_pow *= 10;
        vector<ll> sol(6);
        if(get_sol(0, n, ten_pow, pos, acc))
        {
            for(auto i : acc[{0, n}])
                cout << i << " ";
            cout << "\n";
        }
        else
            cout << "-1\n";
    }
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,k,n) for(int i= (int) k;i< (int) n;i++)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;
const int limit = 1048576;
using namespace std;

bool get_sol(ll carry, ll ans, ll ten_pow, const vector<pair<ll, ll> >& pos, map<pair<pair<ll, ll>, ll>, vector<ll> >& acc)
{
//    cout << "\nAA " << carry << " " << ans << " " << ten_pow << endl;
    if(acc.count({{carry, ans}, ten_pow}))
        return true;
    ll target = 10 * carry + ans / ten_pow;
//    cout << "C " << carry << " A " << ans << " T " << target << " P " << ten_pow << endl;
    if(ten_pow == 1)
    {
        if(pos[target] != make_pair(-1ll, -1ll ))
        {
//            cout << "BB" << endl;
            vector<ll>sol(6);
            rep(j, 0, pos[target].ft)
                sol[j] = 4;
            rep(j, pos[target].ft, pos[target].ft + pos[target].sd)
                sol[j] = 7;
            acc[{{carry, ans}, ten_pow}] = sol;
            return true;
        }
    }
    else
        rep(i, 0, 5)
            if(get_sol(i, ans % ten_pow, ten_pow / 10, pos, acc))
                if(target >= i and pos[target - i] != make_pair(-1ll, -1ll))
                {
                    vector<ll> sol = acc[{{i, ans % ten_pow}, ten_pow / 10}];
                    rep(j, 0, pos[target - i].ft)
                        sol[j] += ten_pow * 4;
                    rep(j, pos[target - i].ft, pos[target - i].ft + pos[target - i].sd)
                        sol[j] += ten_pow * 7;
                    acc[{{carry, ans}, ten_pow}] = sol;
                    return true;
                }

    return false;
}

int main()
{
    ios_base::sync_with_stdio(0);
//	cin.tie(0);
    vector<pair<ll, ll> > pos(102, {-1, -1});
    rep(i, 0, 7)
        rep(j, 0, 7 - i)
            pos[4  * i + 7 * j] = {i, j};
    ll t; cin >> t;
    map<pair<pair<ll, ll>, ll>, vector<ll> >acc;
    rep(j, 1, t + 1)
    {
        ll n; cin >> n;
        ll ten_pow = 1;
        while(10 <= n / ten_pow)
            ten_pow *= 10;
        vector<ll> sol(6);
        if(get_sol(0, n, ten_pow, pos, acc))
        {
            for(auto i : acc[{{0, n}, ten_pow}])
                cout << i << " ";
            cout << "\n";
        }
        else
            cout << "-1\n";
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cassert>
#include <ctime>
#include <string>

using namespace std;

#ifdef _WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

typedef long double ld;

long long rdtsc() {
  long long tmp;
  asm("rdtsc" : "=A"(tmp));
  return tmp;
}

inline int myrand() {
  return abs((rand() << 15) ^ rand());
}

inline int rnd(int x) {
  return myrand() % x;
}

#define pb push_back
#define mp make_pair
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define sz(x) ((int)(x).size())
#define TASKNAME "text"

const int INF = (int)1e9 + 1;
const ld EPS = 1e-9;

const int maxn = 19 + 5;
char s[maxn + 1];
const int maxsh = 4;
int pr[maxn][maxsh + 1];
int prmore[maxn][maxsh + 1][2];

const int dig[2] = {4, 7};

const int m = 6;

bool solve() {
  if (scanf("%s", s) < 1) {
    return 0;
  }
  int n = (int)strlen(s);
  reverse(s, s + n);
  for (int put = 0; put <= n; ++put) {
    for (int sh = 0; sh <= maxsh; ++sh) {
      pr[put][sh] = -1;
    }
  }

  for (int put = 0; put < n; ++put) {
    for (int sh = 0; sh <= maxsh; ++sh) {
      if (put && pr[put][sh] == -1) {
        continue;
      }
      if (!put && sh != 0) {
        continue;
      }
      for (int c1 = 0; c1 <= m; ++c1) {
        for (int c2 = 0; c1 + c2 <= m; ++c2) {
          int val = c1 * dig[0] + c2 * dig[1] + sh;
          int r = val % 10, nsh = val / 10;
          if (r + '0' != s[put]) {
            continue;
          }
          if (pr[put + 1][nsh] == -1) {
            pr[put + 1][nsh] = sh;
            prmore[put + 1][nsh][0] = c1;
            prmore[put + 1][nsh][1] = c2;
          }
        }
      }
    }
  }

  if (pr[n][0] == -1) {
    printf("-1\n");
    return 1;
  }
  vector<int> res[m];
  for (int put = n, sh = 0; put > 0; --put) {
    int c1 = prmore[put][sh][0];
    int c2 = prmore[put][sh][1];
    for (int i = 0; i < c1; ++i) {
      res[i].pb(dig[0]);
    }
    for (int i = 0; i < c2; ++i) {
      res[i + c1].pb(dig[1]);
    }
    for (int i = c1 + c2; i < m; ++i) {
      res[i].pb(0);
    }
    sh = pr[put][sh];
  }
  for (int i = 0; i < m; ++i) {
    vector<int> &cur = res[i];
    bool first = 1;
    for (int j = 0; j < sz(cur); ++j) {
      if (cur[j] || j == sz(cur) - 1) {
        first = 0;
      }
      if (!first) {
        printf("%d", cur[j]);
      }
    }
    printf("%c", " \n"[i == m - 1]);
  }
  return 1;
}

int main() {
  srand(rdtsc());
#ifdef DEBUG
  freopen(TASKNAME".out", "w", stdout);
  assert(freopen(TASKNAME".in", "r", stdin));
#endif

  int maxt;
  while (scanf("%d", &maxt) == 1) {
    for (int t = 0; t < maxt; ++t) {
      assert(solve());
    }
#ifdef DEBUG
    eprintf("%.18lf\n", (double)clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

struct Data {
	int sum, num4, num7;

	bool operator<(const Data &b) const {
		if(sum != b.sum)	return sum < b.sum;
		if(num4 != b.num4)	return num4 < b.num4;
		return num7 < b.num7;
	}
	bool operator==(const Data &b) const {
		return sum==b.sum && num4==b.num4 && num7==b.num7;
	}
};
vector<Data> v;

void dfs(int cnt, int sum, int num4, int num7) {
	if(cnt == 6) {
		v.PB((Data) {sum, num4, num7});
		return ;
	}

	dfs(cnt+1, sum  , num4  , num7  );
	dfs(cnt+1, sum+4, num4+1, num7  );
	dfs(cnt+1, sum+7, num4  , num7+1);
}

int a[20], dp[10][20], cnt4[20], cnt7[20];

int main() {
	dfs(0, 0, 0, 0);
	sort(ALL(v));
	v.resize(unique(ALL(v))-v.begin());

	int t;
	scanf("%d", &t);
	while(t--) {
		ll x;
		scanf("%lld", &x);

		int len = 0;
		for(int i=0; i<20; i++) {
			a[i] = x%10;
			x/=10;
			if(a[i])	len = i;
		}

		memset(dp, -1, sizeof(dp));
		int m = SZ(v);
		for(int j=0; j<m; j++) {
			if(v[j].sum%10 == a[0])	dp[0][v[j].sum/10] = j;
		}
		for(int i=1; i<=len; i++) {
			for(int j=0; j<m; j++) {
				for(int k=0; k<10; k++) {
					if(dp[i-1][k] < 0)	continue;
					int tmp = v[j].sum+k;
					int x = tmp/10, y = tmp%10;
					if(y==a[i])	dp[i][x] = j;
				}
			}
		}

		if(dp[len][0] < 0) {
			puts("-1");
			continue;
		}

		int prv = 0;
		for(int i=len; i>=0; i--) {
			cnt4[i] = v[dp[i][prv]].num4;
			cnt7[i] = v[dp[i][prv]].num7;
			prv = a[i]-v[dp[i][prv]].sum%10;
		}

		ll pw10[20];
		pw10[0] = 1;
		for(int i=1; i<=len; i++)	pw10[i]=pw10[i-1]*10;
		for(int i=0; i<6; i++) {
			ll ans = 0;
			for(int i=0; i<=len; i++) {
				if(cnt4[i]) {
					cnt4[i]--;
					ans += 4*pw10[i];
				}
				else if(cnt7[i]) {
					cnt7[i]--;
					ans += 7*pw10[i];
				}
			}
			printf("%lld%c", ans, " \n"[i==5]);
		}
	}

    return 0;
}


#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

struct Data {
	int sum, num4, num7;

	bool operator<(const Data &b) const {
		if(sum != b.sum)	return sum < b.sum;
		if(num4 != b.num4)	return num4 < b.num4;
		return num7 < b.num7;
	}
	bool operator==(const Data &b) const {
		return sum==b.sum && num4==b.num4 && num7==b.num7;
	}
};
vector<Data> v;

void dfs(int cnt, int sum, int num4, int num7) {
	if(cnt == 6) {
		v.PB((Data) {sum, num4, num7});
		return ;
	}

	dfs(cnt+1, sum  , num4  , num7  );
	dfs(cnt+1, sum+4, num4+1, num7  );
	dfs(cnt+1, sum+7, num4  , num7+1);
}

int a[20], dp[20][20], cnt4[20], cnt7[20];

int main() {
	dfs(0, 0, 0, 0);
	sort(ALL(v));
	v.resize(unique(ALL(v))-v.begin());

	int t;
	scanf("%d", &t);
	while(t--) {
		ll x;
		scanf("%I64d", &x);

		int len = 0;
		for(int i=0; i<20; i++) {
			a[i] = x%10;
			x/=10;
			if(a[i])	len = i;
		}

		memset(dp, -1, sizeof(dp));
		int m = SZ(v);
		for(int j=0; j<m; j++) {
			if(v[j].sum%10 == a[0])	dp[0][v[j].sum/10] = j;
		}
		for(int i=1; i<=len; i++) {
			for(int j=0; j<m; j++) {
				for(int k=0; k<10; k++) {
					if(dp[i-1][k] < 0)	continue;
					int tmp = v[j].sum+k;
					int x = tmp/10, y = tmp%10;
					if(y==a[i])	dp[i][x] = j;
				}
			}
		}

		if(dp[len][0] < 0) {
			puts("-1");
			continue;
		}

		int prv = 0;
		for(int i=len; i>=0; i--) {
			cnt4[i] = v[dp[i][prv]].num4;
			cnt7[i] = v[dp[i][prv]].num7;
			prv = a[i]-v[dp[i][prv]].sum%10;
		}

		ll pw10[20];
		pw10[0] = 1;
		for(int i=1; i<=len; i++)	pw10[i]=pw10[i-1]*10;
		for(int i=0; i<6; i++) {
			ll ans = 0;
			for(int i=0; i<=len; i++) {
				if(cnt4[i]) {
					cnt4[i]--;
					ans += 4*pw10[i];
				}
				else if(cnt7[i]) {
					cnt7[i]--;
					ans += 7*pw10[i];
				}
			}
			printf("%I64d%c", ans, " \n"[i==5]);
		}
	}

    return 0;
}


#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

struct Data {
	int sum, num4, num7;

	bool operator<(const Data &b) const {
		if(sum != b.sum)	return sum < b.sum;
		if(num4 != b.num4)	return num4 < b.num4;
		return num7 < b.num7;
	}
	bool operator==(const Data &b) const {
		return sum==b.sum && num4==b.num4 && num7==b.num7;
	}
};
vector<Data> v;

void dfs(int cnt, int sum, int num4, int num7) {
	if(cnt == 6) {
		v.PB((Data) {sum, num4, num7});
		return ;
	}

	dfs(cnt+1, sum  , num4  , num7  );
	dfs(cnt+1, sum+4, num4+1, num7  );
	dfs(cnt+1, sum+7, num4  , num7+1);
}

int a[20], dp[20][20], cnt4[20], cnt7[20];

int main() {
	dfs(0, 0, 0, 0);
	sort(ALL(v));
	v.resize(unique(ALL(v))-v.begin());

	int t;
	scanf("%d", &t);
	while(t--) {
		ll x;
		scanf("%I64d", &x);

		int len = 0;
		for(int i=0; i<20; i++) {
			a[i] = x%10;
			x/=10;
			if(a[i])	len = i;
		}

		memset(dp, -1, sizeof(dp));
		int m = SZ(v);
		for(int j=0; j<m; j++) {
			if(v[j].sum%10 == a[0])	dp[0][v[j].sum/10] = j;
		}
		for(int i=1; i<=len; i++) {
			for(int j=0; j<m; j++) {
				for(int k=0; k<10; k++) {
					if(dp[i-1][k] < 0)	continue;
					int tmp = v[j].sum+k;
					int x = tmp/10, y = tmp%10;
					if(y==a[i])	dp[i][x] = j;
				}
			}
		}

		if(dp[len][0] < 0) {
			puts("-1");
			continue;
		}
		debug("%d|%d\n", dp[len-2][2], v[dp[len-2][2]].num4);

		int prv = 0;
		for(int i=len; i>=0; i--) {
			if(!i)	debug("%d|\n", prv);
			cnt4[i] = v[dp[i][prv]].num4;
			cnt7[i] = v[dp[i][prv]].num7;
			prv = (a[i]-v[dp[i][prv]].sum%10+10)%10;
		}

		ll pw10[20];
		pw10[0] = 1;
		for(int i=1; i<=len; i++)	pw10[i]=pw10[i-1]*10;
		for(int i=0; i<6; i++) {
			ll ans = 0;
			for(int i=0; i<=len; i++) {
				if(cnt4[i]) {
					cnt4[i]--;
					ans += 4*pw10[i];
				}
				else if(cnt7[i]) {
					cnt7[i]--;
					ans += 7*pw10[i];
				}
			}
			printf("%I64d%c", ans, " \n"[i==5]);
		}
	}

    return 0;
}


#include<bits/stdc++.h>
#define ft first
#define sd second
#define pb push_back
using namespace std;

typedef long long ll;

int t;
string s;
int n;
pair<int,int> wyn[20];
ll liczba[6];

bool odw[20][20];

bool rek(int k, int c){
  if(odw[k][c] == 1) return 1;
  if(odw[k][c] == -1) return 0;
  if(k == n){
    if(c == 0) return 1;
    else return 0;
  }
  int d = s[k] - '0';
  for(int i = 0; i <= 6; i++){
    for(int j = 0; j + i <= 6; j++){
      int q = i * 7 + j * 4;
      if(q / 10 == c and (10 + d - q) % 10 <= 4){
	if(rek(k + 1, (10 + d - q) % 10)){
	  wyn[k] = {i,j};
	  odw[k][c] = 1;
	  return 1;
	}
      }
    }
  }
  odw[k][c] = -1;
  return 0;
}

int main(){
  ios_base::sync_with_stdio(0);
  cin >> t;
  while(t--){
    for(int i = 0; i < 20; i++) for(int j = 0; j < 10; j++) odw[i][j] = 0;
    cin >> s;
    n = s.length();
    if(rek(0,0) == 0){
      cout<<"-1\n";
      continue;
    }
    //for(int i = 0; i < n; i++) cout<<wyn[i].ft << " " <<wyn[i].sd << endl;
    for(int i = 0; i < 6; i++) liczba[i] = 0;
      for(int i = 0; i < n; i++){
      for(int i = 0; i < 6; i++) liczba[i] *= 10;
      int k = 0;
      for(int j = 0; j < wyn[i].ft; j++){
	liczba[k] += 7;
	k++;
      }
      for(int j = 0; j < wyn[i].sd; j++){
	liczba[k] += 4;
	k++;
      }
    }
    for(int i = 0; i < 6; i++) cout<<liczba[i] << " ";
    cout<<"\n";
  }
}


#include<bits/stdc++.h>
#define ft first
#define sd second
#define pb push_back
using namespace std;

typedef long long ll;

int t;
string s;
int n;
pair<int,int> wyn[20];
ll liczba[6];

bool odw[20][20];

bool rek(int k, int c){
  if(odw[k][c] == 1) return 1;
  if(odw[k][c] == -1) return 0;
  if(k == n){
    if(c == 0) return 1;
    else return 0;
  }
  int d = s[k] - '0';
  for(int i = 0; i <= 6; i++){
    for(int j = 0; j + i <= 6; j++){
      int q = i * 7 + j * 4;
      if(q / 10 == c and d - q % 10 <= 4){
	if(rek(k + 1, d - q % 10)){
	  wyn[k] = {i,j};
	  odw[k][c] = 1;
	  return 1;
	}
      }
    }
  }
  odw[k][c] = -1;
  return 0;
}

int main(){
  ios_base::sync_with_stdio(0);
  cin >> t;
  while(t--){
    for(int i = 0; i < 20; i++) for(int j = 0; j < 10; j++) odw[i][j] = 0;
    cin >> s;
    n = s.length();
    if(rek(0,0) == 0){
      cout<<"-1\n";
      continue;
    }
    //for(int i = 0; i < n; i++) cout<<wyn[i].ft << " " <<wyn[i].sd << endl;
    for(int i = 0; i < 6; i++) liczba[i] = 0;
      for(int i = 0; i < n; i++){
      for(int i = 0; i < 6; i++) liczba[i] *= 10;
      int k = 0;
      for(int j = 0; j < wyn[i].ft; j++){
	liczba[k] += 7;
	k++;
      }
      for(int j = 0; j < wyn[i].sd; j++){
	liczba[k] += 4;
	k++;
      }
    }
    for(int i = 0; i < 6; i++) cout<<liczba[i] << " ";
    cout<<"\n";
  }
}


#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	if(n==2){
	    std::cout << "YES" << std::endl;
            return 0 ;
	}
	std::cin >> n;
    vector<int> a(n,0);
    while(n--){
        int node1;
        int node2;
        std::cin >>node1>>node2;
        a[node1]+=1;
        a[node2]+=1;
    }
    for(int i = 0 ; i < a.size() ; i++){
        if(a[i]<2){
            std::cout << "NO" << std::endl;
            return 0 ;
        }
    }
    std::cout << "YES" << std::endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	std::cin >> n;
	if(n==2){
	    std::cout << "YES" << std::endl;
            return 0 ;
	}
    vector<int> a(n,0);
    while(n--){
        int node1;
        int node2;
        std::cin >>node1>>node2;
        a[node1-1]+=1;
        a[node2-1]+=1;
    }
    for(int i = 0 ; i < a.size() ; i++){
        if(a[i]<2){
            std::cout << "NO" << std::endl;
            return 0 ;
        }
    }
    std::cout << "YES" << std::endl;

	return 0;
}