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>
using namespace std;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) for(int i=0;i<n;i++)
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vlai=valarray<int>;

#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()


int main(void){
    int p;
    cin>>p;
    rep(lp,p){
        string n;cin>>n;
        int ans=0;
        while(n.length()!=1){
            int mx=-1;
            range(i,1,n.length()){
                string a=n.substr(0,i);
                string b=n.substr(i);
                mx=max(mx,stoi(a)*stoi(b));
            }
            n=to_string(mx);
            ans++;
        }
        cout<<ans<<endl;
    }
}

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));
					l = N / int(pow(10, j + 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 <string>
#include <cstdlib>
#include <algorithm>
#include <sstream>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;

bool T[1000001];

string kakezan(string s)
{
  int m = -1;
  for(int i = 1; i < s.size(); i++){
    m = max(m, atoi(s.substr(0,i).c_str()) * atoi(s.substr(i).c_str()));
  }
  ostringstream ostr;
  ostr << m;
  return ostr.str();
}

int main()
{
  int Q;
  cin >> Q;
  REP(i,Q){
    fill(T, T+100000, false);
    string N;
    cin >> N;
    if(N.size() == 1){
      cout << "0" << endl;
      continue;
    }
    int ans = 0;
    string s = N;
    while(s.size() != 1){
      s = kakezan(s);
      if(T[atoi(s.c_str())]){
        cout << "-1" << endl;
        break;
      }
      T[atoi(s.c_str())] = true;
      ans++;
    }
    cout << ans << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<algorithm>
#include<set>

using namespace std;
typedef long long int lli;

lli tejun2(int s) {
    lli res=0;

    for(lli i=1; i<1e7; i*=10)
        res = max(res, (s%i)*(s/i));
    return res;
}

int main(void) {
    int q;
    scanf("%d", &q);
    for(int i=0; i<q; i++) {
        int n;
        scanf("%d", &n);

        set<lli> hist;
        lli last=n;
        for(int i=0; i<100000; i++) {
            if(last/10 == 0) {
                printf("%d\n", i);
                goto BR;
            }
            if(hist.find((last = tejun2(last))) == hist.end()) {
                hist.insert(last);
            }
        }
        printf("-1\n");
BR:
        ;
    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>
#include <numeric>
#include <set>
#include <map>
//#include <bits/stdc++.h>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\n");
#define mod 1000000007

using namespace std;

int Str2Num(string s)
{
	stringstream ss;
	ss << s;
	int num;
	ss >> num;
	return num;
}
string Num2Str(int num)
{
	stringstream ss;
	ss << num;
	return ss.str();
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n; cin >> n;
	rep(i, n)
	{
		string tar; cin >> tar;
		int ans = 0;
		while (1)
		{
			int tmp = 0;
			if ((int)tar.size() == 1) { break; }
			rep(i, (int)tar.size() - 1)
			{
				string sp1, sp2;
				sp1 = accumulate(tar.begin(), tar.begin() + i + 1, string());
				sp2 = accumulate(tar.begin() + i + 1 , tar.end(), string());
				tmp = max(tmp, (Str2Num(sp1) * Str2Num(sp2)));
			}
			tar = Num2Str(tmp);
			ans++;
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

#define REP(i,a) for(long i=0;i<(a);++i)

typedef long long LL;

LL solve(const int n) {
    LL cnt = 0;
    
    LL val = n;
    std::string str = std::to_string(n);

    std::set<LL> set;
    while(str.length() > 1) {
        if(set.count(val) > 0) {
            return -1;
        }
        set.insert(val);

        int len = str.length();

        LL left = 0;
        LL right = std::atoll(str.c_str());
        LL max = 0;
        REP(i, len-1) {

            int x = str[i] - '0';
            left  = left*10 + x;
            right = right - x * std::pow(10, len-i-1);

            max = std::max(max, left*right);
        }
        val = max;
        str = std::to_string(max);

        ++cnt;
    }
    return cnt;   
}

int Q;
int main() {
    std::cin >> Q;
    REP(i, Q) {
        int N;
        std::cin >> N;
        LL res = solve(N);
        std::cout << res << std::endl;
    }
}