#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <sstream>
using namespace std;

int main(int argc, char *argv[])
{
    int q, cnt, tmp;
    string n;
    vector<int>::iterator itr;
    cin >> q;
    while (cin >> n, q--) {
        vector<int> cache;
        for (cnt = 0;; ++cnt) {
            if (n.length() == 1)
                break;
            int kmax = 0;
            for (int i = 1; i < n.length(); ++i) {
                tmp = atoi(n.substr(0, i).c_str()) * atoi(n.substr(i).c_str());
                kmax = max(tmp, kmax);
            }
            itr = find(cache.begin(), cache.end(), kmax);
            if (itr != cache.end()) {
                cnt = -1;
                break;
            }
            else
                cache.push_back(kmax);
            stringstream ss;
            ss << kmax;
            n = ss.str();
        }
        cout << cnt << endl;
    }
    return 0;
}
[taguchi@Ken