#include <bits/stdc++.h>
using namespace std;
int main() {
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int N;
    cin >> N;
    int count = 0;
    set<int> intSet;
    while (N > 9 && intSet.find(N) == intSet.end()) {
      intSet.insert(N);
      count++;
      string s;
      stringstream strStream;
      strStream << N;
      s = strStream.str();
      int maxV = 0;
      for (int i = 1; i < s.size(); i++) {
        string ss = s.substr(0, i);
        string sss = s.substr(i, s.size());
        cout << ss.data() << " : " << sss.data() << endl;
        int ii = atoi(ss.c_str());
        int iii = atoi(sss.c_str());
        maxV = max(maxV, ii * iii);
      }
      N = maxV;
    }
    if (intSet.find(N) != intSet.end()) {
      cout << -1 << endl;
    } else {
      cout << count << endl;
    }
  }
  return 0;
}
