#include <bits/stdc++.h>
using namespace std;
int inf = 1000000000;
int main(void) {
  int q, n;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> n;
    int cnt = 0;
    while (n >= 10) {
      int tmp = -1;
      string ns = to_string(n);
      for (int i = 0; i < ns.size() - 1; i++) {
        cerr << ns.substr(0, i + 1) << " " << ns.substr(i + 1) << endl;
        tmp = max(tmp, stoi(ns.substr(0, i + 1)) * stoi(ns.substr(i + 1)));
      }
      n = tmp;
      cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}
