q = int(raw_input())
for i in range(q):
	n = raw_input()
	num = 0
	while 1:
		length = len(n) 
		if length == 1:
			break
		num += 1
		tmp = 0
		for i in range(1,length):
			tmp = max(tmp, int(n[:i])*int(n[i:]))
		n = str(tmp)
	print num