#include <iostream>
#include <string>
using namespace std;
int main () {
int input[10000],output[10000],cases,iL,oL;
long double mul,rem;
string tmp;
cin >> cases;
for(int i=0;i<cases;i++) {
cin >> tmp;
iL = 0; oL = 0;
if(tmp.length()%2==1) {
input[0] = tmp[0]-48;
iL++;
for(int j=1;j<tmp.length();iL++,j++) {
input[iL] = tmp[j]-48;
input[iL] = input[iL]*10 + (tmp[j+1]-48);
j++;
}
}
else {
for(int j=0;j<tmp.length();iL++,j++) {
input[iL] = tmp[j]-48;
input[iL] = input[iL]*10 + (tmp[j+1]-48);
j++;
}
}
//for(int j=0;j<iL;j++) cout << input[j] << " "; //check input
mul = 0; rem = 0;
for(int j=0;j<iL;j++) {
rem = rem*100 + input[j];
for(int k=9;k>=0;k--) {
if((mul*10+k)*k <= rem) {
rem = rem - (mul*10+k)*k;
//cout << "debug : " << mul*10+k << " " << rem << " ";
mul = mul*10+k*2;
//cout << mul << endl;
output[oL] = k;
oL++;
break;
}
}
}
for(int j=0;j<oL;j++) cout << output[j]; //check output
cout << endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPiAKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluICgpIHsKICAgIGludCBpbnB1dFsxMDAwMF0sb3V0cHV0WzEwMDAwXSxjYXNlcyxpTCxvTDsKCWxvbmcgZG91YmxlIG11bCxyZW07CglzdHJpbmcgdG1wOwoJY2luID4+IGNhc2VzOwoJZm9yKGludCBpPTA7aTxjYXNlcztpKyspIHsKCQljaW4gPj4gdG1wOwoJCWlMID0gMDsgb0wgPSAwOwoJCWlmKHRtcC5sZW5ndGgoKSUyPT0xKSB7CgkJCWlucHV0WzBdID0gdG1wWzBdLTQ4OwoJCQlpTCsrOwoJCQlmb3IoaW50IGo9MTtqPHRtcC5sZW5ndGgoKTtpTCsrLGorKykgewoJCQkJaW5wdXRbaUxdID0gdG1wW2pdLTQ4OwoJCQkJaW5wdXRbaUxdID0gaW5wdX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