#include <bits/stdc++.h>
using namespace std;
const int INF = 2 << 28;
const double EPS = 1e-10;
int main() {
  int Q;
  cin >> Q;
  while (Q--) {
    int cnt = 0;
    string R;
    cin >> R;
    string prev = R;
    while (true) {
      if (R.size() == 1 || !(~cnt)) break;
      int maxi = 0;
      for (int i = 1; i < R.size(); i++) {
        int f = atoi(R.substr(0, i).c_str()),
            s = atoi(R.substr(i, R.size() - i).c_str());
        maxi = max(maxi, f * s);
      }
      R = to_string(maxi);
      if (R == prev)
        cnt = -1;
      else
        cnt++;
    }
    cout << cnt << endl;
  }
}
