n = gets.to_i
n.times do
    r = gets.to_i
    break if r == 0
    i = 0
    while r >= 10
        max = 0
        (r.to_s.length - 1).times do |l|
            str = r.to_s
            a = str[0..l].to_i
            b = str[(l + 1)...str.length].to_i
            max = a * b if a * b > max
        end
        r = max
        i += 1
    end
    puts i
end