import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // BEGIN initialize singles array
        int[] temp = new int[3];
        temp[0] = 0;
        temp[1] = 4;
        temp[2] = 7;
        HashMap<Integer, ArrayList<Integer>> singles = new HashMap<Integer, ArrayList<Integer>>();

        for (int i = 0; i < 43; i++) {
            if (!singles.containsKey(i)) {
                for (int j = 0; j < 3; j++) {
                    if (!singles.containsKey(i)) {
                        for (int k = j; k < 3; k++) {
                            if (!singles.containsKey(i)) {
                                for (int l = k; l < 3; l++) {
                                    if (!singles.containsKey(i)) {
                                        for (int m = l; m < 3; m++) {
                                            if (!singles.containsKey(i)) {
                                                for (int n = m; n < 3; n++) {
                                                    if (!singles.containsKey(i)) {
                                                        for (int o = n; o < 3; o++) {
                                                            if (temp[j]
                                                                    + temp[k]
                                                                    + temp[l]
                                                                    + temp[m]
                                                                    + temp[n]
                                                                    + temp[o] == i) {
                                                                if (!singles
                                                                        .containsKey(i)) {
                                                                    ArrayList tempList = new ArrayList<Integer>();
                                                                    tempList.add(temp[j]);
                                                                    tempList.add(temp[k]);
                                                                    tempList.add(temp[l]);
                                                                    tempList.add(temp[m]);
                                                                    tempList.add(temp[n]);
                                                                    tempList.add(temp[o]);
                                                                    singles.put(
                                                                            i,
                                                                            tempList);
                                                                } else {
                                                                    o = 3;
                                                                }
                                                            }
                                                        }
                                                    } else {
                                                        n = 3;
                                                    }
                                                }
                                            } else {
                                                m = 3;
                                            }
                                        }
                                    } else {
                                        l = 3;
                                    }
                                }
                            } else {
                                k = 3;
                            }
                        }
                    } else {
                        j = 3;
                    }
                }
            }
        }
        // END initialize singles array
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        for (int i = 0; i < t; i++) {
            char[] nString = in.next().toCharArray();
            int[] n = new int[nString.length];
            for (int j = 0; j < n.length; j++) {
                n[j] = Character.digit(nString[j], 10);
            }
            ArrayList<Integer> able = new ArrayList<Integer>();
            boolean foundIt = false;
            if (n[0] - 8 <= 4 && n[0] - 8 >= 0) {
                able.add(8);
            }
            if (n[0] - 7 <= 4 && n[0] - 7 >= 0) {
                able.add(7);
            }
            if (n[0] - 4 <= 4 && n[0] - 4 >= 0) {
                able.add(4);
            }
            if (n[0] - 0 <= 4 && n[0] - 0 >= 0) {
                able.add(0);
            }
            if(n.length > 1){
            ArrayList<Integer> answer = new ArrayList<Integer>();
            for (int j = 0; j < able.size(); j++) {
                int tens = n[0] - able.get(j);
                if (!foundIt) {
                    foundIt = f(n, tens, singles, 1, answer);
                    if (foundIt) {
                        answer.add(able.get(j));
                    }
                }
            }
            if (!foundIt) {
                System.out.println(-1);
            } else {
                long[] finalAnswer = new long[6];
                for (int j = 0; j < 6; j++) {
                    for (int k = 0; k < n.length; k++) {
                        finalAnswer[j] += singles.get(answer.get(k)).get(j)
                                * (long)Math.pow(10, k);
                    }
                    System.out.print(finalAnswer[j] + " ");
                }
            }
            }
            else{
                if(!singles.containsKey(n[0])){
                    System.out.println(-1);
                }
                else{
                    for(int j = 0; j < 6; j++){
                        System.out.print(singles.get(n[0]).get(j) + " ");
                    }
                }
            }
        }
    }

    public static boolean f(int[] n, int tens,
            HashMap<Integer, ArrayList<Integer>> singles, int current,
            ArrayList<Integer> answer) {
        boolean foundIt = false;

        if (current + 1 == n.length) {
            int tempNumber = tens * 10 + n[current];
            if (singles.containsKey(tempNumber)) {
                answer.add(tempNumber);
                return true;
            }
            return false;
        }

        ArrayList<Integer> able = new ArrayList<Integer>();
        for (int i = 0; i < 6 && i <= n[current]; i++) {
            int tempNumber = tens * 10 + n[current] - i;
            if (singles.containsKey(tempNumber)) {
                able.add(n[current] - i);
            }
        }
        int singlesDigit = 0;
        for (int i = 0; i < able.size(); i++) {
            if (!foundIt) {
                foundIt = f(n, n[current] - able.get(i), singles, current + 1,
                        answer);
                if (foundIt) {
                    singlesDigit = able.get(i);
                }
            }
        }
        // BEGIN take one and add 10
        if (!foundIt) {
            if (tens > 0) {
                tens -= 1;
                int tempDigit = n[current] + 10;
                able.clear();
                // BEGIN find able again
                for (int i = 0; i < 6 && i <= tempDigit; i++) {
                    if (tempDigit - i < 10) {
                        int tempNumber = tens * 10 + tempDigit - i;
                        if (singles.containsKey(tempNumber)) {
                            able.add(tempDigit - i);
                        }
                    }
                }
                // END find able again
                for (int i = 0; i < able.size(); i++) {
                    if (!foundIt) {
                        foundIt = f(n, tempDigit - able.get(i), singles,
                                current + 1, answer);
                        if (foundIt) {
                            singlesDigit = able.get(i);
                        }
                    }
                }
            }
        }
        // END take one and add 10
        if (foundIt) {
            answer.add(tens * 10 + singlesDigit);
        }
        return foundIt;
    }

}


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

import static java.util.Arrays.*;

public class E {
	private static final int mod = (int)1e9+7;

	final Random random = new Random(0);
	final IOFast io = new IOFast();

	int[] cnt = new int[10];
	int[] len = new int[10];
	int[][] pos = new int[10][];
	int[] map = new int[8*8];
	long[] ans = new long[6];

	boolean dfs(long v, long idx) {
		if(v == 0) return true;
		if(v < 0 || idx * 4 > v) return false;
		int k = (int)(v / idx % 10);

		for(int x : pos[k]) {
			if(dfs(v - map[x] * idx, idx * 10)) {
				final int i4 = x / 8;
				final int i7 = x % 8;
				for(int i = 0; i < i4; i++) { ans[i] += idx * 4; }
				for(int i = 0; i < i7; i++) { ans[i+i4] += idx * 7; }
				return true;
			}
		}
		return false;
	}

	public void run() throws IOException {
		for(int i = 0; i <= 6; i++){
			for(int j = 0; i + j <= 6; j++) {
				int v = 0;
				for(int k = 0; k < i; k++) v += 4;
				for(int k = 0; k < j; k++) v += 7;
				cnt[v%10]++;
			}
		}
		for(int i = 0; i < 10; i++) pos[i] = new int[cnt[i]];
		for(int i = 0; i <= 6; i++){
			for(int j = 0; i + j <= 6; j++) {
				int v = 0;
				for(int k = 0; k < i; k++) v += 4;
				for(int k = 0; k < j; k++) v += 7;
				pos[v%10][len[v%10]++] = i * 8 + j;
				map[i*8+j] = v;
			}
		}

		int t = io.nextInt();
		for(int i = 0; i < t; i++) {
			long v = io.nextLong();
			Arrays.fill(ans, 0);
			if(dfs(v, 1)) {
				for(int j = 0; j < 6; j++) {
					io.out.print(ans[j] + (j==5?"\n":" "));
				}
			}
			else {
				io.out.println(-1);
			}
		}
	}

	static void arrayIntSort(int[][] x, int key) {
		Arrays.sort(x, new IntArrayComparator(key));
	}

	static class IntArrayComparator implements Comparator<int[]> {
		final int KEY;

		public IntArrayComparator(int key) {
			KEY = key;
		}

		@Override
		public int compare(int[] o1, int[] o2) {
			return o1[KEY] - o2[KEY];
		}
	}

	void main() throws IOException {
		//		IOFast.setFileIO("rle-size.in", "rle-size.out");
		try {
			run();
		}
		catch (EndOfFileRuntimeException e) { }
		io.out.flush();
	}

	public static void main(String[] args) throws IOException {
		new E().main();
	}

	static class EndOfFileRuntimeException extends RuntimeException {
		private static final long serialVersionUID = -8565341110209207657L; }

	static
	public class IOFast {
		private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		private PrintWriter out = new PrintWriter(System.out);

		void setFileIO(String ins, String outs) throws IOException {
			in = new BufferedReader(new FileReader(ins));
			out = new PrintWriter(new FileWriter(outs));
		}

		//		private static final int BUFFER_SIZE = 50 * 200000;
		private static int pos, readLen;
		private static final char[] buffer = new char[1024 * 8];
		private static final char[] str = new char[500000*8*2];
		private static boolean[] isDigit = new boolean[256];
		private static boolean[] isSpace = new boolean[256];
		private static boolean[] isLineSep = new boolean[256];

		static {
			for(int i = 0; i < 10; i++) { isDigit['0' + i] = true; }
			isDigit['-'] = true;
			isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true;
			isLineSep['\r'] = isLineSep['\n'] = true;
		}

		public int read() throws IOException {
			if(pos >= readLen) {
				pos = 0;
				readLen = in.read(buffer);
				if(readLen <= 0) { throw new EndOfFileRuntimeException(); }
			}
			return buffer[pos++];
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(nextString());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(nextString());
		}

		public char nextChar() throws IOException {
			while(true) {
				final int c = read();
				if(!isSpace[c]) { return (char)c; }
			}
		}

		int reads(char[] cs, int len, boolean[] accept) throws IOException {
			try {
				while(true) {
					final int c = read();
					if(accept[c]) { break; }
					cs[len++] = (char)c;
				}
			}
			catch(EndOfFileRuntimeException e) { ; }

			return len;
		}

