def calcStep(x)
  if 0 <= x && x < 10
    step = 0

  elsif
    string = x.to_s
    digit = string.length
    multiArray = []
    for i in 0..(digit - 2)
      multiArray << string[0..i].to_i * string[(i + 1)..(digit - 1)].to_i
    end
    step = calcStep(multiArray.max) + 1
  end
  
  return step
end

ansArray = []

num = gets.chomp.to_i

for i in 0..(num - 1)
  ansArray << calcStep(gets.chomp.to_i)
end

ansArray.each{|x|
  p x
}