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<stdlib.h>
#include<string.h>
#include<sstream>
#include<algorithm>
#include<set>
using namespace std;

int main()
{
	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++)
	{
		int N;
		cin >> N;
		int count = 0;
		set<int> intSet;
		while (N > 9 && intSet.find(N) == intSet.end())
		{
			intSet.insert(N);
			count++;
			string s;
			stringstream strStream;
			strStream << N;
			s = strStream.str();
			int maxV = 0;
			for (int i = 1; i < s.size(); i++)
			{
				string ss = s.substr(0, i);
				string sss = s.substr(i, s.size());
				int ii = atoi(ss.c_str());
				int iii = atoi(sss.c_str());
				maxV = max(maxV, ii * iii);
			}

			N = maxV;
		}
		if (intSet.find(N) != intSet.end())
		{
			cout << -1 << endl;
		}
		else
		{
			cout << count << endl;
		}
	}
	return 0;
}

C++: #include<stdio.h>

int main(){

int n;
while(1){
scanf("%d",&n);if(n==0)break;
int x;
for(int i=0;i<n;i++)
{scanf("%d",&x);
int c=0;int d=10;int w=0,y=0;int max=0;
while(x/10!=0){
for(int j=0;j<6;j++)
{
w=x/d;y=x%d;d*=10;
if(j==0)max=w*y;
else if(w*y>max)max=w*y;}
x=max;c++;d=10;}
printf("%d\n",c);
}
}
return 0;
}

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

using namespace std;

int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

int main(void)
{
	int q;
	cin >> q;
	while (q--){
		int n;
		cin >> n;
		int maxnum = n;
		int cnt = 0;
		while (cnt < 100000){
			string str = toString(maxnum);
			if (toString(maxnum).length() == 1){
				cout << cnt << endl;
				break;
			}
			maxnum = 0;
			for (int i = 0; i < str.length(); i++){
				string a = str.substr(0, i), b = str.substr(i);
				// cout << a << " " << b << endl;
				int tmp = toInt(a) * toInt(b);
				maxnum = max(maxnum, tmp);
			}
			// cout << maxnum << endl;
			cnt++;
		}
		if (cnt == 10000) cout << -1 << endl;
	}

	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1001

const int MAX_P = 200000; //max
bool prime[MAX_P+1];

void Eratosthenes(void){
  for(int i=2;i<=MAX_P;i++)
    prime[i]=true;
  
  for(int i=2;i*i<=MAX_P;i++)
    if(prime[i])  
      for(int j=i;i*j<=MAX_P;j++)
	prime[i*j]=false;
}


bool calc(){
  int n;
  set<int> ss;
  
  scanf("%d",&n);

  for(int i=0;;i++){
    if(ss.find(n)!=ss.end()){
      puts("-1");
      break;
    }
    ss.insert(n);    

    if(n<10){
      printf("%d\n",i);
      break;
    }

    int max_n = 0;
    for(int i=10;i<n;i*=10){
      max_n = max(max_n,(n%i)*(n/i));
    }

    n = max_n;
  }
  
  return true;
}
  
int main(){
  int t;
  
  scanf("%d",&t);
  for(int i=0;i<t;i++){
    calc();
  }
  
  //while(calc());
  
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    while(Q--){
        int N;cin>>N;
        int cnt=0;
        while(N>=10){
            string S=to_string(N);
            int maxi=0;
            for(int i=1;i<S.size();i++){
                int A=stoi(S.substr(0,i)),B=stoi(S.substr(i,int(S.size())-i));
                maxi=max(maxi,A*B);
            }
            N=maxi;
            cnt++;
        }
        
        cout<<cnt<<endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;


int n;

string calc(string x){
	int Max=0;
	for(int i=1;i<x.size();i++){
		Max = max(Max, atoi(x.substr(0, i).c_str()) * atoi(x.substr(i).c_str()));
	}
	stringstream ss;
  	ss << Max;
  	return ss.str();
}
main(){
	int i,j;
	string x;
	cin >> n;
	while(n--){
		int ans=0;
		cin >> x;
		for(;x.size()>1;ans++) x=calc(x);
		cout << ans << endl;
	}
	return 0;
}

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

int jyou(int n){
    int ans = 1;
    for(int i = 0; i < n; i++){
        ans = ans*10;
    }
    return ans;
}

int keta(int n){
    int ans = 0;
    while(n > 0){
        n = n / 10;
        ans++;
    }
    return ans;
}

int funk(int n){
    int ke = keta(n);
    int a, b;
    int ans = 0;

    for(int i = 1; i < ke; i++){
        a = n / jyou(i);
        b = n % jyou(i);
        //cout << a << " " << b << endl;
        ans = max(ans,a*b);
    }

    return ans;
}

int main(void){

    //cout << jyou(3) << endl;
    //cout << keta(1024) << endl;
    //cout << funk(1024) << endl;

    int q; cin >> q;

    for(int i = 0; i < q; i++){
        int n; cin >> n;
        vector<bool> used(1000010, false);
        
        int ans = 0;

        while(n >= 10){

            n = funk(n);

            if(used[n] == true){
                cout << -1 << endl;
                break;
            }
            used[n] = true;
            ans++;
        }

        cout << ans << endl;
    }

    return 0;

}