#include #include #include using namespace std; using ll = long long; int main(void){ ll mx=81181819; vector Ten(10, 1); for(int i=1; i<10; i++) Ten[i]=Ten[i-1]*10ll; int t; cin >> t; while(t--){ ll n; cin >> n; ll tar=mx-n; if(tar<8){ cout << tar << endl; for(int i=0; i> ans(10); auto DFS=[&](auto DFS, int di, ll now, ll maxi, vector> path){ //cout << di << ' ' << now << ' ' << maxi << endl; if(di==0){ if(now==0&&Max>maxi){ Max=maxi, ans=path; } return; } ll ten=Ten[di-1]; if(now/ten>=100) return; {//ten, ten, ..., ten for(ll i=0; i<=7; i++){ if(ten*i>now) break; if(i) path[di].push_back(ten); //cout << di << ' ' << now << ' ' << i << ' ' << now-i*ten << ' ' << ten << endl; DFS(DFS, di-1, now-i*ten, max(maxi, i), path); } } path[di].clear(); {//8*ten, 8*ten, ..., ten for(ll i=1; i<=7; i++){ if(ten*(8*i)>now) break; vector pa(i, 8*ten); path[di]=pa; for(ll j=0; j<2; j++){ if(ten*(8*i+j)>now) break; if(j) path[di].push_back(ten); DFS(DFS, di-1, now-ten*(8*i+j), max(maxi, i+j), path); } } } }; vector> emp(10); DFS(DFS, d, tar, 0, emp); cout << Max << endl; // for(auto p:ans){ // for(auto q:p) cout << q << ' '; cout << endl; // } for(int i=0; ii) num+=ans[j][i]; } cout << num << endl; } } return 0; }