#include <bits/stdc++.h>
using namespace std;
const long long MAX_10p5 = 100010;
const long long MAX_10p9 = 1000000010;
const long long MAX_10p18 = 1000000000000000010;
const long long MOD = 1000000007;
const long long m4x[4] = {1, 0, -1, 0};
const long long m4y[4] = {0, 1, 0, -1};
const long long m8x[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long m8y[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long m9x[9] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long m9y[9] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
struct edge {
  long long from, to, cost;
  bool operator<(const edge& right) const { return cost < right.cost; }
};
struct point {
  long long x, y;
  bool operator<(const point& right) const {
    return x == right.x ? y < right.y : x < right.x;
  }
};
long long pow10(long long x) {
  long long ret = 1;
  if (x == 0)
    return ret;
  else {
    for (long long i = (long long)(0); i < (long long)(x); i++) ret *= 10;
    return ret;
  }
}
int main() {
  long long Q;
  cin >> Q;
  for (long long i = (long long)(0); i < (long long)(Q); i++) {
    long long N, ans = 0;
    cin >> N;
    while (N / 10 != 0) {
      long long tc = 0;
      long long tv = N / 10;
      long long tr;
      while (1) {
        if (tv % 10 == 0) {
          tv /= 10;
          tc++;
        } else {
          tr = N % pow10(tc + 1);
          break;
        }
      }
      N = tv * tr;
      ans++;
    }
    cout << ans << endl;
  }
  return 0;
}
