def recur(n, count):
    if n < 10:
        print(count)
        return
    part = []
    i = 10
    while i < n:
        part.append((n%i) * (n/i))
        i *= 10
    recur(max(part), count+1)


q = int(raw_input())
for i in range(q):
    n = int(raw_input())
    lst = []
    recur(n, 0)