#include <bits/stdc++.h>
using namespace std;
int stoi(string& s) {
  int ret = 0;
  for (unsigned int i = 0; i < s.length(); ++i) {
    ret += s[i] - '0';
    ret *= 10;
  }
  return ret /= 10;
}
int stoi(string& s, int a, int b) {
  string tmp = s.substr(a, b);
  return stoi(tmp);
}
int stoi(string& s, int n) {
  string tmp = s.substr(0, n);
  return stoi(tmp);
}
int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int cnt = 0;
    string s;
    int org;
    cin >> s;
    org = stoi(s);
    int mul1, mul2;
    bool b = true;
    while (s.size() != 1) {
      int mx = 0;
      for (unsigned int j = 1; j < s.size(); ++j) {
        mul1 = stoi(s, j);
        mul2 = stoi(s, j, s.size() - j);
        mx = max(mx, mul1 * mul2);
      }
      if (mx == org) {
        b = false;
        break;
      }
      s = to_string(mx);
      cnt++;
    }
    cout << (b ? cnt : -1) << endl;
  }
  return 0;
}
