for _ in range(int(input())):
    n=int(input())
    a=0;b=[]
    while n//10:
        a+=1
        b+=[n]+b
        x=1;s=m=0
        while n:
            s+=x*(n%10)
            n//=10
            x*=10
            m=max(s*n,m)
        n=m
        if b[-1]==n:print(-1);break
    else:print(a)