#include <bits/stdc++.h>
using namespace std;
int DivideMul(int N, int a) {
  int L = N % (int)pow(10, a);
  int U = (N - L) / pow(10, a);
  return L * U;
}
int Next(int N) {
  int n = 10000000;
  int s = int(log(N) / log(10));
  for (int i = 1; i < s; ++i) {
    n = min(n, DivideMul(N, i));
  }
  return n;
}
int main() {
  int T;
  cin >> T;
  for (int i = 0; i < T; ++i) {
    int N;
    cin >> N;
    int j = 0;
    for (j = 0; N > 9; j++) {
      N = Next(N);
    }
    cout << j << endl;
    ;
  }
}
