#include <bits/stdc++.h>
using namespace std;
string str;
int cnt;
int inf;
string solve(string x) {
  int ret = INT_MIN;
  string a;
  string ans;
  if (x.size() == 1) return x;
  if (inf <= atoi(x.c_str()) && cnt != 0) {
    cnt = -1;
    return 0;
  }
  for (int i = 0; i < (int)str.size(); i++) {
    string b;
    a += x[i];
    for (int j = i + 1; j < (int)str.size(); j++) {
      b += x[j];
    }
    int c = atoi(a.c_str()) * atoi(b.c_str());
    if (ret < c) {
      ret = max(ret, c);
    }
  }
  stringstream s;
  s << ret;
  s >> ans;
  cnt++;
  return solve(ans);
}
int main() {
  int q;
  cin >> q;
  string ans;
  for (int i = 0; i < q; i++) {
    cnt = 0;
    cin >> str;
    inf = atoi(str.c_str());
    solve(str);
    cout << cnt << endl;
  }
}
