Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	q := io.NextInt()
	for i := 0; i < q; i++ {
		io.Println(solve(io.NextInt()))
	}
}

func solve(n int) int {
	f := func(n int) int {
		max := 0
		for i := 10; ; i *= 10 {
			a := n / i
			b := n % i
			if a == 0 {
				break
			}
			max = intMax(a*b, max)
		}
		return max
	}

	cnt := 0
	for {
		if n < 10 {
			break
		}
		n = f(n)
		cnt++
	}

	return cnt
}

func intMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cctype>

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max)) 

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VII;
typedef pair<int,int> PII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	vector<string> S;
	int q;
	string r;
	cin >> q;

	rep(i,q){
		cin >> r;
		S.pb(r);

	}
	rep(i,q){
		int ans = 0;
		string s = S[i];
		while(s.size() != 1){
			int ab_max = 0;
			stringstream max_s;
			rep(j, s.size() - 1){
				stringstream ssa, ssb;
				string as, bs;
				int a, b;
				as = s.substr(0, j + 1);
				bs = s.substr(j + 1, s.size() - j - 1);
				ssa << as;
				ssb << bs;
				ssa >> a;
				ssb >> b;
				if(a * b > ab_max){
					ab_max = a * b;
				}
			}
			max_s << ab_max;
			s = max_s.str();
			ans++;
		}
		cout << ans << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<set>
#include<algorithm>
using namespace std;

int main(){
	int q;
	cin>>q;
	while(q--){
		int n;
		set<int> s;
		cin>>n;
		int ans=0;
		while(10<=n){
			if(s.find(n)!=s.end()){
				ans=-1;
				break;
			}
			s.insert(n);
			int next=0;
			int b=10;
			while(b<=n){
				int t=(n%b)*(n/b);
				next=max(next,t);
				b*=10;
			}
			n=next;
			ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<set>
using namespace std;int Q,N,a,p,M,t;main(){for(cin>>Q;Q-->0;cout<<a<<endl){set<int>u;for(cin>>N,a=0;N/10&&~a;N=M)for(u.count(N)&&(a=-2),u.insert(N),a++,p=M=1;p<N;p*=10,M=t>M?t:M)t=(N/p)*(N%p);}}

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
    int q, n;
    cin >> q;
    while(q--){
        cin >> n;
        int cnt = 0;
        while(n >= 10){
            int tmp = n, k = 0;
            while(tmp >= 10){
                tmp /= 10;
                k++;
            }
            tmp = n, n = 0;
            for(int i = 0; i < k; i++){
                int dig = 10;
                for(int j = 0; j < i; j++) dig *= 10;
                n = max(n, (tmp / dig) * (tmp % dig));
            }
            cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;

int main() {
	int q;
	cin >> q;
	while(q--) {
		int n, cnt=0;
		cin >> n;
		while(n>=10 && cnt<10000) {
			int b = floor(log(n) / log(10.0));
			int maxi = 0;
			for(int i=0; i<b; i++) {
				int p = pow(10,i+1);
				int x = n % p;
				int y = (n-x) / p;
				maxi = max(maxi, x*y);
			}
			n = maxi;
			cnt++;
		}
		cout << (cnt==10000 ? -1 : cnt) << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e9+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int q, n;
int co;
set<int> si;

int solve(int n){
	int res = -1;
	int k = 10;
	while (n / k >= 1){
		int a = n / k, b = n%k;
		res = max(res, a*b);
		k *= 10;
	}
	return res;
}

int main(){
	cin >> q;
	REP(i, q){
		si.clear();
		co = 0;
		cin >> n;
		while (n / 10 > 0){
			if (!si.insert(n).second){
				co = -1;
				break;
			}
			co++;
			n = solve(n);
		}
		cout << co << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;

int main() {
	
	ll q;
	cin >> q;
	while(q--){
		string n;
		cin >> n;
		ll ans = 0;
		while(n.size() > 1){
			if(ans > 10000) break;
			int maxi = 0;
			for(int pos = 1; pos < n.size(); pos++){
				int l = stoi(n.substr(0, pos));
				int r = stoi(n.substr(pos));
				maxi = max(maxi, l * r);
			}
			n = to_string(maxi);
			ans++;
		}
		
		if(ans > 10000) cout << -1 << endl;
		else cout << ans << endl;
		
	}
	
	return 0;
}