		public char[] nextLine() throws IOException {
			int len = 0;
			str[len++] = nextChar();
			len = reads(str, len, isLineSep);

			try {
				if(str[len-1] == '\r') { len--; read(); }
			}
			catch(EndOfFileRuntimeException e) { ; }

			return Arrays.copyOf(str, len);
		}

		public String nextString() throws IOException {
			return new String(next());
		}

		public char[] next() throws IOException {
			int len = 0;
			str[len++] = nextChar();
			len = reads(str, len, isSpace);
			return Arrays.copyOf(str, len);
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(nextString());
		}

		public long[] nextLongArray(final int n) throws IOException {
			final long[] res = new long[n];
			for(int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public int[] nextIntArray(final int n) throws IOException {
			final int[] res = new int[n];
			for(int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[][] nextIntArray2D(final int n, final int k) throws IOException {
			final int[][] res = new int[n][];
			for(int i = 0; i < n; i++) {
				res[i] = nextIntArray(k);
			}
			return res;
		}

		public double[] nextDoubleArray(final int n) throws IOException {
			final double[] res = new double[n];
			for(int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

	}

}


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

public class CF {

	ArrayList<Integer> g = new ArrayList<>();

	int MAX = 50;
	ArrayList<Integer>[] hs = new ArrayList[MAX];
	int[] add = { 0, 4, 7 };

	void go(int curSum) {
		if (g.size() == 6) {
			if (hs[curSum] != null)
				return;
			ArrayList<Integer> tmp = new ArrayList<>();
			for (int x : g)
				tmp.add(x);
			hs[curSum] = tmp;
		} else {
			for (int i = 0; i < 3; i++) {
				g.add(add[i]);
				go(curSum + add[i]);
				g.remove(g.size() - 1);
			}
		}
	}

	void solve() {
		go(0);

		String[] numbers = new String[10];
		for (int i = 0; i < 10; i++) {
			char[] c = new char[1];
			c[0] = (char) ('0' + i);
			numbers[i] = new String(c);
		}
		int t = in.nextInt();
		for (int i = 0; i < t; i++) {
			String need = in.next();
			int[][] last = new int[need.length() + 1][10];
			int[][] last2 = new int[need.length() + 1][10];
			for (int len = 0; len < need.length() + 1; len++) {
				Arrays.fill(last[len], -1);
			}
			last[0][0] = 0;
			for (int j = need.length() - 1; j >= 0; j--) {
				int was = need.length() - 1 - j;
				for (int ll = 0; ll < 10; ll++)
					if (last[was][ll] != -1) {
						for (int next = 0; next < MAX; next++)
							if (hs[next] != null) {
								int would = ll + next;
								if (would % 10 == need.charAt(j) - '0') {
									last[was + 1][would / 10] = next;
									last2[was + 1][would / 10] = ll;
								}
							}
					}
			}
			if (last[last.length - 1][0] == -1) {
				out.println(-1);
			} else {
				ArrayList<Integer> needSum = new ArrayList<>();
				int cur = 0;
				for (int j = last.length - 1; j > 0; j--) {
					needSum.add(last[j][cur]);
					cur = last2[j][cur];
				}
				String[] ans = new String[6];
				for (int j = 0; j < 6; j++) {
					ans[j] = "";
				}
				for (int j = 0; j < needSum.size(); j++) {
					int need1 = needSum.get(j);
					ArrayList<Integer> tmp = hs[need1];
					for (int k = 0; k < 6; k++) {
						if (tmp.get(k) != 0 || ans[k].length() != 0)
							ans[k] = ans[k] + numbers[tmp.get(k)];
					}
				}
				for (int j = 0; j < 6; j++)
					if (ans[j].length() == 0)
						ans[j] = "0";
				for (int j = 0; j < 6; j++) {
					out.print(ans[j] + " ");
				}
				out.println();
			}
		}
	}

	FastScaner in;
	PrintWriter out;

	void run() {
		in = new FastScaner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	void runWithFiles() {
		in = new FastScaner(new File("input.txt"));
		try {
			out = new PrintWriter(new File("output.txt"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

		solve();

		out.close();
	}

	public static void main(String[] args) {
		Locale.setDefault(Locale.US);
		new CF().run();
	}

	class FastScaner {
		BufferedReader br;
		StringTokenizer st;

		FastScaner(InputStream is) {
			br = new BufferedReader(new InputStreamReader(is));
		}

		FastScaner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        // BEGIN initialize singles array
        int[] temp = new int[3];
        temp[0] = 0;
        temp[1] = 4;
        temp[2] = 7;
        HashMap<Integer, ArrayList<Integer>> singles = new HashMap<Integer, ArrayList<Integer>>();
        for (int i = 0; i < 43; i++) {
            if (!singles.containsKey(i)) {
                for (int j = 0; j < 3; j++) {
                    if (!singles.containsKey(i)) {
                        for (int k = j; k < 3; k++) {
                            if (!singles.containsKey(i)) {
                                for (int l = k; l < 3; l++) {
                                    if (!singles.containsKey(i)) {
                                        for (int m = l; m < 3; m++) {
                                            if (!singles.containsKey(i)) {
                                                for (int n = m; n < 3; n++) {
                                                    if (!singles.containsKey(i)) {
                                                        for (int o = n; o < 3; o++) {
                                                            if (temp[j]
                                                                    + temp[k]
                                                                    + temp[l]
                                                                    + temp[m]
                                                                    + temp[n]
                                                                    + temp[o] == i) {
                                                                if (!singles
                                                                        .containsKey(i)) {
                                                                    ArrayList tempList = new ArrayList<Integer>();
                                                                    tempList.add(temp[j]);
                                                                    tempList.add(temp[k]);
                                                                    tempList.add(temp[l]);
                                                                    tempList.add(temp[m]);
                                                                    tempList.add(temp[n]);
                                                                    tempList.add(temp[o]);
                                                                    singles.put(
                                                                            i,
                                                                            tempList);
                                                                } else {
                                                                    o = 3;
                                                                }
                                                            }
                                                        }
                                                    } else {
                                                        n = 3;
                                                    }
                                                }
                                            } else {
                                                m = 3;
                                            }
                                        }
                                    } else {
                                        l = 3;
                                    }
                                }
                            } else {
                                k = 3;
                            }
                        }
                    } else {
                        j = 3;
                    }
                }
            }
        }
        // END initialize singles array
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        for (int i = 0; i < t; i++) {
            char[] nString = in.next().toCharArray();
            int[] n = new int[nString.length];
            for (int j = 0; j < n.length; j++) {
                n[j] = Character.digit(nString[j], 10);
            }
            ArrayList<Integer> able = new ArrayList<Integer>();
            boolean foundIt = false;
            if (n[0] - 8 <= 4 && n[0] - 8 >= 0) {
                able.add(8);
            }
            if (n[0] - 7 <= 4 && n[0] - 7 >= 0) {
                able.add(7);
            }
            if (n[0] - 4 <= 4 && n[0] - 4 >= 0) {
                able.add(4);
            }
            if (n[0] - 0 <= 4 && n[0] - 0 >= 0) {
                able.add(0);
            }
            if(n.length > 1){
            ArrayList<Integer> answer = new ArrayList<Integer>();
            for (int j = 0; j < able.size(); j++) {
                int tens = n[0] - able.get(j);
                if (!foundIt) {
                    foundIt = f(n, tens, singles, 1, answer);
                    if (foundIt) {
                        answer.add(able.get(j));
                    }
                }
            }
            if (!foundIt) {
                System.out.println(-1);
            } else {
                int[] finalAnswer = new int[6];
                for (int j = 0; j < 6; j++) {
                    for (int k = 0; k < n.length; k++) {
                        finalAnswer[j] += singles.get(answer.get(k)).get(j)
                                * Math.pow(10, k);
                    }
                    System.out.print(finalAnswer[j] + " ");
                }
            }
            }
            else{
                if(!singles.containsKey(n[0])){
                    System.out.println(-1);
                }
                else{
                    for(int j = 0; j < 6; j++){
                        System.out.print(singles.get(n[0]).get(j) + " ");
                    }
                }
            }
        }
    }

    public static boolean f(int[] n, int tens,
            HashMap<Integer, ArrayList<Integer>> singles, int current,
            ArrayList<Integer> answer) {
        boolean foundIt = false;

        if (current + 1 == n.length) {
            int tempNumber = tens * 10 + n[current];
            if (singles.containsKey(tempNumber)) {
                answer.add(tempNumber);
                return true;
            }
            return false;
        }

        ArrayList<Integer> able = new ArrayList<Integer>();
        for (int i = 0; i < 6 && i <= n[current]; i++) {
            int tempNumber = tens * 10 + n[current] - i;
            if (singles.containsKey(tempNumber)) {
                able.add(n[current] - i);
            }
        }
        int singlesDigit = 0;
        for (int i = 0; i < able.size(); i++) {
            if (!foundIt) {
                foundIt = f(n, n[current] - able.get(i), singles, current + 1,
                        answer);
                if (foundIt) {
                    singlesDigit = able.get(i);
                }
            }
        }
        // BEGIN take one and add 10
        if (!foundIt) {
            if (tens > 0) {
                tens -= 1;
                int tempDigit = n[current] + 10;
                able.clear();
                // BEGIN find able again
                for (int i = 0; i < 6 && i <= tempDigit; i++) {
                    if (tempDigit - i < 10) {
                        int tempNumber = tens * 10 + tempDigit - i;
                        if (singles.containsKey(tempNumber)) {
                            able.add(tempDigit - i);
                        }
                    }
                }
                // END find able again
                for (int i = 0; i < able.size(); i++) {
                    if (!foundIt) {
                        foundIt = f(n, tempDigit - able.get(i), singles,
                                current + 1, answer);
                        if (foundIt) {
                            singlesDigit = able.get(i);
                        }
                    }
                }
            }
        }
        // END take one and add 10
        if (foundIt) {
            answer.add(tens * 10 + singlesDigit);
        }
        return foundIt;
    }

}


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        // BEGIN initialize singles array
        int[] temp = new int[3];
        temp[0] = 0;
        temp[1] = 4;
        temp[2] = 7;
        HashMap<Integer, ArrayList<Integer>> singles = new HashMap<Integer, ArrayList<Integer>>();
        for (int i = 0; i < 43; i++) {
            if (!singles.containsKey(i)) {
                for (int j = 0; j < 3; j++) {
                    if (!singles.containsKey(i)) {
                        for (int k = j; k < 3; k++) {
                            if (!singles.containsKey(i)) {
                                for (int l = k; l < 3; l++) {
                                    if (!singles.containsKey(i)) {
                                        for (int m = l; m < 3; m++) {
                                            if (!singles.containsKey(i)) {
                                                for (int n = m; n < 3; n++) {
                                                    if (!singles.containsKey(i)) {
                                                        for (int o = n; o < 3; o++) {
                                                            if (temp[j]
                                                                    + temp[k]
                                                                    + temp[l]
                                                                    + temp[m]
                                                                    + temp[n]
                                                                    + temp[o] == i) {
                                                                if (!singles
                                                                        .containsKey(i)) {
                                                                    ArrayList tempList = new ArrayList<Integer>();
                                                                    tempList.add(temp[j]);
                                                                    tempList.add(temp[k]);
                                                                    tempList.add(temp[l]);
                                                                    tempList.add(temp[m]);
                                                                    tempList.add(temp[n]);
                                                                    tempList.add(temp[o]);
                                                                    singles.put(
                                                                            i,
                                                                            tempList);
                                                                } else {
                                                                    o = 3;
                                                                }
                                                            }
                                                        }
                                                    } else {
                                                        n = 3;
                                                    }
                                                }
                                            } else {
                                                m = 3;
                                            }
                                        }
                                    } else {
                                        l = 3;
                                    }
                                }
                            } else {
                                k = 3;
                            }
                        }
                    } else {
                        j = 3;
                    }
                }
            }
        }
        // END initialize singles array
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        for (int i = 0; i < t; i++) {
            char[] nString = in.next().toCharArray();
            int[] n = new int[nString.length];
            for (int j = 0; j < n.length; j++) {
                n[j] = Character.digit(nString[j], 10);
            }
            ArrayList<Integer> able = new ArrayList<Integer>();
            boolean foundIt = false;
            if (n[0] - 8 <= 4 && n[0] - 8 >= 0) {
                able.add(8);
            }
            if (n[0] - 7 <= 4 && n[0] - 7 >= 0) {
                able.add(7);
            }
            if (n[0] - 4 <= 4 && n[0] - 4 >= 0) {
                able.add(4);
            }
            if (n[0] - 0 <= 4 && n[0] - 0 >= 0) {
                able.add(0);
            }
            if(n.length > 1){
            ArrayList<Integer> answer = new ArrayList<Integer>();
            for (int j = 0; j < able.size(); j++) {
                int tens = n[0] - able.get(j);
                if (!foundIt) {
                    foundIt = f(n, tens, singles, 1, answer);
                    if (foundIt) {
                        answer.add(able.get(j));
                    }
                }
            }
            if (!foundIt) {
                System.out.println(-1);
            } else {
                long[] finalAnswer = new long[6];
                for (int j = 0; j < 6; j++) {
                    for (int k = 0; k < n.length; k++) {
                        finalAnswer[j] += singles.get(answer.get(k)).get(j)
                                * (long)Math.pow(10, k);
                    }
                    System.out.print(finalAnswer[j] + " ");
                }
            }
            }
            else{
                if(!singles.containsKey(n[0])){
                    System.out.println(-1);
                }
                else{
                    for(int j = 0; j < 6; j++){
                        System.out.print(singles.get(n[0]).get(j) + " ");
                    }
                }
            }
        }
    }

    public static boolean f(int[] n, int tens,
            HashMap<Integer, ArrayList<Integer>> singles, int current,
            ArrayList<Integer> answer) {
        boolean foundIt = false;

        if (current + 1 == n.length) {
            int tempNumber = tens * 10 + n[current];
            if (singles.containsKey(tempNumber)) {
                answer.add(tempNumber);
                return true;
            }
            return false;
        }

        ArrayList<Integer> able = new ArrayList<Integer>();
        for (int i = 0; i < 6 && i <= n[current]; i++) {
            int tempNumber = tens * 10 + n[current] - i;
            if (singles.containsKey(tempNumber)) {
                able.add(n[current] - i);
            }
        }
        int singlesDigit = 0;
        for (int i = 0; i < able.size(); i++) {
            if (!foundIt) {
                foundIt = f(n, n[current] - able.get(i), singles, current + 1,
                        answer);
                if (foundIt) {
                    singlesDigit = able.get(i);
                }
            }
        }
        // BEGIN take one and add 10
        if (!foundIt) {
            if (tens > 0) {
                tens -= 1;
                int tempDigit = n[current] + 10;
                able.clear();
                // BEGIN find able again
                for (int i = 0; i < 6 && i <= tempDigit; i++) {
                    if (tempDigit - i < 10) {
                        int tempNumber = tens * 10 + tempDigit - i;
                        if (singles.containsKey(tempNumber)) {
                            able.add(tempDigit - i);
                        }
                    }
                }
                // END find able again
                for (int i = 0; i < able.size(); i++) {
                    if (!foundIt) {
                        foundIt = f(n, tempDigit - able.get(i), singles,
                                current + 1, answer);
                        if (foundIt) {
                            singlesDigit = able.get(i);
                        }
                    }
                }
            }
        }
        // END take one and add 10
        if (foundIt) {
            answer.add(tens * 10 + singlesDigit);
        }
        return foundIt;
    }

}


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

public class E {

	int[] dig = new int[] { 0, 4, 7 };

	int[] number;
	boolean[][] was;

	int numLen = 20;
	int nums = 6;

	int[][] cnt;

	long[] numbers;

	boolean solve(int pos, int per) {
		if (pos < 0) {
			if (per == 0) {
				for (int i = 0; i < numLen; i++) {
					int t = 0;
					for (int j = 0; j < 3; j++) {
						for (int k = 0; k < cnt[i][j]; k++) {
							numbers[t] = numbers[t] * 10L + dig[j];
							t++;
						}
					}
				}
				return true;
			} else {
				return false;
			}
		}
		if (was[pos][per]) {
			return false;
		}
		was[pos][per] = true;
		for (cnt[pos][0] = 0; cnt[pos][0] <= 6; cnt[pos][0]++) {
			for (cnt[pos][1] = 0; cnt[pos][1] + cnt[pos][0] <= 6; cnt[pos][1]++) {
				cnt[pos][2] = 6 - cnt[pos][0] - cnt[pos][1];
				if ((cnt[pos][1] * 4 + cnt[pos][2] * 7 + per) % 10 == number[pos]
						&& solve(pos - 1,
								(cnt[pos][1] * 4 + cnt[pos][2] * 7 + per) / 10)) {
					return true;
				}
			}
		}
		return false;

	}

	void solve() throws IOException {
		number = new int[numLen];
		was = new boolean[numLen][5];
		cnt = new int[numLen][3];
		numbers = new long[nums];
		long n = nextLong();
		for (int i = numLen - 1; i >= 0; i--) {
			number[i] = (int)(n % 10);
			n /= 10;
		}
		if (solve(numLen - 1, 0)) {
			for (int i = 0; i < nums - 1; i++) {
				out.print(numbers[i] + " ");
			}
			out.println(numbers[nums - 1]);
		} else {
			out.println("-1");
		}

	}

	void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		int n = nextInt();
		for (int i = 0; i < n; i++) {
			solve();
		}
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new E().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;

	String next() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String temp = in.readLine();
			if (temp == null) {
				return null;
			}
			st = new StringTokenizer(temp);
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	long nextLong() throws IOException {
		return Long.parseLong(next());
	}

}


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

public class E {

	int[] dig = new int[] { 0, 4, 7 };

	int[] number;
	boolean[][] was;

	int numLen = 20;
	int nums = 6;

	int[][] cnt;

	long[] numbers;

	boolean solve(int pos, int per) {
		if (pos < 0) {
			if (per == 0) {
				for (int i = 0; i < numLen; i++) {
					int t = 0;
					for (int j = 0; j < 3; j++) {
						for (int k = 0; k < cnt[i][j]; k++) {
							numbers[t] = numbers[t] * 10L + dig[j];
							t++;
						}
					}
				}
				return true;
			} else {
				return false;
			}
		}
		if (was[pos][per]) {
			return false;
		}
		was[pos][per] = true;
		for (cnt[pos][0] = 0; cnt[pos][0] <= 6; cnt[pos][0]++) {
			for (cnt[pos][1] = 0; cnt[pos][1] + cnt[pos][0] <= 6; cnt[pos][1]++) {
				cnt[pos][2] = 6 - cnt[pos][0] - cnt[pos][1];
				if ((cnt[pos][1] * 4 + cnt[pos][2] * 7 + per) % 10 == number[pos]
						&& solve(pos - 1,
								(cnt[pos][1] * 4 + cnt[pos][2] * 7 + per) / 10)) {
					return true;
				}
			}
		}
		return false;

	}

	void solve() throws IOException {
		number = new int[numLen];
		was = new boolean[numLen][5];
		cnt = new int[numLen][3];
		numbers = new long[nums];
		int n = nextInt();
		for (int i = numLen - 1; i >= 0; i--) {
			number[i] = n % 10;
			n /= 10;
		}
		if (solve(numLen - 1, 0)) {
			for (int i = 0; i < nums - 1; i++) {
				out.print(numbers[i] + " ");
			}
			out.println(numbers[nums - 1]);
		} else {
			out.println("-1");
		}

	}

	void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		int n = nextInt();
		for (int i = 0; i < n; i++) {
			solve();
		}
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new E().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;

	String next() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String temp = in.readLine();
			if (temp == null) {
				return null;
			}
			st = new StringTokenizer(temp);
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	long nextLong() throws IOException {
		return Long.parseLong(next());
	}

}


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Niyaz Nigmatullin
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		FastPrinter out = new FastPrinter(outputStream);
		TaskE solver = new TaskE();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskE {
    final int MAXCARRY = 6;
    public void solve(int testNumber, FastScanner in, FastPrinter out) {
        int t = in.nextInt();
        for (int curTest = 0; curTest < t; curTest++) {
            long n = in.nextLong();
            String s = n + "";
            int[] d = new int[s.length()];
            for (int i = 0; i < d.length; i++) {
                d[i] = s.charAt(i) - '0';
            }
            boolean[][] dp = new boolean[d.length + 1][MAXCARRY];
            dp[d.length][0] = true;
            for (int i = d.length - 1; i >= 0; i--) {
                for (int carry2 = 0; carry2 < MAXCARRY; carry2++) {
                    if (!dp[i + 1][carry2]) {
                        continue;
                    }
                    for (int carry = 0; carry < MAXCARRY; carry++) {
                        int needSum = carry * 10 + d[i] - carry2;
                        for (int seven = 0; seven * 7 <= needSum && seven <= 6; seven++) {
                            int left = needSum - seven * 7;
                            if (left % 4 != 0 || left / 4 + seven > 6) {
                                continue;
                            }
                            dp[i][carry] = true;
                            break;
                        }
                    }
                }
            }
            if (!dp[0][0]) {
                out.println(-1);
                continue;
            }
            long[] answer = new long[6];
            all: for (int i = 0, carry = 0; i < d.length; i++) {
                for (int carry2 = 0; carry2 < MAXCARRY; carry2++) {
                    if (!dp[i + 1][carry2]) continue;
                    int needSum = carry * 10 + d[i] - carry2;
                    for (int seven = 0; seven * 7 <= needSum && seven <= 6; seven++) {
                        int left = needSum - seven * 7;
                        if (left % 4 != 0 || left / 4 + seven > 6) {
                            continue;
                        }
                        int four = left / 4;
                        carry = carry2;
                        for (int j = 0; j < seven; j++) {
                            answer[j] = answer[j] * 10 + 7;
                        }
                        for (int j = 0; j < four; j++) {
                            answer[j + seven] = answer[j + seven] * 10 + 4;
                        }
                        for (int j = 0; j < 6 - seven - four; j++) {
                            answer[j + seven + four] *= 10;
                        }
                        continue all;
                    }
                }
                throw new AssertionError();
            }
            out.printArray(answer);
        }
    }
}

class FastScanner extends BufferedReader {

    public FastScanner(InputStream is) {
        super(new InputStreamReader(is));
    }

    public int read() {
        try {
            int ret = super.read();
//            if (isEOF && ret < 0) {
//                throw new InputMismatchException();
//            }
//            isEOF = ret == -1;
            return ret;
        } catch (IOException e) {
            throw new InputMismatchException();
        }
    }

    public String next() {
        StringBuilder sb = new StringBuilder();
        int c = read();
        while (isWhiteSpace(c)) {
            c = read();
        }
        if (c < 0) {
            return null;
        }
        while (c >= 0 && !isWhiteSpace(c)) {
            sb.appendCodePoint(c);
            c = read();
        }
        return sb.toString();
    }

    static boolean isWhiteSpace(int c) {
        return c >= 0 && c <= 32;
    }

    public int nextInt() {
        int c = read();
        while (isWhiteSpace(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int ret = 0;
        while (c >= 0 && !isWhiteSpace(c)) {
            if (c < '0' || c > '9') {
                throw new NumberFormatException("digit expected " + (char) c
                        + " found");
            }
            ret = ret * 10 + c - '0';
            c = read();
        }
        return ret * sgn;
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }

    }

class FastPrinter extends PrintWriter {

    public FastPrinter(OutputStream out) {
        super(out);
    }

    public FastPrinter(Writer out) {
        super(out);
    }

    public void printArray(long[] a) {
        for (int i = 0; i < a.length; i++) {
            if (i > 0) {
                print(' ');
            }
            print(a[i]);
        }
        println();
    }

}


import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st = new StringTokenizer("");

    private void run() throws IOException {
        if (new File("input.txt").exists())
            in = new BufferedReader(new FileReader("input.txt"));
        else
            in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    final int MAX = 30;

    private void solve() throws IOException {

        long ten[] = new long[19];
        ten[0] = 1;
        for (int i = 1; i < 19; i++)
            ten[i] = ten[i - 1] * 10;
        int cnt = 0;
        int sev[] = new int[MAX];
        int fou[] = new int[MAX];
        int sum[] = new int[MAX];
        for (int i = 0; i < 7; i++)
            for (int j = 0; j < 7 - i; j++) {
                sev[cnt] = i;
                fou[cnt] = j;
                sum[cnt++] = i * 7 + j * 4;
            }
        int c[] = new int[20];
        long ans[] = {0, 0, 0, 0, 0, 0};
        int prev[][] = new int[20][8];
        int s[][] = new int[20][MAX];
        int T = nextInt();
        for (int t = 0; t < T; t++) {
            long n = nextLong();
            long m = n;
            int l = 0;
            while (m > 0) {
                c[l++] = (int)(m % 10);
                m /= 10;
            }
            c[l] = 0;
            for (int i = 0; i < 20; i++)
                fill(prev[i], -1);
            for (int i = 0; i < 20; i++)
                fill(s[i], -1);
            s[0][0] = 0;
            prev[0][0] = 0;
            for (int i = 0; i < l; i++) {
                for (int j = 0; j < 8; j++)
                    if (prev[i][j] > -1) {
                        for (int k = 0; k < cnt; k++) {
                            if ((j + sum[k]) % 10 == c[i]) {
                                prev[i + 1][(j + sum[k]) / 10] = k;
                                s[i + 1][k] = j;
                            }
                        }
                    }
            }
            if (prev[l][0] == -1) {
                out.println(-1);
            }
            else {
                fill(ans, 0);
                int cur = 0;
                int cn = 0;
                for (int i = l; i > 0; i--) {
                    int ms = prev[i][cur];
                    cur = s[i][ms];
                    cn = 0;
                    for (int j = 0; j < sev[ms]; j++)
                        ans[cn++] += ten[i - 1] * 7;
                    for (int j = 0; j < fou[ms]; j++)
                        ans[cn++] += ten[i - 1] * 4;
                }
                for (int i = 0; i < 6; i++)
                    out.print(ans[i] + " ");
                out.println();
            }
        }

    }

    void chk(boolean b) {
        if (b)
            return;
        System.out.println(new Error().getStackTrace()[1]);
        exit(999);
    }
    void deb(String fmt, Object... args) {
        System.out.printf(Locale.US, fmt + "%n", args);
    }
    String nextToken() throws IOException {
        while (!st.hasMoreTokens())
            st = new StringTokenizer(in.readLine());
        return st.nextToken();
    }
    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
    String nextLine() throws IOException {
        st = new StringTokenizer("");
        return in.readLine();
    }
    boolean EOF() throws IOException {
        while (!st.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null)
                return true;
            st = new StringTokenizer(s);
        }
        return false;
    }
}


import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st = new StringTokenizer("");

    private void run() throws IOException {
        if (new File("input.txt").exists())
            in = new BufferedReader(new FileReader("input.txt"));
        else
            in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    final int MAX = 30;

    private void solve() throws IOException {

        long ten[] = new long[19];
        ten[0] = 1;
        for (int i = 1; i < 19; i++)
            ten[i] = ten[i - 1] * 10;
        int cnt = 0;
        int sev[] = new int[MAX];
        int fou[] = new int[MAX];
        int sum[] = new int[MAX];
        for (int i = 0; i < 7; i++)
            for (int j = 0; j < 7 - i; j++) {
                sev[cnt] = i;
                fou[cnt] = j;
                sum[cnt++] = i * 7 + j * 4;
            }
        int c[] = new int[20];
        int ans[] = {0, 0, 0, 0, 0, 0};
        int prev[][] = new int[20][8];
        int s[][] = new int[20][MAX];
        int T = nextInt();
        for (int t = 0; t < T; t++) {
            long n = nextLong();
            long m = n;
            int l = 0;
            while (m > 0) {
                c[l++] = (int)(m % 10);
                m /= 10;
            }
            c[l] = 0;
            for (int i = 0; i < 20; i++)
                fill(prev[i], -1);
            for (int i = 0; i < 20; i++)
                fill(s[i], -1);
            s[0][0] = 0;
            prev[0][0] = 0;
            for (int i = 0; i < l; i++) {
                for (int j = 0; j < 8; j++)
                    if (prev[i][j] > -1) {
                        for (int k = 0; k < cnt; k++) {
                            if ((j + sum[k]) % 10 == c[i]) {
                                prev[i + 1][(j + sum[k]) / 10] = k;
                                s[i + 1][k] = j;
                            }
                        }
                    }
            }
            if (prev[l][0] == -1) {
                out.println(-1);
            }
            else {
                fill(ans, 0);
                int cur = 0;
                int cn = 0;
                for (int i = l; i > 0; i--) {
                    int ms = prev[i][cur];
                    cur = s[i][ms];
                    cn = 0;
                    for (int j = 0; j < sev[ms]; j++)
                        ans[cn++] += ten[i - 1] * 7;
                    for (int j = 0; j < fou[ms]; j++)
                        ans[cn++] += ten[i - 1] * 4;
                }
                for (int i = 0; i < 6; i++)
                    out.print(ans[i] + " ");
                out.println();
            }
        }

    }

    void chk(boolean b) {
        if (b)
            return;
        System.out.println(new Error().getStackTrace()[1]);
        exit(999);
    }
    void deb(String fmt, Object... args) {
        System.out.printf(Locale.US, fmt + "%n", args);
    }
    String nextToken() throws IOException {
        while (!st.hasMoreTokens())
            st = new StringTokenizer(in.readLine());
        return st.nextToken();
    }
    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
    String nextLine() throws IOException {
        st = new StringTokenizer("");
        return in.readLine();
    }
    boolean EOF() throws IOException {
        while (!st.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null)
                return true;
            st = new StringTokenizer(s);
        }
        return false;
    }
}


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

public class E {

	final int masks = 3 * 3 * 3 * 3 * 3 * 3;
	int[] precalc = new int[masks];
	int[] lucky = new int[] { 0, 4, 7 };
	{
		for (int i = 0; i < masks; i++) {
			int mask = i;
			for (int j = 0; j < 6; j++) {
				precalc[i] += lucky[mask % 3];
				mask /= 3;
			}
		}
	}

	final int len = 20;
	int[] digits = new int[len];
	boolean[][] can = new boolean[5][len + 1];
	int[][] prevMask = new int[5][len + 1];
	int[][] prevCarry = new int[5][len + 1];

	public void solve(long l) {
		int len = 20;

		for (int i = 0; i < len; i++) {
			digits[i] = (int) (l % 10);
			l /= 10;
		}

		for (int i = 0; i < 5; i++) {
			Arrays.fill(can[i], false);
		}
		can[0][0] = true;

		for (int curLen = 0; curLen < len; curLen++) {
			for (int curCarry = 0; curCarry < 5; curCarry++) {
				if (!can[curCarry][curLen]) {
					continue;
				}

				for (int mask = 0; mask < masks; mask++) {
					int sum = precalc[mask] + curCarry;
					if (sum % 10 == digits[curLen]) {
						can[sum / 10][curLen + 1] = true;
						prevMask[sum / 10][curLen + 1] = mask;
						prevCarry[sum / 10][curLen + 1] = curCarry;
					}
				}
			}
		}

		if (!can[0][len]) {
			out.println(-1);
			return;
		}

		int[][] result = new int[6][len + 1];

		int carry = 0;
		for (int curLen = len; curLen > 0; curLen--) {
			int mask = prevMask[carry][curLen];

			carry = prevCarry[carry][curLen];

			for (int j = 0; j < 6; j++) {
				result[j][curLen - 1] = lucky[mask % 3];
				mask /= 3;
			}
		}

		for (int i = 0; i < 6; i++) {
			out.print(getNumber(result[i]));
			if (i == 5) {
				out.println();
			} else {
				out.print(" ");
			}
		}
	}

	private long getNumber(int[] is) {
		long res = 0;
		for (int i = is.length - 1; i >= 0; i--) {
			res = res * 10 + is[i];
		}
		return res;
	}

	FastScanner in;
	PrintWriter out;

	public void run() {
		try {
			in = new FastScanner();
			out = new PrintWriter(System.out);
			int t = in.nextInt();
			for (int i = 0; i < t; i++) {
				solve(in.nextLong());
			}
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastScanner(String name) {
			try {
				br = new BufferedReader(new FileReader(name));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

	public static void main(String[] args) {
		new E().run();
	}
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class E {
    static int[][] dp;
    static int[][] step;
    static char[] digits;

    public static int f(int i, int c) {
        if (i == -1)
            return c == 0 ? 1 : 0;
        if (dp[i][c] != -1)
            return dp[i][c];
        int ret = 0;
        for (int a = 0; a <= 6 && ret == 0; a++) {
            for (int b = 0; a + b <= 6 && ret == 0; b++) {
                int have = a * 4 + b * 7 + c;
                if (have % 10 + '0' == digits[i]) {
                    ret |= f(i - 1, have / 10);
                    if (ret == 1)
                        step[i][c] = a << 4 | b;
                }
            }
        }
        return dp[i][c] = ret;
    }

    public static void main(String[] args) throws Exception {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer strtok;
        strtok = new StringTokenizer(in.readLine());
        int tc = Integer.parseInt(strtok.nextToken());
        while (tc-- > 0) {
            long v = Long.parseLong(in.readLine());
            digits = (v + "").toCharArray();
            dp = new int[digits.length][5];
            step = new int[digits.length][5];
            for (int[] a : dp)
                Arrays.fill(a, -1);
            if (f(digits.length - 1, 0) == 0) {
                System.out.println(-1);
            } else {
                char[][] results = new char[6][digits.length];
                int c = 0;
                for (int i = digits.length - 1; i >= 0; i--) {
                    int a = step[i][c] >> 4;
                    int b = step[i][c] & 0xF;
                    for (int j = 0; j < a; j++)
                        results[j][i] = '4';
                    for (int j = a; j < a + b; j++)
                        results[j][i] = '7';
                    for (int j = a + b; j < 6; j++)
                        results[j][i] = '0';
                    c = (c + a * 4 + b * 7) / 10;
                }
                for (int i = 0; i < results.length; i++)
                    System.out.print(Long.parseLong(new String(results[i]))
                            + " ");
                System.out.println();
            }
        }
    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 * @author pttrung
 */
public class E_Round_206_Div1 {

    public static long MOD = 1000000007;

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        int t = in.nextInt();
        for(int z = 0; z < t; z++){
            String v = in.next();
            int[][]stats =new int[v.length()][2];
            boolean re  = cal(v.length() - 1, 0, stats,v);
            if(re){
                long[]result = new long[6];
                for(int i = 0; i < v.length(); i++){
                    int index = 0;
                    for(int j = 0; j < stats[i][0]; j++){
                        result[index] = result[index] * 10 + 4;
                        index++;
                    }
                    for(int j = 0; j < stats[i][1]; j++){
                        result[index] = result[index] * 10 + 7;
                        index++;
                    }
                    for(int j = index; j < 6; j++){
                        result[j] *= 10;
                    }
                }
                for(long tmp : result){
                    out.print(tmp + " ");
                }
                out.println();
            }else{
                out.println(-1);
            }
        }
        out.close();
    }

    public static boolean cal(int index, int last,int[][]stats, String v){
        if(index < 0){
            return last == 0;
        }
        int need = v.charAt(index) - '0';
        boolean result = false;
        for(int i = 0; i <= 6 && !result; i++){
            for(int j = 0; j + i <= 6; j++){
                int tmp = i*4 + j*7 + last;
                if(tmp % 10 == need){
                    if(cal(index - 1 , tmp / 10,stats, v)){
                        stats[index][0] = i;
                        stats[index][1] = j;
                        result = true;
                        break;
                    }
                }
            }
        }
        return result;
    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int start, int end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return Integer.compare(x, o.x);
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, long b, long MOD) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2, MOD);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Queue;

public class ProblemE {

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);

		int T = Integer.valueOf(in.readLine());
		for (int i = 0 ; i < T ; i++) {
			long[] ans = solve(Long.valueOf(in.readLine()));
			if (ans == null) {
				out.println(-1);
			} else {
				out.println(ans[0] + " " + ans[1] + " " + ans[2] + " " + ans[3] + " " + ans[4] + " " + ans[5]);
			}
		}
		out.flush();
	}

	private static long[] solve(long v) {
		char[] c = new StringBuilder(String.valueOf(v)).reverse().toString().toCharArray();
		int l = c.length;
		boolean[][][] dp = new boolean[l+1][7][5];
		int[][][][] taken = new int[l+1][7][5][4];

		for (int i = 0 ; i < 7 ; i++) {
			dp[0][i][0] = true;
		}
		for (int i = 0 ; i < l ; i++) {
			for (int live = 0 ; live < 7 ; live++) {
				for (int up = 0 ; up < 5 ; up++) {
					if (!dp[i][live][up]) {
						continue;
					}
					for (int four = 0 ; four <= live ; four++) {
						for (int seven = 0 ; four + seven <= live ; seven++) {
							int digit = four * 4 + seven * 7 + up;
							if (digit % 10 != c[i] - '0') {
								continue;
							}
							int nd = digit/10;
							for (int tl = (live - four - seven) ; tl <= live ; tl++) {
								dp[i+1][tl][nd] = true;
								taken[i+1][tl][nd][0] = four;
								taken[i+1][tl][nd][1] = seven;
								taken[i+1][tl][nd][2] = live;
								taken[i+1][tl][nd][3] = up;
							}
						}
					}
				}
			}
		}

		for (int live = 0 ; live < 7 ; live++) {
			for (int up = 0 ; up <= 0 ; up++) {
				if (dp[l][live][up]) {
					long[] res = new long[6];
					for (int i = l ; i >= 1 ; i--) {
						int f = taken[i][live][up][0];
						int s = taken[i][live][up][1];
						int nlive = taken[i][live][up][2];
						int nup = taken[i][live][up][3];
						long base = (long)Math.pow(10L, i-1);
						for (int j = 0 ; j < f ; j++) {
							res[j] += base * 4;
						}
						for (int j = f ; j < f + s ; j++) {
							res[j] += base * 7;
						}
						live = nlive;
						up = nup;
					}
					return res;
				}
			}
		}
		return null;
	}

	public static void debug(Object... o) {
		System.err.println(Arrays.deepToString(o));
	}
}


//package round206;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class E {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		boolean[][][] dp = new boolean[43][7][7];
		dp[0][0][0] = true;
		for(int i = 0;i < 6;i++){
			for(int j = 42;j >= 0;j--){
				for(int k = 6;k >= 0;k--){
					for(int l = 6;l >= 0;l--){
						if(dp[j][k][l]){
							dp[j+4][k+1][l] = true;
							dp[j+7][k][l+1] = true;
						}
					}
				}
			}
		}
		int[][] repr = new int[43][];
		outer:
		for(int i = 0;i <= 42;i++){
			for(int j = 0;j <= 6;j++){
				for(int k = 0;k <= 6;k++){
					if(dp[i][j][k]){
						repr[i] = new int[]{j, k};
						continue outer;
					}
				}
			}
		}

		for(int T = ni();T >= 1;T--){
			long n = nl();
			int[][] lrepr = new int[5][];
			if(n < 1000000000000000000L){
				lrepr[0] = new int[0];
			}else{
				lrepr[1] = new int[0];
			}
			for(long d = 100000000000000000L;d >= 1;d /= 10){
				int[][] nlrepr = new int[5][];
				int di = (int)(n/d%10);
				for(int k = 0;k <= 4;k++){
					if(lrepr[k] != null){
						for(int l = 0;l <= 4;l++){
							int u = k*10+di-l;
							if(u >= 0 && u <= 42 && repr[u] != null && nlrepr[l] == null){
								nlrepr[l] = Arrays.copyOf(lrepr[k], lrepr[k].length+2);
								nlrepr[l][lrepr[k].length] = repr[u][0];
								nlrepr[l][lrepr[k].length+1] = repr[u][1];
							}
						}
					}
				}
				lrepr = nlrepr;
			}
			if(lrepr[0] != null){
				long[] a = new long[6];
				int o = 0;
				for(long d = 100000000000000000L;d >= 1;d /= 10, o+=2){
					int p = 0;
					for(int i = 0;i < lrepr[0][o];i++)a[p++] += 4*d;
					for(int i = 0;i < lrepr[0][o+1];i++)a[p++] += 7*d;
				}
				for(int i = 0;i < 6;i++){
					if(i > 0)out.print(" ");
					out.print(a[i]);
				}
				out.println();
			}else{
				out.println(-1);
			}
		}
	}

	void run() throws Exception
	{
//		int n = 5000, m = 99999;
//		Random gen = new Random();
//		StringBuilder sb = new StringBuilder();
//		sb.append(n + " ");
//		for(int i = 0;i < n;i++){
//			sb.append(Math.abs(gen.nextLong()%1000000000000000000L) + " ");
//		}
//		INPUT = sb.toString();
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new E().run(); }

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class E {
	static boolean vis[][][][];
	static int[] vals;
	static boolean found;
	static int[][] construct;
	static int[] nexts = new int[] { 7, 4, 0 };

	public static void dfs(int decPlace, int row, int sum, int carry) {
		if (found)
			return;
		// System.out.println("das");
		if (decPlace < 0) {
			if (carry == 0&&sum==0) {
				// for (int j = 0; j < construct.length; j++)
				// System.out.println("a7eh"+Arrays.toString(construct[j]));
				found = true;
			}
			return;
		}
		vis[decPlace][row][sum][carry] = true;
		int curSum = carry * 10 + sum;
		for (int i = 0; i < 3 && !found; i++) {
			int pos = curSum + nexts[i];
			if (row == 5 && pos % 10 != vals[decPlace])
				continue;
			int newDec = decPlace, newRow = row + 1;
			int newSum = pos % 10;
			int newCarry = pos / 10;
			if (row == 5) {
//				System.out.println(decPlace + " " + row + " " + sum + " "
//						+ carry + "  fa " + pos + " " + curSum);
//				for (int j = 0; j < construct.length; j++)
//					System.out.println(Arrays.toString(construct[j]));
				newDec--;
				newRow = 0;
				newSum = newCarry;
				newCarry = 0;
			}
			if (newDec < 0 || !vis[newDec][newRow][newSum][newCarry]) {
				construct[row][decPlace] = nexts[i];
				dfs(newDec, newRow, newSum, newCarry);
			}
		}
	}

	public static void main(String[] args) throws Exception {
		int numCnt = nextInt();
		PrintWriter out = new PrintWriter(System.out);
		for (int i = 0; i < numCnt; i++) {
			String t = next();
			vals = new int[t.length()];
			long num = Long.parseLong(t);
			for (int j = t.length() - 1; j >= 0; --j) {
				vals[j] = (int) (num % 10);
				num /= 10;
			}
//			System.out.println(Arrays.toString(vals));
			vis = new boolean[t.length()][6][10][10];
			construct = new int[6][t.length()];
			found = false;
			dfs(vals.length - 1, 0, 0, 0);
//			for (int j = 0; j < construct.length; j++)
//				System.out.println("a7a" + Arrays.toString(construct[j]));
			if (found) {
				for (int j = 0; j < construct.length; j++) {
					long tmp = 0;
					for (int k = 0; k < construct[j].length; k++) {
						tmp *= 10;
						tmp += construct[j][k];
					}
					out.print(tmp + " ");
				}
				out.println();
			} else {
				out.println("-1");
			}
		}
		out.flush();
	}

	static BufferedReader br = new BufferedReader(new InputStreamReader(
			System.in));
	static StringTokenizer tokenizer = new StringTokenizer("");

	static int nextInt() throws Exception {
		return Integer.parseInt(next());
	}

	static double nextDouble() throws Exception {
		return Double.parseDouble(next());
	}

	static String next() throws Exception {
		while (true) {
			if (tokenizer.hasMoreTokens()) {
				return tokenizer.nextToken();
			}
			String s = br.readLine();
			if (s == null) {
				return null;
			}
			tokenizer = new StringTokenizer(s);
		}
	}
}


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

public class E {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	int[][] how = new int[43][];

	void preCalc() {
		outer: for (int i = 0; i <= 42; i++) {
			for (int c4 = 0; c4 <= 6; c4++) {
				if ((i - 4 * c4) % 7 == 0) {
					int c7 = (i - 4 * c4) / 7;
					if (c7 >= 0 && c4 + c7 <= 6) {
						how[i] = new int[6];
						Arrays.fill(how[i], 0, c4, 4);
						Arrays.fill(how[i], c4, c4 + c7, 7);
						continue outer;
					}
				}
			}
		}
		// System.err.println(Arrays.deepToString(how));
	}

	Map<Long, long[]> map = new HashMap<>();
	static final long[] NO_ANSWER = {};

	long[] go(long x) {
		if (map.containsKey(x)) {
			return map.get(x);
		}

		if (x == 0) {
			long[] res = new long[6];
			map.put(x, res);
			return res;
		}

		int rem = (int) (x % 10);
		for (int i = rem; i <= 42; i += 10) {
			if (how[i] != null) {
				long to = (x - i) / 10;
				if (to < 0)
					break;
				long[] res = go(to);
				if (res.length == 6) {
					res = res.clone();
					for (int j = 0; j < 6; j++) {
						res[j] = res[j] * 10 + how[i][j];
					}
					map.put(x, res);
					return res;
				}
			}
		}

		map.put(x, NO_ANSWER);
		return NO_ANSWER;
	}

	void solve(long x) {
		long[] res = go(x);
		if (res.length == 6) {
			for (int i = 0; i < 6; i++) {
				out.print(res[i] + " ");
			}
			out.println();
		} else {
			out.println(-1);
		}
	}

	E() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		int t = nextInt();
		while (t-- > 0) {
			solve(nextLong());
		}
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new E();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}


import java.io.IOException;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.HashMap;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.StringTokenizer;
import java.util.Collection;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author RiaD
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Reader in = new Reader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskE solver = new TaskE();
		int testCount = Integer.parseInt(in.next());
		for (int i = 1; i <= testCount; i++)
			solver.solve(i, in, out);
		out.close();
	}
}

class TaskE {
    HashMap<Long, ArrayList<ArrayList<Integer>> > memo = new HashMap<Long, ArrayList<ArrayList<Integer>>>();
    ArrayList<Integer>[] dp = new ArrayList[43];
    {
        dp[0] = new ArrayList<Integer>();
        int[] digits = {4, 7};
        for(int i = 1; i <= 42; ++i) {
            for (int digit : digits) {
                int p = i - digit;
                if(p < 0) {
                    continue;
                }
                if(dp[p] == null)
                    continue;

                if((dp[i] == null || dp[p].size() + 1 < dp[i].size()) && dp[p].size() <= 5) {
                    dp[i] = new ArrayList<Integer>();
                    dp[i].addAll(dp[p]);
                    dp[i].add(digit);
                }
            }
        }
        for(int i = 0; i <= 42; ++i) {
            if(dp[i] == null)
                continue;
            while (dp[i].size() < 6)
                dp[i].add(0);
        }

        memo.put(0L, new ArrayList<ArrayList<Integer>>());
        for(int i = 0; i <= 42; ++i)
            if(dp[i] != null && dp[i].size() != 6)
                throw new AssertionError(i);
    }

    ArrayList<ArrayList<Integer>> solve(long x) {
        if(memo.containsKey(x)) {
            return memo.get(x);
        }
        if(x < 0)
            return null;
        for(int c = (int) (x % 10); c <= 42; c += 10){
            if(dp[c] == null)
                continue;
            ArrayList<ArrayList<Integer>> res = solve((x - c) / 10);
            if(res != null) {
                ArrayList<ArrayList<Integer>> newRes = new ArrayList<ArrayList<Integer>>();
                newRes.addAll(res);
                newRes.add(dp[c]);
                memo.put(x, newRes);

                return newRes;
            }
        }

        return null;

    }
    public void solve(int testNumber, Reader in, OutputWriter out) {
        long x = in.nextLong();
        ArrayList<ArrayList<Integer>> res = solve(x);
        //System.err.println(res);
        if(res == null) {
            out.print(-1);
        }
        else {

            for(int j = 0; j < 6; ++j) {
                boolean flag = false;
                for(int i = 0; i < res.size(); ++i) {
                    if(flag || res.get(i).get(j) != 0) {
                        flag = true;
                        out.print(res.get(i).get(j));
                    }
                }

                if(!flag)
                    out.print("0");
                out.print(" ");
            }

        }
        out.println();

    }
}

class Reader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public Reader(BufferedReader reader) {
        this.reader = reader;
    }

    public Reader(InputStream stream) {
        this(new BufferedReader(new InputStreamReader(stream)));
    }

    public String nextString() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(readLine());
        }
        return tokenizer.nextToken();
    }

    public long nextLong() {
        return Long.parseLong(nextString());
    }

    public String next() {
        return nextString();
    }

    private String readLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

class OutputWriter extends PrintWriter {

	public OutputWriter(OutputStream out) {
		super(out);
	}

	public OutputWriter(java.io.Writer writer){
		super(writer);
	}

	}


import java.io.IOException;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.HashMap;
import java.io.PrintStream;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.StringTokenizer;
import java.util.Collection;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author RiaD
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Reader in = new Reader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskE solver = new TaskE();
		int testCount = Integer.parseInt(in.next());
		for (int i = 1; i <= testCount; i++)
			solver.solve(i, in, out);
		out.close();
	}
}

class TaskE {
    HashMap<Long, ArrayList<ArrayList<Integer>> > memo = new HashMap<Long, ArrayList<ArrayList<Integer>>>();
    ArrayList<Integer>[] prev = new ArrayList[43];
    {
        prev[0] = new ArrayList<Integer>();
        int[] digits = {4, 7};
        for(int i = 1; i <= 42; ++i) {
            for (int digit : digits) {
                int p = i - digit;
                if(p < 0) {
                    continue;
                }
                if(prev[p] == null)
                    continue;

                if(prev[i] == null || prev[p].size() + 1 < prev[i].size() && prev[p].size() <= 5) {
                    prev[i] = new ArrayList<Integer>();
                    prev[i].addAll(prev[p]);
                    prev[i].add(digit);
                }
            }
        }
        for(int i = 0; i <= 42; ++i) {
            if(prev[i] == null)
                continue;
            while (prev[i].size() < 6)
                prev[i].add(0);
        }

        memo.put(0L, new ArrayList<ArrayList<Integer>>());
    }

    ArrayList<ArrayList<Integer>> solve(long x) {
        if(memo.containsKey(x)) {
            return memo.get(x);
        }
        if(x < 0)
            return null;
        for(int c = (int) (x % 10); c <= 42; c += 10){
            if(prev[c] == null)
                continue;
            ArrayList<ArrayList<Integer>> res = solve((x - c) / 10);
            if(res != null) {
                ArrayList<ArrayList<Integer>> newRes = new ArrayList<ArrayList<Integer>>();
                newRes.addAll(res);
                newRes.add(prev[c]);
                memo.put(x, newRes);

                return newRes;
            }
        }

        return null;

    }
    public void solve(int testNumber, Reader in, OutputWriter out) {
        long x = in.nextLong();
        ArrayList<ArrayList<Integer>> res = solve(x);
        System.err.println(res);
        if(res == null) {
            out.print(-1);
        }
        else {

            for(int j = 0; j < 6; ++j) {
                boolean flag = false;
                for(int i = 0; i < res.size(); ++i) {
                    if(flag || res.get(i).get(j) != 0) {
                        flag = true;
                        out.print(res.get(i).get(j));
                    }
                }

                if(!flag)
                    out.print("0");
                out.print(" ");
            }

        }
        out.println();

    }
}

class Reader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public Reader(BufferedReader reader) {
        this.reader = reader;
    }

    public Reader(InputStream stream) {
        this(new BufferedReader(new InputStreamReader(stream)));
    }

    public String nextString() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(readLine());
        }
        return tokenizer.nextToken();
    }

    public long nextLong() {
        return Long.parseLong(nextString());
    }

    public String next() {
        return nextString();
    }

    private String readLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

class OutputWriter extends PrintWriter {

	public OutputWriter(OutputStream out) {
		super(out);
	}

	public OutputWriter(java.io.Writer writer){
		super(writer);
	}

	}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define For(i,j,k) for(int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for(int i=(int)(j);i>=(int)(k);i--)
inline ll read(){
	ll x=0;char ch=getchar();bool f=0;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=1;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return f?-x:x;
}
void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);putchar(x%10+'0');
}
void writeln(ll x){write(x);puts("");}
void writep(ll x){write(x);putchar(' ');}
const int N=35;
const int num[3]={7,4,0};
int b[N],opt;
ll ans[N];
bool f[N][N][10];
struct info{
	int a[10],sum;
	int& operator [](int x){
		return a[x];
	}
}ycl[N];
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
pii zy[N][N][10];
void init(int u,int pre,int sum){
	if(u==7){
		ycl[++opt].sum=sum;
		For(i,1,6) ycl[opt][i]=b[i];
		return;
	}
	For(i,pre,2){
		b[u]=num[i];
		init(u+1,i,sum+num[i]);
	}
}
int main(){
	init(1,0,0);
	int T=read();
	while(T--){
		memset(ans,0,sizeof(ans));
		memset(f,0,sizeof(f));
		For(i,1,19) For(j,1,opt){
			For(k,0,9) zy[i][j][k]=mp(0,0);
		}
		ll n=read();int pos=1;
		For(i,1,opt){
			if(ycl[i].sum%10==n%10){
				f[1][i][ycl[i].sum/10]=1;
				zy[1][i][ycl[i].sum/10]=mp(0,0);
			}
		}
		n/=10;
		For(i,2,19){
			if(n==0) break;
			int p=n%10;
			For(j,1,opt){
				For(k,1,opt){
					int x=ycl[j].sum%10,t=(p-x+10)%10;
					if(f[i-1][k][t]){
						int tot=ycl[j].sum+t;
						f[i][j][tot/10]=1;
						zy[i][j][tot/10]=mp(k,t);
						break;
					}
				}
			}
			pos=i;n/=10;
		}
		bool d=0;
		For(i,1,opt){
			if(f[pos][i][0]){
				int x=pos,y=i,z=0;
				while(x){
					pii t=zy[x][y][z];
					For(o,1,6) ans[o]=(ll)10*ans[o]+ycl[y][o];
					x--;y=t.fi;z=t.se;
				}
				d=1;
				break;
			}
		}
		if(!d) puts("-1");
		else{
			For(i,1,6) writep(ans[i]);
			puts("");
		}
	}
}
/*
5
42
17
444
7
51

*///hello


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

#define scl(x) scanf("%lld",&x)
#define sc(x)  scanf("%d",&x)
#define ll long long
#define lop(i,n) for(int i=0;i<n;++i)
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

int memo[20][7],t,n;
string x;

int solve(int idx,int carry){
	if(idx==-1)return !carry;
	int &ret=memo[idx][carry];
	if(~ret)return ret;
	ret=0;
	for(int c0=0;c0<=6;c0++)
		for(int c4=0;c4+c0<=6;c4++){
			int c7=6-c0-c4;
			if((4*c4+7*c7+carry)%10!=x[idx]-'0')continue;
			if(solve(idx-1,(4*c4+7*c7+carry)/10))return ret=1;
		}
	return ret;
}
ll arr[6];
int main(){
#ifndef ONLINE_JUDGE
	freopen("i.txt","r",stdin);
#endif
	sc(t);
	lop(C,t){
		cin>>x;
		n=x.size();
		memset(memo,-1,sizeof memo);
		if(solve(n-1,0)){
			int idx=n-1,carry=0;
			ll ml=1;
			lop(i,6)arr[i]=0;
			while(~idx){
				for(int c0=0,f=0;c0<=6&&!f;c0++)
					for(int c4=0;c4+c0<=6&&!f;c4++){
						int c7=6-c0-c4;
						if((4*c4+7*c7+carry)%10!=x[idx]-'0')continue;
						if(solve(idx-1,(4*c4+7*c7+carry)/10)){
							int j=0;
							lop(i,c4)arr[j++]+=4*ml;
							lop(i,c7)arr[j++]+=7*ml;
							f=1;
							carry=(4*c4+7*c7+carry)/10;
							idx--;
						}
					}
				ml*=10;
			}
			lop(i,6)printf("%lld%c",arr[i]," \n"[i==5]);
		}
		else puts("-1");
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define For(i,j,k) for(int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for(int i=(int)(j);i>=(int)(k);i--)
inline ll read(){
	ll x=0;char ch=getchar();bool f=0;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=1;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return f?-x:x;
}
void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);putchar(x%10+'0');
}
void writeln(ll x){write(x);puts("");}
void writep(ll x){write(x);putchar(' ');}
const int N=35;
const int num[3]={7,4,0};
int b[N],opt;
ll ans[N];
bool f[N][N][10];
struct info{
	int a[10],sum;
	int& operator [](int x){
		return a[x];
	}
}ycl[N];
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
pii zy[N][N][10];
void init(int u,int pre,int sum){
	if(u==7){
		ycl[++opt].sum=sum;
		For(i,1,6) ycl[opt][i]=b[i];
		return;
	}
	For(i,pre,2){
		b[u]=num[i];
		init(u+1,i,sum+num[i]);
	}
}
int main(){
	init(1,0,0);
	int T=read();
	while(T--){
		memset(ans,0,sizeof(ans));
		memset(f,0,sizeof(f));
		For(i,1,18) For(j,1,opt){
			For(k,0,9) zy[i][j][k]=mp(0,0);
		}
		ll n=read(),m=n;int pos=1;
		For(i,1,opt){
			if(ycl[i].sum%10==n%10){
				f[1][i][ycl[i].sum/10]=1;
				zy[1][i][ycl[i].sum/10]=mp(0,0);
			}
		}
		n/=10;
		For(i,2,18){
			if(n==0) break;
			int p=n%10;
			For(j,1,opt){
				For(k,1,opt){
					int x=ycl[j].sum%10,t=(p-x+10)%10;
					if(f[i-1][k][t]){
						int tot=ycl[j].sum+t;
						f[i][j][tot/10]=1;
						zy[i][j][tot/10]=mp(k,t);
						break;
					}
				}
			}
			pos=i;n/=10;
		}
		bool d=0;
		For(i,1,opt){
			if(f[pos][i][0]){
				int x=pos,y=i,z=0;
				while(x){
					pii t=zy[x][y][z];
					For(o,1,6) ans[o]=(ll)10*ans[o]+ycl[y][o];
					x--;y=t.fi;z=t.se;
				}
				d=1;
				break;
			}
		}
		if(!d) puts("-1");
		else{
			ll tot=0;
			For(i,1,6) tot+=ans[i];
			if(tot!=m) cout<<"#"<<m<<" "<<tot;
			else{
				For(i,1,6) writep(ans[i]);
				puts("");
			}
		}
	}
}
/*
5
42
17
444
7
51

*/


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define For(i,j,k) for(int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for(int i=(int)(j);i>=(int)(k);i--)
inline ll read(){
	ll x=0;char ch=getchar();bool f=0;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=1;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return f?-x:x;
}
void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);putchar(x%10+'0');
}
void writeln(ll x){write(x);puts("");}
void writep(ll x){write(x);putchar(' ');}
const int N=35;
const int num[3]={7,4,0};
int b[N],opt;
ll ans[N];
bool f[N][N][10];
struct info{
	int a[10],sum;
	int& operator [](int x){
		return a[x];
	}
}ycl[N];
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
pii zy[N][N][10];
void init(int u,int pre,int sum){
	if(u==7){
		ycl[++opt].sum=sum;
		For(i,1,6) ycl[opt][i]=b[i];
		return;
	}
	For(i,pre,2){
		b[u]=num[i];
		init(u+1,i,sum+num[i]);
	}
}
int main(){
	init(1,0,0);
	int T=read();
	while(T--){
		memset(ans,0,sizeof(ans));
		memset(f,0,sizeof(f));
		For(i,1,18) For(j,1,opt){
			For(k,0,9) zy[i][j][k]=mp(0,0);
		}
		ll n=read();int pos=1;
		For(i,1,opt){
			if(ycl[i].sum%10==n%10){
				f[1][i][ycl[i].sum/10]=1;
				zy[1][i][ycl[i].sum/10]=mp(0,0);
			}
		}
		n/=10;
		For(i,2,18){
			if(n==0) break;
			int p=n%10;
			For(j,1,opt){
				For(k,1,opt){
					int x=ycl[j].sum%10,t=(p-x+10)%10;
					if(f[i-1][k][t]){
						int tot=ycl[j].sum+t;
						f[i][j][tot/10]=1;
						zy[i][j][tot/10]=mp(k,t);
						break;
					}
				}
			}
			pos=i;n/=10;
		}
		bool d=0;
		For(i,1,opt){
			if(f[pos][i][0]){
				int x=pos,y=i,z=0;
				while(x){
					pii t=zy[x][y][z];
					For(o,1,6) ans[o]=(ll)10*ans[o]+ycl[y][o];
					x--;y=t.fi;z=t.se;
				}
				d=1;
				break;
			}
		}
		if(!d) puts("-1");
		else{
			For(i,1,6) writep(ans[i]);
			puts("");
		}
	}
}
/*
5
42
17
444
7
51

*/


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define For(i,j,k) for(int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for(int i=(int)(j);i>=(int)(k);i--)
inline ll read(){
	ll x=0;char ch=getchar();bool f=0;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=1;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return f?-x:x;
}
void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);putchar(x%10+'0');
}
void writeln(ll x){write(x);puts("");}
void writep(ll x){write(x);putchar(' ');}
const int N=35;
const int num[3]={7,4,0};
int b[N],opt;
ll ans[N];
bool f[N][N][10];
struct info{
	int a[10],sum;
	int& operator [](int x){
		return a[x];
	}
}ycl[N];
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
pii zy[N][N][10];
void init(int u,int pre,int sum){
	if(u==7){
		ycl[++opt].sum=sum;
		For(i,1,6) ycl[opt][i]=b[i];
		return;
	}
	For(i,pre,2){
		b[u]=num[i];
		init(u+1,i,sum+num[i]);
	}
}
int main(){
	init(1,0,0);
	int T=read();
	while(T--){
		memset(ans,0,sizeof(ans));
		memset(f,0,sizeof(f));
		ll n=read();int pos=1;
		For(i,1,opt){
			if(ycl[i].sum%10==n%10){
				f[1][i][ycl[i].sum/10]=1;
				zy[1][i][ycl[i].sum/10]=mp(0,0);
			}
		}
		n/=10;
		For(i,2,18){
			if(n==0) break;
			int p=n%10;
			For(j,1,opt){
				For(k,1,opt){
					int x=ycl[j].sum%10,t=(p-x+10)%10;
					if(f[i-1][k][t]){
						int tot=ycl[j].sum+t;
						f[i][j][tot/10]=1;
						zy[i][j][tot/10]=mp(k,t);
						break;
					}
				}
			}
			pos=i;n/=10;
		}
		bool d=0;
		For(i,1,opt){
			if(f[pos][i][0]){
				int x=pos,y=i,z=0;
				while(x){
					pii t=zy[x][y][z];
					For(o,1,6) ans[o]=(ll)10*ans[o]+ycl[y][o];
					x--;y=t.fi;z=t.se;
				}
				d=1;
				break;
			}
		}
		if(!d) puts("-1");
		else{
			For(i,1,6) writep(ans[i]);
			puts("");
		}
	}
}
/*
5
42
17
444
7
51

*/


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define For(i,j,k) for(int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for(int i=(int)(j);i>=(int)(k);i--)
inline ll read(){
	ll x=0;char ch=getchar();bool f=0;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=1;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return f?-x:x;
}
void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);putchar(x%10+'0');
}
void writeln(ll x){write(x);puts("");}
void writep(ll x){write(x);putchar(' ');}
const int N=35;
const int num[3]={7,4,0};
int b[N],opt;
ll ans[N];
bool f[N][N][10];
struct info{
	int a[10],sum;
	int& operator [](int x){
		return a[x];
	}
}ycl[N];
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
pii zy[N][N][10];
void init(int u,int pre,int sum){
	if(u==7){
		ycl[++opt].sum=sum;
		For(i,1,6) ycl[opt][i]=b[i];
		return;
	}
	For(i,pre,2){
		b[u]=num[i];
		init(u+1,i,sum+num[i]);
	}
}
int main(){
	init(1,0,0);
	int T=read();
	while(T--){
		memset(ans,0,sizeof(ans));
		memset(f,0,sizeof(f));
		For(i,1,19) For(j,1,opt){
			For(k,0,9) zy[i][j][k]=mp(0,0);
		}
		ll n=read();int pos=1;
		For(i,1,opt){
			if(ycl[i].sum%10==n%10){
				f[1][i][ycl[i].sum/10]=1;
				zy[1][i][ycl[i].sum/10]=mp(0,0);
			}
		}
		n/=10;
		For(i,2,19){
			if(n==0) break;
			int p=n%10;
			For(j,1,opt){
				For(k,1,opt){
					int x=ycl[j].sum%10,t=(p-x+10)%10;
					if(f[i-1][k][t]){
						int tot=ycl[j].sum+t;
						f[i][j][tot/10]=1;
						zy[i][j][tot/10]=mp(k,t);
						break;
					}
				}
			}
			pos=i;n/=10;
		}
		bool d=0;
		For(i,1,opt){
			if(f[pos][i][0]){
				int x=pos,y=i,z=0;
				while(x){
					pii t=zy[x][y][z];
					For(o,1,6) ans[o]=(ll)10*ans[o]+ycl[y][o];
					x--;y=t.fi;z=t.se;
				}
				d=1;
				break;
			}
		}
		if(!d) puts("-1");
		else{
			For(i,1,6) writep(ans[i]);
			puts("");
		}
	}
}
/*
5
42
17
444
7
51

*/


