#include <bits/stdc++.h>
using namespace std;
inline int nextInt() {
  int d;
  cin >> d;
  return d;
}
bool isUsed[(int)1e6 + 1];
int getNext(int n) {
  int ret = -1;
  for (int d = 10; d < n; d *= 10) {
    int n1 = n % d;
    int n2 = (n - n1) / d;
    ret = max(ret, n1 * n2);
  }
  return ret;
}
int solve(int n) {
  int step = 0;
  memset(isUsed, false, (int)1e6 + 1);
  while (true) {
    if (n < 10) {
      return step;
    }
    if (isUsed[n]) {
      return -1;
    }
    isUsed[n] = true;
    n = getNext(n);
    step++;
  }
  return 0;
}
int main() {
  int Q = nextInt();
  for (int i = 0; i < Q; i++) {
    int R = nextInt();
    int ans = solve(R);
    cout << ans << endl;
  }
  return 0;
}
