#include <bits/stdc++.h>
int main() {
  int n, count, cut;
  int num, front, back, max, now;
  std::vector<int> prev;
  while (scanf("%d", &n) > 0) {
    for (int i = 0; i < n; i++) {
      scanf("%d", &num);
      max = 0;
      count = 0;
      if (num < 10) {
        printf("%d\n", count);
        continue;
      }
      while (num > 10) {
        count++;
        back = 0;
        cut = 0;
        max = 0;
        while ((front = num / 10) > 0) {
          for (int i = 1; i <= cut; i++) back *= 10;
          back += (num % 10);
          now = back * front;
          if (max < now) max = now;
          num /= 10;
        }
        num = max;
        if (prev.size() != 0) {
          for (int i = 0; i < prev.size(); i++)
            if (num == prev.at(i)) {
              count = -1;
              goto out;
            }
        }
        prev.push_back(num);
      }
    out:
      printf("%d\n", count);
      prev.clear();
    }
  }
  return 0;
}
