#include <bits/stdc++.h>
using namespace std;
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();
}
int main(void) {
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    int maxnum = n;
    int cnt = 0;
    while (cnt < 100000) {
      string str = toString(maxnum);
      if (toString(maxnum).length() == 1) {
        cout << cnt << endl;
        break;
      }
      maxnum = 0;
      for (int i = 0; i < str.length(); i++) {
        string a = str.substr(0, i), b = str.substr(i);
        int tmp = toInt(a) * toInt(b);
        maxnum = max(maxnum, tmp);
      }
      cnt++;
    }
    if (cnt == 10000) cout << -1 << endl;
  }
  return 0;
}
