def mul(n, cnt = 0)
  ns = []
  if n.size == 1
    return cnt
  else
    (n.size-1).times do |i|
      ns << n[0..i].to_i * n[i+1..-1].to_i
    end
    cnt += 1
    mul(ns.max.to_s, cnt)
  end
end

gets.to_i.times do
  n = gets.strip
  p mul(n)
end