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 <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;


int main(){

	int Q,N,count,tmp,max,S;
	bool FLG;
	scanf("%d",&Q);
	bool* table = new bool[1000001];

	for(int loop = 0; loop < Q; loop++){
		for(int i = 0; i <= 1000000;i++)table[i] = false;

		count = 0;
		scanf("%d",&N);
		table[N] = true;

		FLG = false;
		while(true){
			if(N/10 == 0)break;

			max = 0;

			for(S = 10;N/S != 0; S *= 10){
				tmp = (N/S)*(N%S);
				max = (max >= tmp)?max:tmp;
			}
			N = max;
			if(table[N] == true){
				FLG = true;
				break;
			}else{
				table[N] = true;
				count++;
			}
		}

		if(FLG){
			printf("-1\n");
		}else{
			printf("%d\n",count);
		}

	}

	return 0;
}

C++: #include<iostream>
#include<vector>
#include<queue>
using namespace std;
int f(int r,int t,int r2){
	if(r<10){
		return t;
	}else if(t>r2){
		return -1;
		}else{
		priority_queue<int> a;
		int keta=10;
		while(r>keta){
			int b=r/keta,c=r%keta;
			a.push(b*c);
			keta*=10;
		}
		return f(a.top(),t+1,r2);
	}
}
int main(void){
int n;
cin>>n;
for(int k=0;k<n;k++){
int r;
cin>>r;

cout<<f(r,0,r)<<endl;
}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    string s;
    cin>>n;
    for (int i=0;i<n;i++) {
        long long int count=0;
        cin>>s;
        while (1) {
            if (count>1000000000) {
                cout<<-1<<endl;
                break;
            } else {
                if (s.size()==1) {
                    cout<<count<<endl;
                    break;
                } else {
                    long long int max=0;
                    for (int i=1;i<s.size();i++) {
                        string one=s.substr(0,i);
                        string another=s.substr(i,s.size()-i);
                        long long int tmp=stoi(one)*stoi(another);
                        if (tmp>max) {
                            max=tmp;
                        }
                    }
                    s=to_string(max);
                    //cout<<s<<endl;
                    count++;
                }
            }
        }
    }
}

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

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;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
string cal(string s) {
	int max_v = -1111111;
	rep(i, 1, s.length()) {
		max_v = max(max_v, stoi(s.substr(0, i))*stoi(s.substr(i)));
	}
	return to_string(max_v);
}
signed main() {
	int q; cin >> q;
	rep(i, 0, q) {
		string s;
		cin >> s;
		set<string>taro;
		int cnt = 0;
		if (stoi(s) < 10)goto here;
		while (taro.find(s) == taro.end()) {
			if (stoi(s) < 10)break;
			cnt++;
			taro.insert(s);
			s = cal(s);
			dump(cnt);
			dump(s);

		}
	here:;
		if (taro.find(s) == taro.end())cout << cnt << endl;
		else cout << -1 << endl;

	}
	return 0;
}

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

using namespace std;

int main(void){

	int Q,R;
	int ko,max;
	int cnt;

	cin>>Q;

	for(int i=0;i<Q;i++){
		cin>>R;
		cnt=0;
		while(1){
			if(R/10==0) break;
			max=(R/10)*(R%10);
			for(int j=100;R/j!=0;j*=10){
				ko=(R/j)*(R%j);
				if(ko>max) ko=max;
			}
			cnt++;
			R=max;
		}
		cout<<cnt<<endl;
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
string StringChanger(int);
string StringChanger(int n){
  stringstream ss;
  ss << n;
  return ss.str();
}
int main(){
  int q,maxy;
  string str;
  cin >> q;
  for(int i=0;i<q;i++){
    cin >> str;
    int cnt = 0;
    while(str.size()!=1){
      int maxy = 0;
      for(int j=0,l=str.size();j<l;j++){
        string sub1 = str.substr(0,j);
        string sub2 = str.substr(j);
        maxy = max(maxy,atoi(sub1.c_str())*atoi(sub2.c_str()));
      }
      str = StringChanger(maxy);
      cnt++;
    }
    cout << cnt << endl;
  }
}