#include <bits/stdc++.h>
using namespace std;
int Q, N, logn, r, l, turn;
int main() {
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> N;
    logn = int(log10(N)) + 1;
    if (logn == 1)
      cout << 0 << endl;
    else {
      turn = 0;
      while (logn != 1) {
        int max = 0;
        for (int j = 0; j < logn - 1; j++) {
          r = N % int(pow(10, j + 1) + 0.1);
          l = N / int(pow(10, j + 1) + 0.1);
          if (max < r * l) {
            max = r * l;
          }
        }
        N = max;
        logn = int(log10(N)) + 1;
        turn++;
      }
      return turn;
    }
  }
  return 0;
}
