#include <bits/stdc++.h>
using namespace std;
int const MOD = 1000000007;
int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    string s;
    cin >> s;
    int cnt = 0;
    while (1) {
      if (s.length() == 1)
        break;
      else {
        int ma = 0;
        for (int i = 1; i <= s.length(); i++) {
          string s1 = s.substr(0, i);
          string s2 = s.substr(i, s.length() - i);
          ma = max(ma, atoi(s1.c_str()) * atoi(s2.c_str()));
        }
        s = to_string(ma);
        cnt++;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
