#!/usr/bin/env python
Q = input()

for loop in range(Q):
	n = str(input())
	cnt = 0
	while len(n) > 1:
		cnt += 1
		nmin = 0
		for i in range(len(n) - 1):
			n1 = int(n[:i + 1])
			n2 = int(n[i + 1:])
			nmin = max(nmin, n1 * n2)
		n = str(nmin)
	print(cnt)
