#include <bits/stdc++.h>
using namespace std;
vector<int> ans_list;
bool dp[1000000];
int main() {
  int Q;
  cin >> Q;
  memset(dp, 0, sizeof(dp));
  while (Q) {
    Q--;
    int N;
    cin >> N;
    int ans = 0;
    memset(dp, 0, sizeof(dp));
    while (N / 10 > 0) {
      if (dp[N]) {
        ans = -1;
        break;
      }
      int tmp = 0;
      for (int i = 1; N / pow(10, i) > 0; i++) {
        tmp = max(tmp, (N / (int)pow(10, i)) * (N % (int)pow(10, i)));
      }
      dp[N] = false;
      N = tmp;
      ans++;
    }
    ans_list.push_back(ans);
  }
  for (int i = 0; i < ans_list.size(); i++) {
    cout << ans_list[i] << endl;
  }
  return 0;
}
