import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.container, std.math, std.typecons;
import std.ascii, std.getopt;

void main() {
    int Q, N;

    Q = readln.chomp.to!int;

    foreach (qi ; 0 .. Q) {
        N = readln.chomp.to!int;
        solve(N).writeln;
    }
}

int solve(int N) {
    int cnt;

    while (N > 9) {
        int[] made;
        string ns = N.to!string;

        foreach (i ; 1 .. ns.length) {
            int x = ns[0 .. i].to!int, y = ns[i .. $].to!int;
            made ~= x * y;
        }

        N = made.reduce!max;
        cnt++;
    }

    return cnt;
}