#include <iostream>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <iomanip>
#include <queue>
#include <utility>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, char> pci;

const int kN = 20;
const int kD = 10;

int num[kN];
int dp[kN + 1][kD + 1];
int path[kN + 1][kD + 1];
int ans[6][kN];

map<int, vector<int>> moves;

int DP(int n, int carry) {
    if (n == 0) {
        return carry == 0 ? 1 : 0;
    }
    if (dp[n][carry] == -1) {
        dp[n][carry] = 0;
        for (const auto& pr : moves) {
            int sum = pr.first;
            if ((sum + carry) % 10 == num[n - 1] && DP(n - 1, (sum + carry) / 10)) {
                dp[n][carry] = 1;
                path[n][carry] = sum;
            }
        }
    }
    return dp[n][carry];
}

void GenMoves() {
    vector<int> arr = {0, 4, 7};
    for (int a1 : arr) for (int a2 : arr) for (int a3 : arr) for (int a4: arr) for (int a5 : arr) for (int a6 : arr) {
        moves[a1 + a2 + a3 + a4 + a5 + a6] = {a1, a2, a3, a4, a5, a6};
    }
}

void WriteAns() {
    memset(ans, 0, sizeof(ans));
    int ind = kN;
    int carry = 0;
    while (path[ind][carry] != -1) {
        int sum = path[ind][carry];
        for (int i = 0; i < 6; ++i) { ans[i][ind - 1] = moves[sum][i]; }
        --ind;
        carry = (carry + sum) / 10;
    }
    for (int i = 0; i < 6; ++i) {
        ll res = 0;
        for (int j = 0; j < kN; ++j) {
            res = res * 10 + ans[i][j];
        }
        cout << res << ' ';
    }
    cout << '\n';
}

void Write(ll n) {
    memset(num, 0, sizeof(num));
    int ind = kN - 1;
    while (n) {
        num[ind--] = n % 10;
        n /= 10;
    }
}

int main() {
    std::ios_base::sync_with_stdio(false);
    GenMoves();
    int tests_count;
    cin >> tests_count;
    for (int test_index = 0; test_index < tests_count; ++test_index) {
        ll n;
        cin >> n;
        Write(n);
        memset(dp, 255, sizeof(dp));
        memset(path, 255, sizeof(path));
        if (DP(kN, 0) == 0) {
            cout << "-1\n";
            continue;
        }
        WriteAns();
    }
    return 0;
}