#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
template <class S, class T>
ostream& operator<<(ostream& os, pair<S, T> p) {
  os << '(' << (p.first) << ", " << (p.second) << ')';
  return os;
}
template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i = 1, len = v.size(); i < len; ++i) os << ' ' << v[i];
  return os;
}
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
bool contains(vector<int>& vector<string>, int x) {
  for (int v : vector<string>) {
    if (v == x) return true;
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  while (n--) {
    int x;
    cin >> x;
    int cx = 0;
    vector<int> history;
    while (x > 9) {
      int nx = 0;
      for (int d = 10;; d *= 10) {
        int z = x / d;
        int y = x % d;
        if (z == 0) break;
        nx = max(nx, z * y);
      }
      x = nx;
      cerr << ">>> "
           << "x"
           << " = " << x << endl;
      ;
      ++cx;
    }
    cout << cx << endl;
  }
  return 0;
}
