import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
for (int i = 0; i < t; i++) {
int n =sc.nextInt();
int sum=0;
int res=0;
boolean flag=false;
for (int j = 1; j <= n; ) {
res++;
sum=j+Sum(j);
j=sum;
if(sum==n) {
flag = true;
break;
}
}
if(flag)
System.out.println(res);
else System.out.println(-1);
}
}
public static int Sum(int n){
int sum=0;
while (n>0){
sum+=n%10;
n=n/10;
}
return sum;
}
}