#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
int main(void) {
  int p;
  cin >> p;
  for (int lp = 0; lp < p; lp++) {
    string n;
    cin >> n;
    int ans = 0;
    while (n.length() != 1) {
      int mx = -1;
      for (int i = 1; i < n.length(); i++) {
        string a = n.substr(0, i);
        string b = n.substr(i);
        mx = max(mx, stoi(a) * stoi(b));
      }
      n = to_string(mx);
      ans++;
    }
    cout << ans << endl;
  }
}
