n = gets.to_i
n.times do
  x = gets.to_i
  count = 0
  while x > 9
    x   = x.to_s
    max = 0
    for i in 0 .. x.size - 2
      max = [max, (x[0 .. i].to_i) * (x[i + 1 .. x.size - 1].to_i)].max
    end
    if max >= x.to_i
      puts -1
      break
    end
    count += 1
    x = max
  end
  if x < 10
    puts count
  end
end

