#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include "stdlib_printing.hh"
using namespace std;
typedef long long LL;
LL inf = 1e18;
int main(int argc, char** argv){
// Precalc
vector<LL> f(1e6+1,inf);
f[0] = 0;
for(LL x = 1; x <= 1e6; x++){
LL y = x;
while(y != 0){
LL d = y % 10; y /= 10;
if(x - d >= 0) f[x] = min(f[x], f[x-d]+1);
}
}
vector<LL> answers(1e6+1,inf);
for(LL s = 1e6; s >= 1; s--){
answers[f[s]] = s;
}
// Solve
LL t; cin >> t;
while(t--){
LL n; cin >> n;
if(answers[n] == inf) cout << -1 << "\n";
else cout << answers[n] << "\n";
}
}