#include <bits/stdc++.h>
using namespace std;
unsigned long long int power(unsigned long long int x,
                             unsigned long long int n) {
  if (n == 0) return 1;
  if (n == 1) return x;
  if (x == 0) return 0;
  if (n % 2 == 1) {
    unsigned long long int y;
    y = power(x, (n - 1) / 2);
    return x * y * y;
  } else {
    unsigned long long int y;
    y = power(x, n / 2);
    return y * y;
  }
  return -1;
}
int main(void) {
  int Q;
  cin >> Q;
  vector<int> N;
  vector<int> ans;
  for (int i = 0; i < Q; i++) {
    unsigned long long int n_i;
    unsigned long long int p;
    int ans = 0;
    cin >> n_i;
    p = n_i;
    while (p > 9) {
      stringstream ss;
      ss << p;
      int max = 0;
      for (int i = 1; i < ss.str().length(); i++) {
        unsigned long long int tmp;
        unsigned long long int div1, div2;
        tmp = power(10, i);
        div1 = p / tmp;
        div2 = p % tmp;
        if (div1 * div2 >= max) {
          p = div1 * div2;
          max = p;
        }
      }
      ans++;
      if (p > n_i) {
        ans = -1;
        p = -1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
