#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
string IntToString(long long int number) {
  stringstream ss;
  ss << number;
  return ss.str();
}
string tmp;
string tmp2;
int main() {
  int q, cnt;
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    cin >> tmp;
    tmp2 = tmp;
    cnt = 0;
    while (tmp.size() != 1) {
      int mmax = -1;
      for (int i = (int)(1); i < (int)(tmp.size()); i++) {
        string st1, st2;
        for (int j = (int)(0); j < (int)(i); j++) st1 += tmp[j];
        for (int j = (int)(i); j < (int)(tmp.size()); j++) st2 += tmp[j];
        mmax = max(mmax, stoi(st1) * stoi(st2));
      }
      cnt++;
      tmp = IntToString(mmax);
    }
    cout << cnt << endl;
  }
  return 0;
}
