#include <bits/stdc++.h>
using namespace std;
int pow(int n, int k) {
  int res = 1;
  for (int i = 0; i < k; i++) {
    res *= n;
  }
  return n;
}
bool solve() {
  int num;
  cin >> num;
  int ans = 0;
  while (num / 10 != 0) {
    int tmp = num;
    int k = 0;
    while (tmp != 0) {
      tmp /= 10;
      k++;
    }
    int res = -1;
    for (int i = 0; i < k - 1; i++) {
      int n = num;
      int a = n % pow(10, k + 1);
      int b = n / pow(10, k + 1);
      res = max(res, a * b);
    }
    num = res;
    ans++;
  }
  cout << ans << endl;
  return true;
}
int main() {
  cout.setf(ios::fixed);
  cout.precision(10);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) solve();
  return 0;
}
