//???????????????????????????????????????????°??????????????????¨?????????????????§, ???????????§???????????????
#include <iostream>
#include <algorithm>
using namespace std;

int power10[8];

int next(int n) {
	int ret = 0;
	for (int i = 1; i < 7; i++) {
		int a = n / power10[i];
		int b = n % power10[i];
		ret = max(ret, a * b);
	}
	return ret;
}

int main() {
	int q, n;
	
	power10[0] = 1;
	for (int i = 1; i < 8; i++) power10[i] = power10[i - 1] * 10;
	
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> n;
		for (int j = 0; ; j++) {
			if (n < 10) {
				cout << j << endl;
				break;
			}
			n = next(n);
		}
	}
	return 0;
}