#include <bits/stdc++.h>
using namespace std;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    string suji;
    cin >> suji;
    int len = suji.length();
    int cnt = 0;
    while (std::stoi(suji) >= 10)
      for (int j = 1; j < len; j++) {
        int num1;
        int num2;
        int tot;
        num1 = std::stoi(suji.substr(0, j));
        num2 = std::stoi(suji.substr(j, len - 1));
        cnt++;
        tot = num1 + num2;
        suji = std::to_string(tot);
      }
    cout << cnt << endl;
  }
  return 0;
}
