#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
int temp;
bool a=true;
cin>>temp;
int c=0,tt=temp;
while(tt>0){
tt/=10;
c++;
}
for(int j=temp-c*9;j<temp;j++){
int sum=j;
int t=j;
while(t>0){
sum+=t%10;
t/=10;
}
if(sum==temp){
cout<<j<<endl;
a=false;
break;
}
}
if(a)cout<<'0'<<endl;
}
return 0;
}