for i in range(int(input())):
    n = int(input())
    j = 0
    while n >= 10:
        m_max = 0
        for k in range(1, int(log10(n)) + 1):
            m = (n // (10**k)) * (n % (10**k))
            if m >= m_max:
                m_max = m
        n = m_max
        j += 1
    print(j)