#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n, res = 0;
    cin >> n;
    while (n / 10) {
      int pre = n;
      res++;
      int MAX = 0;
      int j = 1, k = 0;
      while (n) {
        k += j * (n % 10);
        n /= 10;
        MAX = max(MAX, k * n);
      }
      n = MAX;
      if (pre == n) {
        res = -1;
        break;
      }
    }
    cout << res << endl;
  }
  return 0;
}
