n = gets.to_i
n.times do |i|
  x = gets.to_i
  res = 0

  xs = x.to_s
  while xs.size > 1 do
    maxx = 0

    xs.size.times do |j|
      tmpx = xs[(0...j + 1)].to_i * xs[j + 1...xs.size].to_i
      maxx = [tmpx, maxx].max
    end

    xs = maxx.to_s
    res += 1
  end
  p res
end