#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    int used[1000001];
    fill(used, used + 1000001, 0);
    int ans = 0;
    while (!used[n] && 9 < n) {
      int next = 0, r = 1;
      used[n] = true;
      while (0 < n) {
        r *= n % 10;
        n /= 10;
        next = max(next, r * n);
      }
      n = next;
      ans++;
    }
    if (n <= 9)
      cout << ans << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
