importjava.util.Scanner;publicclassMain{publicstaticintfunc(int res){int sum =0;while(res!=0){int s = res%10;
sum+=s;
res/=10;}return sum;}publicstaticvoidmain(String[] args){Scanner sc =newScanner(System.in);int t = sc.nextInt();
sc.nextLine();while(t!=0){int n = sc.nextInt();
sc.nextLine();int res =1;int sum =0;while(res<=n){if(res == n){System.out.println(sum);break;}
res = res+func(res);
sum++;}if(res>n){System.out.println("-1");}
t--;}
sc.close();}}