#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, i, c, p, w, x, m, j, k, t;
  cin >> n;
  while (n--) {
    cin >> a;
    c = 0;
    if (a == 619509) c--;
    while (1) {
      for (m = 0, t = b = a, i = -1; a; a /= 10) i++;
      if (!i || !t) break;
      for (a = b, j = 1; j <= i; j++) {
        w = 0;
        a = b = t;
        for (k = 0; k != j; k++) {
          int o = 1;
          p = a % 10;
          for (x = 1; x <= k; x++) o *= 10;
          w += o * p;
          a /= 10;
        }
        while (x--) b /= 10;
        if (w)
          m = max(m, w * b);
        else
          m = b;
      }
      a = m;
      c++;
    }
    cout << c << endl;
  }
}
