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 <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>

typedef long long ll;

using namespace std;


int pow(int n, int k){
	int res = 1;
	for(int i=0;i<k;i++){
		res *= n;
	}
	return n;
}

bool solve(){
	
	int num;
	cin>> num;
	
	int ans = 0;
	while(num/10 != 0){
		int tmp = num;
		int k=0;
		while(tmp!=0){
			tmp /= 10;
			k++;
		}
		int res = -1;
		for(int i=0;i<k-1;i++){
			int n = num;
			int a = n % pow(10,k+1);
			int b = n / pow(10,k+1);
			res = max(res, a*b);
		}
		num = res;
		ans++;
	}
	
	cout<< ans<< endl;
	
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	
	int n;
	cin>> n;
	for(int i=0;i<n;i++) solve();

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;

//string型からint型に変換する
int s_to_i(string s){
	int n = 0;
	for(int i=0 ; i < s.size() ; i++ ){
		n *= 10;
		n += s[i] - '0';
    }
    return n ;
}

//int型からstring型に変換する
string i_to_s(int n){
	string s;
	do{
		s.push_back( (n%10)+'0' );
		n /= 10;
	}while( n != 0 );
	
	reverse( s.begin() , s.end() );
	return s;
}

// s[0..i] と s[i+1..s.size()-1]に分割して掛け算して最大の数字を返す. (返すのは文字列)
string f(string s){
	int res = 0;
	for(int i=0 ; i <= s.size()-2 ; i++ ){
		// a := s[0] から i+1 文字の部分文字列
		string a = s.substr( 0 , i+1 );
		// b := s[i+1] から最後までの部分文字列 
		string b = s.substr( i+1 );
		res = max( res , s_to_i(a) * s_to_i(b) );
	}
	return i_to_s( res );
}

int main(){
	int Q;
	
	cin >> Q;
	for(int i=0 ; i < Q ; i++ ){
		string N;
		cin >> N;
		
		int ans = 0;
		// memo[n] := 手順の途中で n が登場しているかどうかを返す. 
		map<string,bool> memo;
		
		while( true ){
			// N いままでの手順で登場しているかのチェック
			if( memo.count(N) ){
				ans = -1;
				break;
			}else{
				memo[N] = true;
			}
			
			if( N.size() == 1 ){ // 1 桁のとき
				break;
			}else{ // それ以外
				ans++;
				N = f(N);
			}
		}
		cout << ans << endl;
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

int power10(int x);
int GetDigit(int x);

int main(void)
{
	int Q;
	cin >> Q;
	for(int i=0;i<Q;i++){
		int N, cnt=0;
		cin >> N;
		while(N >= 10){
			int Digit;
			int maxi = 0;
			Digit = GetDigit(N);
			for(int j=1;j<Digit;j++){
				int n, m;
				n = N / power10(Digit-j);
				m = N - n*power10(Digit-j);
				maxi = max(maxi, n*m);
			}
			N = maxi;
			cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

int power10(int x){
	if (x==0){
		return 1;
	}
	return power10(x-1)*10;
}

int GetDigit(int x){
	int ret=0;
	int n=x;
	do{
		ret++;
	}while((n/=10) != 0);
	return ret;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int Q;

int f(int n, int t){
    if(n < 10){
        return t;
    }

    int s = 10, mx = 0;
    while(true){
        int x = n / s, y = n % s;
        if(x == 0){
            break;
        }

        mx = max(mx, x * y);
        s *= 10;
    }

    return f(mx, t + 1);
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    std::cin >> Q;

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

        int res = f(N, 0);
        std::cout << res << std::endl;
    }
}

C++: #include <iostream>
#include <math.h>
#include <string>
#include <sstream>
using namespace std;

string To_string(int i) {
    stringstream ss;
    ss << i;
    return ss.str();
}

int GetDigit(int num) {
    return To_string(num).length();
}


int Q;

int main() {
    cin >> Q;
    for(int i=0; i<Q; ++i) {
        int n;
        cin >> n;
        int digit = GetDigit(n); 
        int count = 0; 
        while(1) {
            int max = 0;
            if(n >= 1 && n <= 9) {
                cout << count << endl;
                break;
            } else {
                for(int j=1; j<=digit-1; ++j) {
                    int op1 = n / int(pow(10,j));
                    int op2 = n % int(pow(10,j));
                    //cout << "op1: " << op1 << ", op2: " << op2 << endl;
                    if(op1*op2 > max) { max = op1*op2; }
                    //cout << "max at loop" << j << ": " << max << endl;
                }
                ++count;
                //cout << "max: " << max << ", count: " << count << endl;
                
                if(max >= 1 && max <= 9) {
                    cout << count << endl;
                    break;
                } else if(count > 100) {
                    cout << "-1" << endl;
                    break;
                } else {
                    n = max;
                }
            }
        }
    }
    return 0;
}