#include using namespace std; const int N = 81181819; std::vector Bs; vector calc(int X, int mx, int mlen = 7, vector ans = {}) { if (!X) { return ans; } if (ans.size() >= mlen) return {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; vector ret = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; for (auto& a : Bs) { if (a > mx || a > X) continue; int Y = X - a; ans.push_back(a); auto b = calc(Y, a, mlen, ans); if (b.size() <= mlen) { ret = b; mlen = b.size(); } ans.pop_back(); } return ans; } int main () { int L = (((((((2 * 3) + 1) * 3 + 1) * 3 + 2) * 3 + 1) * 3 + 2) * 3 + 1) * 3 + 2; int XX[] = {0, 1, 8}; for (int i = L; i >= 0; i --) { int y = 0; int b = 1; int j = i; while (j) { y += b * XX[j % 3]; j /= 3; b *= 10; } Bs.push_back(y); } int T; cin >> T; while (T--) { int n; cin >> n; auto ret = calc(N - n, N); cout << ret.size() << endl; for (auto a : ret) cout << a << endl; } }