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 <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;


int main(){
	int Q;
	while(cin>>Q){
		int N;
		REP(k,0,Q){
			int ans=0;
			set<int> s;
			cin>>N;
			while(N/10>0){
				int mx=0;
				int waru=10;
				s.insert(N);
				for(int i=0;N/waru>0;i++){
					int l=N/waru;
					int r=N%waru;
					mx=max(mx,l*r);
					waru*=10;
				}
				N=mx;
				ans++;
				if(s.find(N)!=s.end()){
					ans=-1;
					break;
				}
			}
			p(ans);
		}
	}

	return 0;
}

C++: #include <iostream>
#include <cassert>
#define REP(i,l,n) for(int i=l;i<n;++i)
#define rep(i,n) REP(i,0,n)
int ans;
int Q,n;
using namespace std;
int main() {
  cin >> Q;
  rep(i,Q){
    cin >> n;
    ans = 0;
    while(n > 9){
      ans++;
      int max = 0,div = 1;
      rep(j,5){
        div *= 10;
        int post = (n/div)*(n%div);
        if(post>max) max = post;
      }
      n = max;
    }
    cout << ans << endl;
  }
  return 0;
}

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

int Q, N, logn, r, l, turn;

int main(){
	cin >> Q;
	for (int i = 0; i < Q; i++){
		cin >> N;
		logn = int(log10(N)) + 1; //N????????°?????????
		if (logn == 1) cout << 0 << endl;
		else{
			turn = 0;
			while (logn != 1){
				int max = 0;
				for (int j = 0; j < logn - 1; j++){
					r = N % int(pow(10, j + 1)+0.1);
					l = N / int(pow(10, j + 1) + 0.1);
					if (max < r*l){
						max = r*l;
					}
				}
				N = max;
				if (N == 0) logn = 1;
				else logn = int(log10(N)) + 1; //N????????°?????????
				turn++;
			}
			cout << turn << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int q, n;
    cin >> q;
    while(q--){
        cin >> n;
        set<int> s;
        int cnt = 0;
        while(n >= 10){
            if(s.count(n)){
                cnt = -1;
                break;
            }
            s.insert(n);
            string t = to_string(n);
            int ans = 0;
            for (int i = 1; i < t.size(); ++i) {
                int x = stoi(t.substr(0, i)), y = stoi(t.substr(i, 10));
                ans = max(ans, x*y);
            }
            n = ans;
            cnt++;
        }
        cout << cnt << "\n";
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>

#include <numeric>
#include <iterator>

using namespace std;
#define TIMES(var, N) for (int var = 0; var < N; ++var)

#ifdef TEST
#define DEBUG(stmts) \
    do               \
    {                \
        stmts;       \
    } while (0)
#else
#define DEBUG(_)
#endif

int solve(const string &str)
{
    if (str.size() == 1)
    {
        return 0;
    }
    vector<int> m(str.size());
    for (int n = 1; n < str.size(); ++n)
    {
        auto pre = str.substr(0, n);
        auto post = str.substr(n);
        m.push_back(stoi(pre) * stoi(post));
    }
    return 1 + solve(to_string(*max_element(m.begin(), m.end())));
}

int main()
{
    int Q;
    cin >> Q;
    TIMES(_, Q)
    {
        string str;
        cin >> str;
        cout << solve(str) << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int DivideMul(int N,int a){
  int L=N%(int)pow(10,a);
  int U=(N-L)/pow(10,a);
  return L*U;
}

int Next(int N){
  int n=10000000;
  int s=int( log(N)/log(10) );
  for(int i=1;i<s;++i){
      n=min(n,DivideMul(N,i));
  }
  return n;
}


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

    int j=0;
    for( j=0; N>9 ; j++){
      N=Next(N);
    }
   
    cout << j << endl;;
  }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <numeric>
#include <sstream>

using namespace std;

string itos(int n) {
    ostringstream s;
    s << n;
    return s.str();
}


int main() {
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int n;
        cin >> n;
        set<int> s;
        bool flag = false;
        int cnt = 0;
        while(true) {
     
            string n_str;
            n_str = itos(n);
            if (n < 10) break;
            if (s.find(n) != s.end()) {
                flag = true;
                break;
            }
            s.insert(n);

            
            // cout << "l:" << l << endl;
            int max_v = 0;
            for (int j = 1; j < n_str.length(); j++) {
                int head = 0, tail = 0;
                head = stoi(n_str.substr(0, j));
                tail = stoi(n_str.substr(j));
                // cout << head << " " << tail << endl;
                max_v = max(max_v, head * tail);
            }
            // cout << "max: " << max_v << endl;
            n = max_v;
            cnt++;
        }

        if (flag) {
            cout << -1 << endl;
        } else {
            cout << cnt << endl;
        }
    }

}

C++: #include <iostream>
#include <algorithm>

using namespace std;

int Q;
int N;

int solve(int n) {
    if (0 <= n && n <= 9) return 0;
    int max_n = 0;
    for (int i = 10; i <= n; i *= 10) {
        int a = n / i;
        int b = n % i;
        max_n = max(max_n, a*b);
    }
    return solve(max_n) + 1;
}

int main() {
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        cin >> N;
        cout << solve(N) << endl;
    }
    return 0;
}