#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double eps = 1e-10;
const double pi = acos(-1.0);
const long long INF = 1LL << 62;
const int inf = 1 << 29;
int nexts[1000010];
int main(void) {
  for (int i = 10; i <= 1000000; ++i) {
    nexts[i] = 0;
    string in = to_string(i);
    int n = in.size();
    for (int j = (0); j < (n - 1); ++j) {
      int a = stoi(in.substr(0, j + 1));
      int b = stoi(in.substr(j + 1, n - j - 1));
      nexts[i] = max(nexts[i], a * b);
    }
  }
  int q;
  cin >> q;
  for (int loop = (0); loop < (q); ++loop) {
    int cur;
    cin >> cur;
    int ans = 0;
    while (cur >= 10) {
      ans++;
      cur = nexts[cur];
    }
    cout << ans << endl;
  }
  return 0;
}
