#include <bits/stdc++.h>
using namespace std;
int max(int a, int b) {
  if (a >= b)
    return a;
  else
    return b;
}
int main() {
  int q;
  int ten[7] = {10, 100, 1000, 10000, 100000, 1000000};
  while (cin >> q) {
    int cnt = 0;
    for (int l = 0; l < q; l++) {
      int r;
      cin >> r;
      cnt = 0;
      while (1) {
        if (r < 10) {
          cout << cnt << endl;
          break;
        } else {
          int length = 0;
          for (int i = 0; i < 7; i++) {
            if (ten[i] >= q) {
              length = i;
              break;
            }
          }
          int next = 0;
          for (int i = 0; i <= length; i++) {
            int a, b;
            a = r % ten[i];
            b = r / ten[i];
            next = max(next, a * b);
          }
          r = next;
          cnt++;
        }
      }
    }
    break;
  }
  return 0;
}
