#include <bits/stdc++.h>
using namespace std;
long long m[100000];
int main() {
  int n;
  cin >> n;
  for (int z = 0; z < n; z++) {
    long long a;
    cin >> a;
    int sum = 0;
    while (to_string(a).length() != 1) {
      string h = to_string(a), c, d;
      long long b = 0;
      for (int i = 0; i < h.length() - 1; i++) {
        c = h.substr(0, i + 1);
        d = h.substr(i + 1, h.length() - i - 1);
        b = max((stoll(c) * stoll(d)), b);
      }
      a = b;
      int s = 0, e = sum - 1, t;
      while (e - s > 1) {
        t = (e + s) / 2;
        if (m[t] >= a) s = t;
        if (m[t] < a) e = t;
      }
      if ((m[s] == a || m[e] == a) && s >= 0 && e >= 0) {
        sum = -1;
        break;
      }
      m[sum] = a;
      sort(m, m + sum);
      sum++;
    }
    cout << sum << endl;
  }
}
