import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Scanner;

public class E {

	static Scanner sc = new Scanner(System.in);
	static int[] back = new int[50000];

	public static void main(String[] args) {
		test();
		int T = sc.nextInt();
		for (int i = 0; i < T; ++i) {
			solve(sc.nextLong());
		}
	}

	static void solve(long n) {
		if (n < back.length && back[(int) n] == -1) {
			System.out.println(-1);
			return;
		}

		ArrayList<Integer> vs = new ArrayList<>();
		ArrayList<Long> base = new ArrayList<>();
		long b = 1;
		while (n > 0) {
			vs.add((int) (n % 10000));
			base.add(b);
			n /= 10000;
			b *= 10000;
		}
		long[][] ans = new long[vs.size()][6];
		boolean result = dfs(vs, ans, 0);
		if (!result) {
			System.out.println(-1);
			return;
		}
		long[] ret = new long[6];
		for (int i = 0; i < vs.size(); ++i) {
//			System.out.println(Arrays.toString(ans[i]));
			for (int j = 0; j < 6; ++j) {
				ret[j] += ans[i][j] * base.get(i);
			}
		}
		for (int i = 0; i < 5; ++i) {
			System.out.print(ret[i] + " ");
		}
		System.out.println(ret[5]);
	}

	static boolean dfs(ArrayList<Integer> v, long[][] ans, int depth) {
		if (depth == v.size()) return true;
		int cur = v.get(depth);
		for (int i = 0; i < 5; ++i) {
			if (depth < v.size() - 1 && i > v.get(depth + 1)) return false;
			if (depth == v.size() -1 && i > 0) return false;
			int rest = cur + i * 10000;
			if (back[rest] == -1) continue;
			if (depth < v.size() - 1) {
				v.set(depth + 1, v.get(depth + 1) - i);
			}
			for (int j = 0; j < 6; ++j) {
				ans[depth][j] = back[rest];
				rest -= back[rest];
			}
			if (dfs(v, ans, depth + 1)) return true;
			for (int j = 0; j < 6; ++j) {
				ans[depth][j] = 0;
			}
			if (depth < v.size() - 1) {
				v.set(depth + 1, v.get(depth + 1) + i);
			}
		}
		return false;
	}

	static void test() {
		ArrayList<ArrayList<Integer>> list = new ArrayList<>();
		for (int i = 0; i < 5; ++i) {
			list.add(new ArrayList<Integer>());
		}
		list.get(0).add(4);
		list.get(0).add(7);
		for (int i = 1; i < 5; ++i) {
			for (int v : list.get(i - 1)) {
				list.get(i).add(v * 10);
				list.get(i).add(v * 10 + 4);
				list.get(i).add(v * 10 + 7);
			}
		}
		ArrayList<Integer> all = new ArrayList<>();
		for (ArrayList<Integer> l : list) {
			for (int v : l) {
				all.add(v);
			}
		}
		Arrays.fill(back, -1);
		back[0] = 0;
		BitSet bs = new BitSet(back.length + 1);
		bs.set(0);
		for (int i = 0; i < 6; ++i) {
			for (int j = back.length - 1; j >= 0; --j) {
				if (bs.get(j)) continue;
				for (int v : all) {
					if (j - v < 0) break;
					if (bs.get(j - v)) {
						back[j] = v;
						bs.set(j);
						break;
					}
				}
			}
		}

		//		for (int i = bs.nextClearBit(0); i >= 0 && i < bs.size(); i = bs.nextClearBit(i + 1)) {
		//			System.out.print(i + " ");
		//		}
		//		System.out.println();
	}

}
