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<vector>
using namespace std;
int Q;
int A;
int t[1000005];
int ans[105];

void solve(int y){
  int cnt=0;
  while(A>=10){
    if(t[A]==y||ans[t[A]]==-1){
      ans[y]=-1;      break;    }
    t[A]=y;
    int x=-1;
    for(int i=10;i<A;i*=10){
      int a=A/i,b=A%i;
      x=max(x,a*b);
    }
    A=x;
    cnt++;
  }
  ans[y]=cnt;
}

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

C++: using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using CHY72;

namespace CHY72{
    
    public class PointXY{
        public int X , Y;
        public int SQLength() { return X * X + Y * Y; }
        public bool Flag = false;
        public PointXY(int _X,int _Y) {
            X = _X; Y = _Y;
        }
        public PointXY(PointXY P1, int _X = 0, int _Y = 0) {
            X = P1.X +  _X; Y =P1.Y + _Y;
        }
        public static bool operator ==(PointXY P1, PointXY P2) {
            return (P1.X== P2.X && P1.Y == P2.Y);
        }
        public static bool operator !=(PointXY P1, PointXY P2) {return !(P1 ==P2);}
        public override int GetHashCode() {return X.GetHashCode() ^ Y.GetHashCode();}
        public override bool Equals(object obj) {
            if (obj == null || this.GetType() != obj.GetType()) {return false;}
            return (this == (PointXY)obj);
        }

    }

    public class Lib72 {
        public static int NumFromChar(char CNUM) { return CNUM - 48; }

        public static int[] KETAArray(int Num) {return KETAArray(Num.ToString()); }
        public static int[] KETAArray(string Num) {
            char[] cKETA = Num.ToCharArray();
            int[] iKETA = new int[cKETA.Length];
            for (int i = 0; i < iKETA.Length; i++) {
                iKETA[i] = NumFromChar(cKETA[i]);
            }
            return iKETA;
        }
        public static int KETA(int Num) { return Num.ToString().ToCharArray().Length; }
        public static int FromKETAArray(int[] _ketaarray) {
            int result = 0;
            int[] R_ketaarray = _ketaarray.Reverse().ToArray(); 
            for (int i = 0,j=1; i < R_ketaarray.Length; i++,j *=10) {
                result += j * R_ketaarray[i];
            }
            return result;
        }
        public static bool isPrime(int p) {
            if (p != 2 && p % 2 == 0) return false;
            if (p == 1) return false;
            int SQp = (int)(Math.Sqrt(p));
            for (int i = 3; i <= SQp; i++) {
                if (p % i == 0) return false;
            }
            return true;
        } 
    }
}    

public class Program {
    static bool ReadLine_1(ref int num1, bool Fin0 = true) {
        string str = Console.ReadLine();
        num1 = int.Parse(str);
        return (Fin0 && num1 == 0);
    }
    static int  ReadLine_1() {
        return  int.Parse(Console.ReadLine());
    }
    static bool ReadLine_2(ref int num1, ref int num2, char Spliter = ' ', bool Fin0 = true,int FinNum =0) {
        string str = Console.ReadLine();
        num1 = int.Parse(str.Split(Spliter)[0]);
        num2 = int.Parse(str.Split(Spliter)[1]);
        return (Fin0 && num1 == FinNum && num2 == FinNum);
    }
    static int[] ReadLine72(char Spliter = ' ') {
        return Console.ReadLine().Split(Spliter).Select(s => int.Parse(s)).ToArray();
    }

    const int DefaultMax = 72727272;



    static void Main(string[] args) {
        int Q = ReadLine_1();
        for (int i = 0; i < Q; i++) {
            int N = ReadLine_1(); int R = 0;
            while (true){
                if (Lib72.KETA(N) == 1) break;
                string Nstr = "" + N;
                break;

                R++;
            }
            Console.WriteLine(Rer);
        }
    }
}

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

using namespace std;

string N;

int toint(string s) {
	int res = 0;
	for (int i = 0; i < (int)s.size(); i++) res = 10 * res + (s[i] - '0');
	return res;
}

string tostr(int i) {
	stringstream s;
	s << i;
	return s.str();
}

void solve() {
	set<int> use;
	use.insert(toint(N));
	
	int cnt = 0;
	
	while ((int)N.size() != 1) {
		int maxi = 0;
		
		int len = (int)N.size();
		for (int i = 1; i < len; i++) {
			string l = N.substr(0, i), r = N.substr(i);
			int li = toint(l), ri = toint(r);
			int mul = li * ri;
			maxi = max(maxi, mul);
		}
		
		if (use.find(maxi) != use.end()) {
			cout << -1 << endl;
			return;
		}
		
		use.insert(maxi);
		N = tostr(maxi);
		
		cnt++;
	}
	
	cout << cnt << endl;
}

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

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  int n,m,s,max,cnt;
  string  str,str1;
  cin>>n;
  for(int i=0;i<n;i++){
     cin>>str;
     cnt=0;
     while(1){
       if(str.size()==1) break;
       str1=str[0],max=0;
     for(int j=0;j<str.size()-1;j++){
       if(j>0) str1+=str[j];
       m=stoi(str1),s=stoi(&str[j+1]);
       if(max<m*s) max=m*s;
     }
     str=to_string(max),cnt++;
     }
     cout<<cnt<<endl;    
  }
  return 0;
}