#include using namespace std; // #include // using namespace atcoder; // using mint = modint998244353; using ll = long long; #define fix(x) fixed << setprecision(x) #define rep(i, n) for(int i = 0; i < n; ++i) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a> mp; vector>> a; vector v(5559); for(int i=1;i<=5558;++i){ int x = 0, m = i, o = 1; while(m){ x += (m%3 + (m%3)/2*6)*o; m /= 3; o *= 10; } v[i] = x; mp[x] = {x}; for(int j=1;j<=i;++j) mp[v[j]+x] = {v[j], x}; } for(auto p:mp) a.emplace_back(p); sort(all(a)); int m = a.size(); int t; cin >> t; while(t--){ int n; cin >> n; n = 81181819 - n; vector ans; ans.assign(7,0); int k = n, o = 1; while(k){ int x = k % 10; if(x>=8) ans[0] += 7 * o, x -= 7; rep(i,x) ans[i] += o; k /= 10, o *= 10; } if(mp.count(n)) ans = mp[n]; else{ for(int l=0,r=m-1;;++l){ while(r>=0 || a[l].first+a[r].first>n) --r; if(ra[l].second.size()+a[r].second.size()){ ans.resize(0); for(int x:a[l].second) ans.emplace_back(x); for(int x:a[r].second) ans.emplace_back(x); }else if(mp.count(n-a[l].first-a[r].first)){ auto& v = mp[n-a[l].first-a[r].first]; if(ans.size()>a[l].second.size()+a[r].second.size()+v.size()){ ans.resize(0); for(int x:a[l].second) ans.emplace_back(x); for(int x:a[r].second) ans.emplace_back(x); for(int x:v) ans.emplace_back(x); } } } } cout << ans.size() << '\n'; for(int x:ans) cout << x << '\n'; } return 0; }