#times volume24 2424
Q=int(input())
for i in range(Q):
    N=str(input())
    c=0
    while len(N)>1 and c<15:
        M=0
        for j in range(1,len(N)):
  #          print(N[:j])
            l=int(N[:j])
            r=int(N[j:])
            l*=r
            if M<l:
                M=l
        #    print(M)
        N=str(M)
        c+=1
    if c>=15:
        d=[int(N)]
        while c>=0 and c<50:
            while len(N)>1 and c<50:
                M=0
                for j in range(1,len(N)):
  #          print(N[:j])
                    l=int(N[:j])
                    r=int(N[j:])
                    l*=r
                    if M<l:
                        M=l
        #    print(M)
                k=0
                while k<len(d) and M<d[k]:
                    k+=1
                if M==d[k]:
                    c=-1
                else:
                    d.insert(j,M)
                N=str(N)
    print(c)