#include <bits/stdc++.h>

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

#define rand() ((rand()<<15)+rand())

const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
template<typename T>
struct chash {
	int operator()(T x) { return hash<T>{}(x ^ RANDOM); }
};
template<typename Key, typename Value>
using hash_map = gp_hash_table<Key, Value, chash<Value>>;
template<typename T, typename Cmp = less<T>>
using oset = tree<T, null_type, Cmp, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long lint;
typedef complex<double> point;

const int INF = 0x3f3f3f3f;
const lint INFL = 0x3f3f3f3f3f3f3f3fLL;
const double E = 1e-9, pi = 2 * acos(0);

template<typename T, typename U> void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> void amax(T &x, U y) { if (x < y) x = y; }

const int M = 6;

bool solve(int testNumber) {
	if (testNumber == 1) {
		cin >> testNumber;
	}
	lint n;
	if (!(cin >> n)) {
		return false;
	}
	vector<int> digs;
	for (; n; n /= 10) {
		digs.push_back(n % 10);
	}
	int nn = (int)digs.size();
	vector<vector<pair<int, int>>> dp(nn + 1, vector<pair<int, int>>(M, {-1, -1}));
	dp[0][0] = {-2, -2};
	for (int i = 1; i <= nn; i++) {
		for (int j = 0; j < M; j++) {
			int need = 10 * j + digs[i - 1];
			for (int k = 0; k <= M; k++) {
				for (int l = 0; l <= M - k; l++) {
					int have = k * 4 + l * 7;
					if (need >= have and need - have < M and dp[i - 1][need - have] != make_pair(-1, -1)) {
						dp[i][j] = {k, l};
					}
				}
			}
		}
	}
	vector<lint> ans;
	if (dp[nn][0] == make_pair(-1, -1)) {
		ans = {-1};
	} else {
		int p = nn, r = 0;
		ans.resize(M);
		while (p) {
			int n4, n7;
			tie(n4, n7) = dp[p][r];
			for (int i = 0; i < n7; i++) {
				ans[i] = 10 * ans[i] + 7;
			}
			for (int i = n7; i < n7 + n4; i++) {
				ans[i] = 10 * ans[i] + 4;
			};
			r = 10 * r + digs[p - 1] - n4 * 4 - n7 * 7;
			p--;
		}
	}
	for (lint x: ans) {
		printf("%lld ", x);
	}
	printf("\n");
	return true;
}

void init(const char *in = nullptr, const char *out = nullptr) {
	if (in) freopen(in, "r", stdin);
	if (out) freopen(out, "w", stdout);
	srand(unsigned((long long)new char));
}

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(nullptr);
	init();
	for (int i=1; solve(i); i++);
	return 0;
}

