import sys

import math

Q = sys.stdin.readline()

for _ in range(int(Q)):

    cnt = 0

    N = int(sys.stdin.readline())

    if N != 0:

        digLeng = int(math.log10(N)) + 1

    else:

        digLeng = 1

    while digLeng > 1:

        Nmax = 0

        for dig in range(digLeng):

            lNum = N // int(math.pow(10,dig))

            rNum = N % int(math.pow(10,dig))

            Nmax = max(Nmax,lNum * rNum)

        N = Nmax

        cnt += 1

        if N != 0:

            digLeng = int(math.log10(N)) + 1

        else:

            digLeng = 1

    print(cnt)
from math import log10



for i in range(int(eval(input()))):

    n = int(eval(input()))

    j = 0

    while n >= 10:

        n = max((n // (10**k)) * (n % (10**k)) for k in range(1, int(log10(n)) + 1))

        j += 1

    print(j)
import sys
import math

Q = sys.stdin.readline()
for _ in range(int(Q)):
    cnt = 0
    N = int(sys.stdin.readline())
    if N != 0:
        digLeng = int(math.log10(N)) + 1
    else:
        digLeng = 1
    while digLeng > 1:
        Nmax = 0
        for dig in range(digLeng):
            lNum = N // int(math.pow(10, dig))
            rNum = N % int(math.pow(10, dig))
            Nmax = max(Nmax, lNum * rNum)
        N = Nmax
        cnt += 1
        if N != 0:
            digLeng = int(math.log10(N)) + 1
        else:
            digLeng = 1
    print(cnt)

from math import log10

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

-import sys -import math +from math import log10 -Q = sys.stdin.readline() -for _ in range(int(Q)): -    cnt = 0 -    N = int(sys.stdin.readline()) -    if N != 0: -        digLeng = int(math.log10(N)) + 1 -    else: -        digLeng = 1 -    while digLeng > 1: -        Nmax = 0 -        for dig in range(digLeng): -            lNum = N // int(math.pow(10, dig)) -            rNum = N % int(math.pow(10, dig)) -            Nmax = max(Nmax, lNum * rNum) -        N = Nmax -        cnt += 1 -        if N != 0: -            digLeng = int(math.log10(N)) + 1 -        else: -            digLeng = 1 -    print(cnt) +for i in range(int(eval(input()))): +    n = int(eval(input())) +    j = 0 +    while n >= 10: +        n = max((n // (10**k)) * (n % (10**k)) for k in range(1, int(log10(n)) + 1)) +        j += 1 +    print(j)