#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; } int main() { ios::sync_with_stdio(false); cin.tie(0); map trans; trans[0] = {0, 0}; rep(_, 7) { auto nt = trans; for (auto [v, c18] : trans) { auto [c1, c8] = c18; nt.emplace(v + 1, P{c1 + 1, c8}); nt.emplace(v + 8, P{c1, c8 + 1}); } swap(nt, trans); } int p10[9]; p10[0] = 1; rep(i, 8) p10[i+1] = p10[i] * 10; int tt; cin >> tt; while (tt--) { int n; cin >> n; n = 81181819 - n; map dp[9]; dp[0][0] = {0, -1}; int digit[8]; rep(i, 8) { int x = n % 10; digit[i] = x; n /= 10; for (auto [v, mxpre] : dp[i]) { auto [mx, pre] = mxpre; for (auto [add, c18] : trans) if ((v + add) % 10 == x) { int nmx = max(mx, c18.first + c18.second); auto [it, inserted] = dp[i+1].emplace((v + add) / 10, P{nmx, v}); if (!inserted && nmx < it->second.first) { it->second = P{nmx, v}; } } } } VI ans(dp[8][0].first); assert(!ans.empty()); rrep(i, 8) { auto [mx, pre] = dp[i+1][n]; int add = 10 * n + digit[i] - pre; auto [c1, c8] = trans[add]; int ptr = 0; rep(_, c1) ans[ptr++] += p10[i]; rep(_, c8) ans[ptr++] += p10[i] * 8; n = pre; } cout << ans.size() << '\n'; for (int x : ans) cout << x << '\n'; } }