import sys

def logic(N):
  counter = 0
  while True:
    if N < 10: break
    maxmult = 0
    i = 1
    while True:
      a = N % (10**i)
      if N == a: break
      b = (N-a) / (10**i)
      maxmult = max(maxmult, a*b)
      i += 1
    N = maxmult
    counter += 1
  print counter

Q = int(raw_input())
for _ in xrange(Q):
  N = int(raw_input())
  logic(N)