import java.util.*;
import java.io.*;

public class E {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
CAS:
        for(int cas=1; cas<=T; cas++) {
            long n = in.nextLong();

            long n4 = 0;
            long n7 = 0;
            long n28 = 0;

            if(n%4 == 0) {
                n4 = n/4;
                n7 = 0;
            } else if(n%4==1) {
                if(n < 21) {
                    System.out.println(-1);
                    continue CAS;
                }
                n4 = (n-21)/4;
                n7 = 3;
            } else if(n%4==2) {
                if(n < 14) {
                    System.out.println(-1);
                    continue CAS;
                }
                n4 = (n-14)/4;
                n7 = 2;
            } else if(n%4==3) {
                if(n < 7) {
                    System.out.println(-1);
                    continue CAS;
                }
                n4 = (n-7)/4;
                n7 = 1;
            }

            n28 = n4/7;
            n4 %= 7;

            if(f(n4+n28*7,n7)) continue CAS;
            if(f(n4,n7+n28*4)) continue CAS;

            System.out.println(-1);
        }
    }

    static boolean f(long n4, long n7) {
        long t1 = n4;
        long t2 = n7;

        int[] FOUR = new int[18];
        int[] SEVEN = new int[18];
        for(int pos=0; pos<18; pos++) {
            FOUR[pos] = (int)(t1%10);
            SEVEN[pos] = (int)(t2%10);
            if(FOUR[pos]+SEVEN[pos]>6) return false;
            t1 /= 10;
            t2 /= 10;
        }

        for(int i=0; i<6; i++) {
            int num = 0;
            long p10 = 1;
            for(int pos=0; pos<18; pos++) {
                if(FOUR[pos]>0) {
                    num += p10*4;
                    FOUR[pos]--;
                } else if(SEVEN[pos]>0) {
                    num += p10*7;
                    SEVEN[pos]--;
                }
                p10 *= 10;
            }
            System.out.print(num);
            System.out.print(i==5?'\n':' ');
        }
        return true;
    }
}
