#include "bits/stdc++.h"
#include <string>
using namespace std;

typedef long long ll;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int dy[] = { 0, 0, 1, -1 };
int dx[] = { 1, -1, 0, 0 };

ll A, B, C, D, E, F, G, H, I, J, K, L, M,
N, O, P, Q, R, S, T, U, V, W, X, Y, Z;

struct Card {
	ll number;
	char color;
} Card_t;

namespace aojKakezan { void aojKakezan(); }
int main()
{
	aojKakezan::aojKakezan();
	return 0;
}

//* ?????????n??????????????\??????????????????????????????????????????
template <typename T>
vector<T> INP(ll n)
{
	vector<T> x;
	REP(i, n) {
		T tmp; cin >> tmp;
		x.push_back(tmp);
	}
	return x;
}
//* n??????1????????????????????\?????????????????????????????¨??????????????????
vector<char> SPRIT_STRING(ll n)
{
	string str; cin >> str;
	vector<char> cs(n);
	REP(i, n) cs[i] = str[i];
	return cs;
}

int stoi(const std::string& str, std::size_t* idx = NULL, int base = 10) {
	const char* p = str.c_str();
	char* end;
	errno = 0;
	long x = std::strtol(p, &end, base);
	if (p == end) {
		throw std::invalid_argument("stoi");
	}
	if (errno == ERANGE || x < INT_MIN || x > INT_MAX) {
		throw std::out_of_range("stoi");
	}
	if (idx != NULL) {
		*idx = static_cast<std::size_t>(end - p);
	}
	return static_cast<int>(x);
}
int stoi(const std::wstring& str, std::size_t* idx = NULL, int base = 10) {
	const wchar_t* p = str.c_str();
	wchar_t* end;
	errno = 0;
	long x = std::wcstol(p, &end, base);
	if (p == end) {
		throw std::invalid_argument("stoi");
	}
	if (errno == ERANGE || x < INT_MIN || x > INT_MAX) {
		throw std::out_of_range("stoi");
	}
	if (idx != NULL) {
		*idx = static_cast<std::size_t>(end - p);
	}
	return static_cast<int>(x);
}
std::string to_string(long long int val)
{
	char buffer[std::numeric_limits<long long int>::digits10 + 2]; // '-' + NULL
	std::sprintf(buffer, "%lld", val);
	return buffer;
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2424
namespace aojKakezan {
	void aojKakezan() {
		cin >> Q;
		REP(i, Q) {
			string current; cin >> current;
			ll cnt = 0;
			while (current.size() > 1) {
				ll maxNext = 0;
				REP(p, current.size() - 1) {
					ll a = stoi(current.substr(0, p+1));
					ll b = stoi(current.substr(1 + p, current.size() - (p+1)));
					maxNext = max(maxNext, a * b);
				}
				current = to_string(maxNext);
				cnt++;
			}
			cout << cnt << endl;
		}
	}
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2102&lang=jp
namespace aojRummy {
	bool comp(const Card& a, const Card& b)
	{
		return a.number < b.number;
	}

	bool rummyCheck(vector<Card> cards)
	{
		if (cards.size() == 0) return true;
		if (cards.size() % 3 != 0) return false;
		sort(cards.begin(), cards.end(), comp);
		bool okay = false;
		do {
			int repNum = cards.size() / 3;
			bool localOkay = true;
			REP(i, repNum) {
				ll zero = cards[i * 3].number;
				ll one = cards[i * 3 + 1].number;
				ll two = cards[i * 3 + 2].number;
				if (not((zero == one and one == two) or ((zero + 1) == one and (one + 1) == two)))
					localOkay = false;
			}
			if (localOkay)
				okay = true;
		} while (next_permutation(cards.begin(), cards.end(), comp));
		return okay;
	}

	void aojRummy()
	{
		cin >> T;

		N = 9;
		REP(t, T) {
			vector<Card> cards(N);
			REP(i, 9) cin >> cards[i].number;
			REP(i, 9) cin >> cards[i].color;

			vector<Card> red, green, blue;
			REP(i, N) {
				Card c = cards[i];
				if (c.color == 'R') red.push_back(c);
				else if (c.color == 'G') green.push_back(c);
				else blue.push_back(c);
			}

			if (rummyCheck(red) and rummyCheck(blue) and rummyCheck(green))
				cout << 1 << endl;
			else
				cout << 0 << endl;
		}
	}
}

//* http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1129
void aojHanafudaShuffle()
{
	N = R = 1;
	while (true) {
		cin >> N >> R;
		if (N == 0 and R == 0) break;

		vector<ll> cards(N);
		REP(i, N) cards[i] = i + 1;

		REP(i, R) {
			cin >> P >> C;
			rotate(cards.begin() + (N - (C + P - 1)), cards.begin() + (N - (P - 1)), cards.end());
			//vector<ll> tmp(C);
			//copy(cards.begin() + (N - (C + P - 1)), cards.begin() + N - (P - 1), tmp.begin());
			//copy(cards.begin() + (N - (P - 1)), cards.end(), cards.begin() + (N - (C + P - 1)));
			//copy(tmp.begin(), tmp.end(), cards.begin() + (N - C));
		}

		cout << cards[cards.size() - 1] << endl;
	}
}


Measured memory_bytes: 3348