#! /usr/bin/python
# -*- coding: utf-8 -*-

def MaxPro(val):
    mul = 10
    dig = 1
    while val >= mul:
        dig += 1
        mul *= 10
    Max = 0
    for i in range(1, dig):
        tmp = (val%(10**i))*(val/10**i)
        if Max < tmp:
            Max = tmp
    return Max

def ProCnt(val, cnt):
    if val<10:
        return cnt
    else:
        return ProCnt(MaxPro(val), cnt+1)

q = int(raw_input())
for i in range(q):
    n = int(raw_input())
    print ProCnt(n, 0)
    