#include <bits/stdc++.h>
using namespace std;
int main() {
  int Q;
  int N;
  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) {
    int count = 0;
    scanf("%d", &N);
    while (N >= 10) {
      int temp = N;
      int digit = 0;
      while (temp > 0) {
        digit++;
        temp /= 10;
      }
      count++;
      temp = 10;
      int max = 0;
      for (int i = 0; i < digit - 1; i++) {
        max = max > (N / temp) * (N % temp) ? max : (N / temp) * (N % temp);
        temp *= 10;
      }
      N = max;
    }
    printf("%d\n", count);
  }
  return 0;
}
