#include <bits/stdc++.h>
int main() {
  int i, j, n, m, count, max;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &m);
    count = 0;
    while (m / 10 != 0 && count < 100) {
      max = (m / 10) * (m % 10);
      for (j = 100; m / j != 0; j *= 10) {
        if (max < (m / j) * (m % j)) max = (m / j) * (m % j);
      }
      m = max;
      count++;
    }
    if (count != 20)
      printf("%d\n", count);
    else
      printf("-1\n");
  }
  return 0;
}
