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>
#include <set>
#include <vector>
#include <string>
using namespace std;
typedef vector<int> vi;
typedef vector<bool> vb;
#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()

int solve(int n){
    set<int> s;
    int c = 0;
    while (1){
        if (n < 10) return c;
        auto it=s.insert(n);
        if (!it.second) return -1;
        string s = to_string(n);
        vector<int> v;
        rep(i, s.size() - 1){
            string a = s.substr(0, i + 1);
            string b = s.substr(i + 1);
            v.push_back(stoi(a)*stoi(b));
        }
        sort(all(v));
        n = v.back();
        c++;
    }
}

int main(){
    int q; cin >> q;
    rep(i, q){
        int n; cin >> n;
        cout << solve(n) << endl;
    }
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int ans(string s) {
    if (s.length() == 1) return 0;
    int mv = 0;
    rep(i, 1, s.length()) {
        mv = max(mv, stoi(s.substr(0, i)) * stoi(s.substr(i)));
    }
    return ans(to_string(mv)) + 1;
}

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    cin >> skipws;

    int n; cin >> n;
    rep(i, 0, n) {
        string s; cin >> s;
        cout << ans(s) << endl;
    }
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int Q;
int ans;
int cnt;
int main(){
	cin>>Q;
	for(int i =0 ;i < Q;i++){
		bool flag =true;
		map<int,int> ma;
		ll n;
		cin>>n;
		ma[n] =1;
		cnt = 0;
		while(1){
			if(n==0){
				break;
			}
			int len =log10(n)+1;
			//cout <<len<<endl;
			if(len==1){
				break;
			}
			ans = 0;
			for(int j = 0;j <len-1;j++){
				unsigned int a =n/(1*pow(10.0,j+1));
				unsigned int b =n%((int)(1*pow(10.0,j+1)));
				//cout <<"b = "<<b<<endl;
				ll x =a*b;
				if(x >ans){
					ans = x;
				}
			}
			if(ma[ans]==1){
				flag = false;
				break;
			}
			ma[ans] = 1;
			//cout <<"ans = "<<ans<<endl;
			cnt++;
			n = ans;
		}
		if(flag){
			cout <<cnt<<endl;
		}else{
			cout <<"-1"<<endl;
		}
	}
	return 0;
}

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

int main() {
	int q;
	cin >> q;
	for (int x = 0; x < q; x++) {
		int n;
		cin >> n;
		int ans = 0;
		vector<int>v;
		while (n > 9) {
			v.push_back(n);
			string a = to_string(n);
			int mx = 0;
			for (int i = 0; i < a.size() - 1; i++) {
				string b, c;
				for (int j = 0; j <= i; j++)b.push_back(a[j]);
				c = a.substr(i + 1);
				int ba = stoi(b);
				int ca = stoi(c);
				mx = max(mx, ba*ca);
			}

			int flg = 1;
			for (int i = 0; i < v.size(); i++) {
				if (mx == v[i])flg = 0;
			}
			if (!flg) {
				ans = -1;
				break;
			}
			else {
				v.push_back(mx);
				n = mx;
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}