gets.to_i.times do
  n = gets.to_i
  hash = {}
  res = 0
  while true do
    s = n.to_s
    break if s.size == 1
    if hash[n]
      res = -1
      break
    else
      res += 1
      hash[n] = 1
    end
    n = s.size.times.map{|i|
      a = s[0..i]
      b = s[i.succ...s.size]
      a.to_i * b.to_i
    }.max
  end
  p res
end