q = gets.to_i
q.times{
	hash = {}
	n = gets.to_i
	loop {
		if hash[n] 
			puts -1
			break
		end
		hash[n] = 0
		
		a = n.to_s.split("")
		if a.size == 1
			puts hash.size - 1
			break 
		else
			n = (0..a.size-2).map{|i|
				a[0..i].join.to_i * a[i+1..-1].join.to_i	
			}.max
		end
	}
}