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;
int main(){
  int q,n=0;
  int num,ten,k=0;
  int count,mx=0;
  int ans=0;
  bool check;
  int s[10000]={0};
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>num;
    k=0;
    n=num;
    ans=0;
    for(int j=0;j<10000;j++){
      s[j]=0;
    }
    while(1){
      mx=0;
      check=false;
      count=2;
      if(n/10==0){
	cout<<ans<<endl;
	break;
      }
      if(n/100==0) count=3;
      else if(n/1000==0) count=4;
      else if(n/10000==0) count=5;
      else if(n/100000==0) count=6;
      else if(n/1000000==0) count=7;
      ten=1;
      for(int j=1;j<count;j++){
	ten*=10;
	mx=max(mx,(n/ten)*(n-(n/ten)*ten));
	/*out<<ten<<endl;*/
      }
      s[k]=mx;
      /*cout<<s[k]<<endl;*/
      k++;
      for(int j=0;j<k-1;j++){
	if(s[k-1]==s[j]){
	  check=true;
          break;
	}
      }
      if(check){
	cout<<-1<<endl;
	break;
      }
      n=mx;
      ans++;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int main(){
	int q;
	int inp;
	cin >>q;
	for(int i =0;i<q;i++){
		cin >>inp;
		int counter =0;
		int a[5]={0};
		while(inp>9){
			int max = 0;
			for(int i = 1;i<6;i++){
				int num=1;
				for(int j= 0; j<i ; j++){
					num *=10;
				}
				a[i-1] =(inp/num)*(inp%num);
				if(max<a[i-1]) max = a[i-1];
			}
			counter++;
			inp = max;
		}
		cout << counter <<endl;
	}

	return 0;
}

C++: #include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
	int q,n;
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>n;
		int ct=0,keta=1;
		while(n>9){
			for(int k=6;k>=1;k--){
				if(n/pow(10,k)>=1){
					keta=k;
					break;
				}
			}
			int ma=0;
			for(int j=1;j<=keta;j++){
				int a=pow(10,j);
				ma=max(ma,(n/a)*(n%a));
			}
			if(n==ma){
				ct=-1;
				break;
			}
			n=ma;
			ct++;
		}
		cout<<ct<<endl;
	}
    return 0;
}

C++: #include <string>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int
main() {
  // int a = std::stoi("123");
  // int a {std::stoi("0123") };
  // vector<int> in { 9, 99, 123 };
  vector<int > in {999999,1000000};
  
  for (auto i:in ) {
    int a = i, cnt=0;;
    string s{};
    while (a >= 10) {
      auto enum_int = [&] {
	s = to_string(a);
	vector<pair<string,string> > xs;    
	for (int i=1;i<s.size(); i++) {
	  xs.push_back( std::make_pair( s.substr(0,i), s.substr(i) ) );
	}
	return xs;
      };
      auto && xs = enum_int();
      int m = 0;
      for (auto & x : xs) {
	m = max(m, std::stoi(x.first) * std::stoi(x.second) );
      }
      a = m;
      cnt++;
    }
    cout << cnt << endl;    
  }

  return 0;
}

C++: #include<iostream>
using namespace std;
#define rep(i, j) for(int i = 0; i < j; i++)

int retMax(int n){
	int ret = -1;
	for(int i = 10; n % i != n; i *= 10){
		int a = n / i, b = n % i;
		ret = max(ret, a * b);
	}
	return ret;
}

int main(){
	int q;
	cin >>q;
	for(int z = 0; z < q; z++){
		int n, ans = 0; cin >>n;
		while(n >= 10){
			int befn = n;
			n = retMax(n);
			ans++;
			if(befn < n){
				ans = -1;
				break;
			}
		}
		cout <<ans <<endl;
	}
	return 0;
}

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


int main(){
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
        unordered_set<int> hold;
        int x,max;
        bool flag=true;
        cin >> x;
        while(x>=10){
            max=0;
            for(int j=10; j<x; j*=10){
                int val = x/j * (x%j);
                if(val > max){
                    max = val;
                }
            }
            x=max;
            if(!(hold.insert(x).second)){
                flag=false;
                break;
            }
        }
        if(flag){
            cout << hold.size() << endl;
        }else{
            cout << -1 << endl;
        }
    }
    return 0;
}

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

int modify(int n){
    string s = to_string(n);
    int ret = -1;
    for(int i = 1; i < s.length(); i++){
        string a = s.substr(0,i), b = s.substr(i);
        ret = max(ret, stoi(a)*stoi(b));
    }
    return ret;
}

int main(){
    int q;
    cin >> q;

    int n;
    while(q-- > 0){
        cin >> n;
        int step = 0;
        while(n > 9){
            n = modify(n);
            step++;
        }
        cout << step << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<set>
using namespace std;int Q,N,a,p,M,t;main(){for(cin>>Q;Q--;cout<<a<<endl){set<int>u;for(cin>>N,a=0;N/10&&~a;N=M)for(u.count(N)&&(a=-2),u.insert(N),a++,p=M=1;p<N;p*=10,M=t>M?t:M)t=(N/p)*(N%p);}}

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

int stoi(string& s){
	int ret=0;
	for(unsigned int i=0;i<s.length();++i){
		ret+=s[i]-'0';
		ret*=10;
	}
	return ret/=10;
}

int stoi(string& s,int a , int b){
	string tmp=s.substr(a , b);
	return stoi(tmp);
}

int stoi(string&s , int n){
	string tmp=s.substr(0,n);
	return stoi(tmp);
}



int main(){
	int q;
	cin >> q;
	for(int i=0;i<q;++i){
		int cnt=0;
		string s;
		int org;
		cin >> s;
		org=stoi(s);
		int mul1,mul2;
		bool b=true;
		while(s.size()!=1){
			int mx=0;
			for(unsigned int j=1;j<s.size();++j){
			mul1=stoi(s,j);
			mul2=stoi(s,j,s.size()-j);
			mx=max(mx,mul1*mul2);
			}
			if(mx==org){
				b=false;
				break;
			}
			s=to_string(mx);
			cnt++;
		}
		cout << (b ?cnt:-1) << endl;
	}
	return 0;
}