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 <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
 
using namespace std;
  
const double eps=1e-10;
 
const int dy[]={-1,-1,0,1,1, 1, 0,-1};
const int dx[]={ 0, 1,1,1,0,-1,-1,-1};

long solve(string s)
{
	long res=0;

	while(s.size()!=1){
		res++;

		long next=-1,now=atol(s.c_str());

		for(int i=1;i<s.size();i++){
			string s1=s.substr(0,i),s2=s.substr(i);
			if(next==-1 || next<atol(s1.c_str())*atol(s2.c_str())) next=atol(s1.c_str())*atol(s2.c_str());
		}
		if(now==next) return -1;
	
		stringstream ss;
		ss<<next;
		s=ss.str();
	}

	return res;
}

int main()
{
	int q;
	cin>>q;

	for(int i=0;i<q;i++){
		string s;
		cin>>s;
		cout<<solve(s)<<endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int q;
int n;
int query(int a, int cnt){
    int next = 0;
    if(a < 10){
        return cnt;
    }
    for(int i = 10; ; i *= 10){
        if(a < i)
            break;
        next = max(next, (a / i) * (a % i));
    }
    if(next >= a){
        return -1;
    }
    query(next, cnt + 1);
}
int main(){
    cin >> q;
    for(int i = 0; i < q; i++){
        cin >> n;
        cout << query(n, 0) << endl;
    }
    return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

using Tup = tuple<int64, int64, int64>;

vector<int32> dig(int64 x){
	vector<int32> res;
	while(x){
		res.push_back(x%10);
		x /= 10;
	}
	return res;
}

int64 next(int64 x){
	int64 res = 0;
	vector<int32> v = dig(x);
	reverse(all(v));
	FOR(i, 1, v.size()){
		int64 x1 = 0, x2 = 0;
		FOR(j, 0, i){
			x1 = x1*10+v[j];
		}
		FOR(j, i, v.size()){
			x2 = x2*10+v[j];
		}
		res = max(res, x1*x2);
	}
	return res;
}

int main(void){
	int32 Q;
	cin >> Q;
	while(Q--){
		int64 N;
		cin >> N;
		int32 cnt = 0;
		while(dig(N).size() > 1){
			cnt++;
			N = next(N);
		}
		cout << cnt << endl;
	}
}

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

string rev( string s );
int calcMultiple( string a, string b );

int main()
{
    int n;
    string m;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> m;

        bool a[1000001] = {};
        int cnt = 0;
        while( m.size() > 1 )
        {
            int max = 0;
            for( int j = 1; j < m.size(); j++ )
            {
                int mul = calcMultiple( m.substr( 0, j ), m.substr( j, m.size() ) );
                if( mul > max )
                    max = mul;
            }

            if( a[max] )
            {
                cnt = -1;
                break;
            }
            a[max] = true;

            string res = "";
            while( max != 0 )
            {
                res += ( max % 10 + '0' );
                max /= 10;
            }

            m = rev( res );
            cnt++;

        }
        cout << cnt << endl;
    }

    return 0;
}

string rev( string s )
{
    string res = "";
    for( int i = s.size() - 1; i >= 0; i-- )
        res += s[i];
    return res;
}

int calcMultiple( string a, string b )
{
    int x = 0, y = 0, d = 1;
    for( int i = a.size() - 1; i >= 0; i-- )
    {
        x += ( a[i] - '0' ) * d;
        d *= 10;
    }

    d = 1;
    for( int i = b.size() - 1; i >= 0; i-- )
    {
        y += ( b[i] - '0' ) * d;
        d *= 10;
    }
    return x * y;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>
#include <complex>

#define INF 100000000
#define EPS 1e-9

using namespace std;

typedef long long ll;

vector<int> ans_list;

bool dp[1000000];

int main(){

	int Q;
	cin >> Q;

	memset(dp, 0, sizeof(dp));

	while (Q){
		Q--;
		int N;
		cin >> N;
		int ans = 0;
		memset(dp, 0, sizeof(dp));

		while (N/10 > 0){
			if (dp[N]){
				ans = -1;
				break;
			}
			int tmp = 0;
			for (int i = 1; N/pow(10,i) > 0; i++){
				tmp = max(tmp, (N / (int)pow(10, i)) * (N % (int)pow(10, i)) );
			}
			dp[N] = false;
			N = tmp;
			ans++;
		}

		ans_list.push_back(ans);

	}
	
	for (int i = 0; i < ans_list.size(); i++){
		cout << ans_list[i] << endl;
	}

	return 0;

}