#include <bits/stdc++.h>
using namespace std;
int size(int n) {
  int s = 0;
  for (int j = 0;; j++) {
    if (n == 0) {
      s = 1;
      break;
    } else if ((pow(10, j)) <= n and n < (pow(10, j + 1))) {
      s++;
      break;
    } else
      s++;
  }
  return s;
}
int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int n;
    cin >> n;
    int res = 0;
    while (size(n) != 1) {
      vector<int> v;
      for (int j = 1; j < size(n); j++) {
        int a, b;
        a = n % int(pow(10, j));
        b = n / int(pow(10, j));
        v.push_back(a * b);
      }
      n = *max_element(v.begin(), v.end());
      res++;
    }
    cout << res << endl;
  }
}
