#include <bits/stdc++.h>
using namespace std;
const int SIZE = 1000001;
vector<int> memo(SIZE, -2);
vector<bool> visited(SIZE, false);
int dfs(int num) {
  if (memo[num] != -2) {
    return memo[num];
  }
  if (memo[num] == -2 && visited[num]) {
    return memo[num] = -1;
  }
  if (num < 10) {
    return memo[num] = 0;
  }
  int m = 10, next = 0, res = -1;
  visited[num] = true;
  while (num >= m) {
    next = max(next, (num / m) * (num % 10));
    m *= 10;
  }
  res = dfs(next);
  res += res != -1;
  return memo[num] = res;
}
int main(void) {
  int q;
  while (cin >> q) {
    for (int i = 0; i < q; ++i) {
      int n;
      cin >> n;
      cout << dfs(n) << endl;
    }
  }
  return 0;
}
