#include <bits/stdc++.h>
using namespace std;
int main() {
  int Q;
  cin >> Q;
  while (Q--) {
    string s;
    cin >> s;
    int ans = 0;
    int j = 0;
    while (s.length() > 1) {
      int l = 0;
      int r = stoi(s);
      int cnt = l * r;
      for (int i = (0); i < ((int)s.length() - 1); ++i) {
        l *= 10;
        l += s[i] - '0';
        r %= (int)pow(10, s.length() - i - 1);
        cnt = max(cnt, l * r);
      }
      s = to_string(cnt);
      j++;
      ans++;
      if (j == 100000) {
        cout << -1 << '\n';
        break;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
