gets.to_i.times{
  n=gets.to_i
  count = 0
  array = []
  
  while true
    break if n/10 == 0
    if array.index(n) != nil
      count = -1
      break
    end

    ns = n.to_s.split("")
    products=[]
    ns.length.times{|t|
      products.push ns[0..t].join.to_i * ns[t+1..ns.length-1].join.to_i
    }
    n = products.max

    count += 1
  end

  p count
}