#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int Q, R;
  int ko, max;
  int cnt;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> R;
    cnt = 0;
    while (1) {
      if (R / 10 == 0) break;
      max = (R / 10) * (R % 10);
      for (int j = 100; R / j != 0; j *= 10) {
        ko = (R / j) * (R % j);
        if (ko > max) ko = max;
      }
      cnt++;
      R = max;
    }
    cout << cnt << endl;
  }
  return 0;
}
