#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); vector stk, S; vector a = {1, 11, 111, 1111}; vector> ope; reverse(a.begin(), a.end()); int sv = 0; constexpr int r = 20; vector S2(12); vector> op2(12); auto dfs = [&](auto dfs, int p, int pay) -> void { if(p == 4){ for(auto v : stk){ if(2 * v >= sv) return; } S.emplace_back(pay); ope.emplace_back(stk); // mod 12 で分類 if(S2[pay % 12] == 0){ S2[pay % 12] = pay; op2[pay % 12] = stk; } return; } for(int i = 0; i <= r; i++){ stk.emplace_back(i); sv += i; dfs(dfs, p + 1, pay + a[p] * i); sv -= i; stk.pop_back(); } }; dfs(dfs, 0, 0); int T; cin >> T; array ans; while(T--){ ll n; cin >> n; ans.fill(0); if(n % 8 != 0){ cout << "-1\n"; continue; } n /= 8; if(n <= 592){ int p = lower_bound(S.begin(), S.end(), n) - S.begin(); if(n == S[p]){ for(int i = 0; i < 4; i++){ cout << ope[p][3 - i] << (i == 3 ? '\n' : ' '); } }else{ cout << "-1\n"; } continue; } int mod = n % 12; for(int i = 0; i < 4; i++){ ans[i] += op2[mod][3 - i]; } n -= S2[mod]; n /= 12; ans[0] += n; ans[1] += n; for(int i = 0; i < 4; i++) cout << ans[i] << (i == 3 ? '\n' : ' '); } }