#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, bool> h;
  int q, n, cnt;
  cin >> q;
  while (q--) {
    cin >> n;
    cnt = 0;
    h.clear();
    h[n] = true;
    while (true) {
      int m = -1, k = 10;
      cnt++;
      for (int i = 0; i < 5; i++) {
        m = max(m, (n / k) * (n % k));
        k *= 10;
      }
      if (h[m]) {
        cout << -1 << endl;
        break;
      }
      if (m < 10) {
        cout << cnt << endl;
        break;
      }
      n = m;
      h[m] = true;
    }
  }
}
