#include <bits/stdc++.h>
using namespace std;
long long calc(long long a) {
  string s = to_string(a);
  long long res = 0;
  for (long long i = 1; i < s.size(); i++) {
    long long t = stoi(s.substr(0, i)) * stoi(s.substr(i));
    res = max(res, t);
  }
  return res;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  for (long long i = 0; i < (n); i++) {
    long long a;
    cin >> a;
    long long cnt = 0;
    while (10 <= a) {
      a = calc(a);
      cnt++;
    }
    cout << cnt << endl;
  }
}
