#include <bits/stdc++.h>
using namespace std;
int GetDigit(int num) { return to_string(num).length(); }
int Q;
int main() {
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    int n;
    cin >> n;
    int digit = GetDigit(n);
    int count = 0;
    while (1) {
      int max = 0;
      if (n >= 1 && n <= 9) {
        cout << count << endl;
        break;
      } else {
        for (int j = 1; j <= digit - 1; ++j) {
          int op1 = n / int(pow(10, j));
          int op2 = n % int(pow(10, j));
          if (op1 * op2 > max) {
            max = op1 * op2;
          }
        }
        ++count;
        if (max >= 1 && max <= 9) {
          cout << count << endl;
          break;
        } else if (count > 100) {
          cout << "-1" << endl;
          break;
        } else {
          n = max;
        }
      }
    }
  }
  return 0;
}
