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 <algorithm>

using namespace std;

int Q, N, C;

int digit(int n, int k = 0)
{
	if (n == 0) { return k; }

	return digit(n / 10, k + 1);
}

int power(int a, int b)
{
	if (b == 0) { return 1; }

	return power(a, b - 1) * a;
}

int main()
{
	cin >> Q;

	for (int i = 0; i < Q; i++)
	{
		cin >> N;

		C = 0;

		while (digit(N) > 1)
		{
			int Next_N = 0;

			for (int j = 1; j < digit(N); j++)
			{
				int l = N / power(10, j);
				int r = N % power(10, j);

				Next_N = max(l * r, Next_N);
			}

			N = Next_N;

			C++;
		}

		cout << C << endl;
	}

	return 0;
}

C++: #pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
	int t;
	cin>>t;
	while(t--){
		ll n;
		cin>>n;
		ll ans=0;
		while(n>=10){
			ll res=0,a=0;
			ll tmp=n;
			int cnt=0;
			while(tmp){
				tmp/=10;
				cnt++;
			}
			tmp=n;
			for(int i=0;i<cnt-1;i++){
				a*=10;
				a+=tmp/(ll)pow(10,cnt-i-1);
				tmp%=(ll)pow(10,cnt-i-1);
				chmax(res,a*tmp);
			}
			n=res;
			ans++;
		}
		cout<<ans<<"\n";
	}
}

C++: #include<iostream>
#include<fstream>
#include<string>

using namespace std;

int search(int num){
    if(num < 10)return 0;

    auto log = 10;
    auto v = 0;
    while(log < num)
    {
        auto tmp = (num % 10) * (num / 10);
        v = max(tmp, v);
        log *= 10;
    }

    return 1 + search(v);

}


int main(){
   

    auto n = 0;
    cin >> n;

    for(auto i = 0; i < n; i++){
        auto num = 0;
        cin >> num;
        cout << search(num) << endl;
    }

    return 0;
}