#include <bits/stdc++.h>
using namespace std;
void reader(int &a) { scanf("%d", &a); }
void reader(double &a) { scanf("%lf", &a); }
void reader(char a[]) { scanf("%s", a); }
void reader(char &a) { scanf(" %c", &a); }
void reader(long long &a) { scanf("%lld", &a); }
void reader(unsigned long long &a) { scanf("%llu", &a); }
template <class T, class U>
void reader(T &t, U &u) {
  reader(t);
  reader(u);
}
template <class T, class U, class V>
void reader(T &t, U &u, V &v) {
  reader(t);
  reader(u);
  reader(v);
}
void writer(const int a, char c) {
  printf("%d", a);
  putchar(c);
}
void writer(const long long a, char c) {
  printf("%lld", a);
  putchar(c);
}
void writer(const unsigned long long a, char c) {
  printf("%llu", a);
  putchar(c);
}
void writer(const double a, char c) {
  printf("%.20lf", a);
  putchar(c);
}
void writer(const char a[]) { printf("%s", a); };
void writer(const char a[], char c) {
  printf("%s", a);
  putchar(c);
};
void writer(const char a, char c) {
  putchar(a);
  putchar(c);
};
template <class T>
void writerLn(T t) {
  writer(t, '\n');
}
template <class T, class U>
void writerLn(T t, U u) {
  writer(t, ' ');
  writer(u, '\n');
}
template <class T, class U, class V>
void writerLn(T t, U u, V v) {
  writer(t, ' ');
  writer(u, ' ');
  writer(v, '\n');
}
template <class T>
void writerArr(T x[], int n) {
  int i;
  if (!n) {
    putchar('\n');
    return;
  }
  for (i = 0; i < n - 1; ++i) writer(x[i], ' ');
  writer(x[n - 1], '\n');
}
template <class T>
void writerVec(vector<T> x) {
  int n = x.size();
  int i;
  if (!n) {
    putchar('\n');
    return;
  }
  for (i = 0; i < n - 1; ++i) writer(x[i], ' ');
  writer(x[n - 1], '\n');
}
vector<string> split(const string &str, char sep) {
  vector<string> v;
  stringstream ss(str);
  string buffer;
  while (getline(ss, buffer, sep)) {
    v.push_back(buffer);
  }
  return v;
}
bool test = 1;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
unsigned long long mod = (int)1e9 + 7;
signed main(void) {
  int i, j, k;
  int q;
  cin >> q;
  for (i = 0; i < q; ++i) {
    string s;
    cin >> s;
    int n = stoi(s);
    int cnt = 0;
    while (n > 9) {
      cnt++;
      int next_n = INT_MIN;
      for (j = 1; j < s.size(); ++j) {
        int a1 = stoi(s.substr(0, j));
        int a2 = stoi(s.substr(j));
        if (a1 * a2 > next_n) {
          next_n = a1 * a2;
        }
      }
      n = next_n;
      s = to_string(n);
    }
    cout << cnt << endl;
  }
  return 0;
}
