for i in range(int(input())):
    n = int(input())
    j = 0
    while n >= 10:
        L = [(n // (10**k)) * (n % (10**k))
             for k in range(1, int(log10(n)) + 1)]
        n = max(L)
        j += 1
    print(j)