#include "atcoder/fenwicktree.hpp" #include #include using namespace std; using isize = size_t; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; using i128 = __int128_t; using u128 = __uint128_t; using f64 = long double; using p2 = pair; using el = tuple; using mint = atcoder::modint998244353; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } i64 pow(i64 x, i64 n) { i64 res = 1; i64 t = x; while (n > 0) { if (n & 1) { res = res * t; } t = t * t; n >>= 1; } return res; } i64 pow(i64 x, i64 n, i64 m) { i64 res = 1; i64 t = x % m; while (n > 0) { if (n & 1) { res = res * t % m; } t = t * t % m; n >>= 1; } return res; } vector> mul(vector> &a, vector> &b) { vector> res(a.size(), vector(b[0].size(), 0)); assert(a[0].size() == b.size()); for (i64 i = 0; i < a.size(); i++) { for (i64 j = 0; j < b[0].size(); j++) { for (i64 k = 0; k < b.size(); k++) { res[i][j] += a[i][k] * b[k][j]; } } } return res; } vector> pow(vector> &a, i64 n) { assert(a.size() == a[0].size()); vector> res(a.size(), vector(a[0].size(), 0)); vector> t = a; for (i64 i = 0; i < a.size(); i++) res[i][i] = 1; while (n > 0) { if (n & 1) { vector> nres = mul(res, t); swap(res, nres); } vector> nt = mul(t, t); swap(nt, t); n >>= 1; } return res; } void _main() { i64 ttt; cin >> ttt; vector> dp(10000, {-1, -1, -1, -1}); for (i64 n = 1; n < dp.size(); n++) { for (i64 a = 0; a * 1111 <= n; a++) { for (i64 b = 0; a * 1111 + b * 111 <= n; b++) { for (i64 c = 0; a * 1111 + b * 111 + c * 11 <= n; c++) { i64 d = n - a * 1111 - b * 111 - c * 11; i64 s = a + b + c + d; i64 mx = max(a, max(b, max(c, d))); if (mx * 2 < s) { dp[n] = {d, c, b, a}; } } } } } while (ttt--) { i64 n; cin >> n; if (n % 8 != 0) { cout << "-1\n"; continue; } n /= 8; if (n >= 10000) { i64 base = n / 1234; n -= base * 1234; vector p = {1, 11, 111, 1111}; vector ans(4, 0); for (i64 i = 3; i >= 0; i--) { ans[i] = base + n / p[i]; n %= p[i]; } for (i64 x : ans) cout << x << " "; cout << "\n"; continue; } vector v = dp[n]; if (v[0] == -1) { cout << "-1\n"; } else { for (i64 x : v) cout << x << " "; cout << "\n"; } } }