#include <bits/stdc++.h>
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const long long infll = (long long)1e+17 + 10;
int q;
int main() {
  std::cin >> q;
  for (int i = 0; i < q; ++i) {
    int n;
    std::cin >> n;
    int cnt = 0;
    while (true) {
      int max = 0;
      std::string str = std::to_string(n);
      for (int i = 1; i < str.size() + 1; ++i) {
        max =
            std::max(max, std::atoi(str.substr(0, i).c_str()) *
                              std::atoi(str.substr(i, str.size() - i).c_str()));
      }
      if (max != 0) {
        n = max;
        cnt++;
      } else
        break;
    }
    std::cout << cnt << std::endl;
  }
  return 0;
}
