#include <bits/stdc++.h>
using namespace std;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> >
    IntReversePrioQueue;
const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1 << 29;
const int MOD = 1000000007;
int calc(int x) {
  if (x < 10) return 0;
  string s = to_string(x);
  int res = 1, tmp = -1;
  for (int i = 0; i <= (int)s.size() - 1 - 1; i++) {
    int a = stoi(s.substr(0, i + 1)), b = stoi(s.substr(i + 1));
    tmp = max(tmp, a * b);
  }
  res += calc(tmp);
  return res;
}
void solve(void) {
  int Q;
  cin >> Q;
  for (int i = 0; i <= Q - 1; i++) {
    int a;
    cin >> a;
    cout << calc(a) << endl;
  }
}
int main(void) {
  solve();
  return 0;
}
