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 <map>
#include <cstdlib>
#include <sstream>
using namespace std;
int main(){
	int Q;
	cin >>Q;
	while(Q--){
		int n;
		cin >>n;
		map<int,int>memo;
		int ans = 0;
		while(!memo[n] && n >= 10){
			memo[n] =true;
			int next = 0;
			stringstream ss;
			ss << n;
			string t =ss.str();
			for(int i = 0 ; i < t.size()-1 ; i++){
				string a = t.substr(0,i+1);
				string b = t.substr(i+1);
				int A = atoi(a.c_str());
				int B = atoi(b.c_str());
				next = max(next,A*B);
			}
			ans++;
			n = next;
		}
		if( n >= 10 ){
			cout << -1 << endl;
		}else{
			cout << ans << endl;
		}
	}
}

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

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for(int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for(ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

int q;

int main() {
	std::cin >> q;
	rep(i, q) {
		int n;
		std::cin >> n;
		int cnt = 0;
		while (true) {
			int max = 0;
			std::string str = std::to_string(n);
			if (str.size() == 1)break;
			REP(i, 1, str.size()) {
				max = std::max(max, std::atoi(str.substr(0, i).c_str()) * std::atoi(str.substr(i, str.size() - i).c_str()));
			}
			n = max;
			cnt++;
		}
		std::cout << cnt << std::endl;
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <cstdlib>
#include <sstream>
#include <algorithm>

using namespace std;
 
string its(int n){
    stringstream s;
    s << n;
     
    return s.str();
}
 
int main(){
    string str;
    int n;
     
    cin >> n;
    while(n--){
        int cnt = 0;
        cin >> str;
        int len = str.size();
         
        while(len > 1){
            cnt++;
            int MAX = 0;
            for(int i = 0 ; i < len-1; i++){
                int a = atoi(str.substr(0,i+1).c_str());
                int b = atoi(str.substr(i+1,len-1).c_str());
                MAX = max(MAX,a*b);
            }
            str = "";
            str += its(MAX);
            len = str.size();
        }
        cout << cnt << endl;
    }
    return 0;
}

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

int n, q;

int keta(int num)
{
    int i = 1;
    while (1) {
        if (num < 10) break;
        num /= 10;
        i++;
    }
    return i;
}

int tejun2(int n, int ketasuu)
{
    int max = 0;
    int tmp = 10;
    for (int i = 1; i < ketasuu; i++) {
        int x = n / tmp;
        int y = n % tmp;
        int tmp2 = x * y;
        if (max < tmp2) max = tmp2;
        tmp *= 10;
    }
    return max;
}

int kakezan(int n)
{
    int count = 0;
    while (1) {
        int ketasuu = keta(n);
        if (ketasuu == 1) break;
        n = tejun2(n, ketasuu);
        count++;
    }
    return count;
}

int main()
{
    cin >> q;
    for (int i = 0; i < q and cin >> n; i++) {
        int ans = kakezan(n);
        cout << ans << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
#include<stdio.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;



int main(void){
	ll q;
	cin>>q;
	for(ll i=0;i<q;i++){
		string s;
		ll ans=0;
		cin>>s;
		while(true){
			if(s.length()==1)break;
			else{
				ans++;
				vector<ll>num;
				for(ll i=0;i<s.length()-1;i++){
					string t=s.substr(0,i+1);
					string u=s.substr(i+1,s.length()-i-1);
					ll x=0,y=0;
					for(ll j=t.length()-1;j>=0;j--){
						ll digit=t[j]-'0';
						x+=digit*pow(10,t.length()-1-j);
					}
					for(ll j=u.length()-1;j>=0;j--){
						ll digit=u[j]-'0';
						y+=digit*pow(10,u.length()-1-j);
					}
					num.push_back(x*y);
				}
				sort(num.begin(),num.end());
				ll m=num[num.size()-1];
				s=to_string(m);
			}
		}
		cout<<ans<<endl;
	}
    return 0;
}

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

//int i=1;
int n;
int i=1;
int temp=0;
int ans=0;

int pow(int a,int b){
  int ans=1;
  if(b==0){
    return 1;
  }
  else{
    for(int i=0;i<b;i++){
      ans = a*ans;
    }
    return ans;
  }
}

int solve(int a){
  temp=0;
  i=1;
  while(1){
    if(a%pow(10,i)==a)break;
    else{
      temp=max(temp,(a%pow(10,i))*((a-a%pow(10,i))/pow(10,i)));
      i++;
    }
  }
  return temp;
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> temp;
    while(1){
      if(temp%10==temp)break;
      else{
        solve(temp);
        ans++;
      }
    }
    cout << ans << endl;
    ans=0;
  }
}