#include <bits/stdc++.h>
int main(void) {
  int q, r, i, j, k, x, numa, numb, ans, multi[6], max;
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    for (j = 0; j < 6; j++) {
      multi[j] = 0;
    }
    scanf("%d", &r);
    k = 1;
    ans = 0;
    for (; r >= 10;) {
      for (j = 0; j < 6; j++) {
        k = k * 10;
        numa = r / 10;
        numb = r % 10;
        multi[j] = numa * numb;
      }
      max = multi[0];
      for (j = 1; j < 6; j++) {
        if (max < multi[j]) {
          max = multi[j];
        }
      }
      r = max;
      ans++;
      if (ans == 1000) {
        break;
      }
    }
    if (ans == 1000) {
      printf("-1\n");
    } else {
      printf("%d\n", ans);
    }
  }
  return 0;
}
