
def solve(n)
    lop = 0
    while n >= 10
        s = n.to_s
        n = 0
        (s.size-1).times do |i|
            u,v = s[0..i].to_i, s[(i+1)..-1].to_i
            n = [n,u*v].max
        end
        lop += 1
    end
    lop
end

gets.to_i.times do
    n = gets.to_i
    p solve(n)
end
