#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string, int>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
T ston(string& str, T n) {
  istringstream sin(str);
  T num;
  sin >> num;
  return num;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll q;
  string s = "024";
  cin >> q;
  for (int i = 0; i < (int)(q); ++i) {
    bool f = true;
    ll n = 0;
    cin >> s;
    while (s.size() != 1) {
      set<ll> st;
      ll ans = -1;
      for (int k = (1); k < (int)(s.size()); ++k) {
        string l = s, r = s;
        l.resize(k);
        r = r.substr(k);
        ll n2 = ston(l, 1) * ston(r, 1);
        ans = max(ans, n2);
        if (!st.insert(n2).second) {
          cout << -1 << endl;
          f = false;
          k = 1e9;
          break;
        }
      }
      s = to_string(ans);
      ++n;
    }
    if (f) cout << n << endl;
  }
  return 0;
}
