#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    int size = s.size();
    int res, ans = 0;
    while (size > 1) {
      res = 0;
      for (int i = 0; i < size - 1; i++) {
        string a = s.substr(0, i + 1);
        string b = s.substr(i + 1);
        res = max(atoi(a.c_str()) * atoi(b.c_str()), ans);
      }
      stringstream ss;
      ss << res;
      s = ss.str();
      size = s.size();
      ans++;
      if (ans > 10) break;
    }
    if (ans > 10)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
