#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n, count = 0;
    cin >> n;
    map<int, bool> h;
    while (1) {
      if (floor(n / 10) == 0) break;
      string s = to_string(n);
      vector<int> p;
      for (int i = (1); i < (s.length()); ++i) {
        int tmp = stoi(s.substr(0, i)) * stoi(s.substr(i));
        if (tmp == 0) break;
        p.push_back(tmp);
      }
      int m = *max_element((p).begin(), (p).end());
      if (h[m]) {
        count = -1;
        break;
      }
      n = m;
      h[m] = true;
      ++count;
    }
    cout << count << endl;
  }
  return EXIT_SUCCESS;
}
