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<algorithm>
using namespace std;
int main()
{
	int q; cin>>q;
	while(q--) 
	{
		int n; cin>>n;
		int used[1000001];
		fill(used,used+1000001,0);
		int ans=0;
		while(!used[n]&&9<n)
		{
			int next=0,r=1;
			used[n]=true;
			while(0<n)
			{
				r*=n%10;
				n/=10;
				next=max(next,r*n);
			}
			n=next;
			ans++;
		}
		if(n<=9) cout<<ans<<endl;
		else cout<<-1<<endl;
	}
  return 0;
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;


int main(){

	int Q,N,count,tmp,max,S;
	bool FLG;
	scanf("%d",&Q);
	bool* table = new bool[1000001];

	for(int loop = 0; loop < Q; loop++){

		count = 0;
		scanf("%d",&N);
		for(int i = 0; i <= N;i++)table[i] = false;
		table[N] = true;

		FLG = false;
		while(true){
			if(N/10 == 0)break;

			max = 0;

			for(S = 10;N/S != 0; S *= 10){
				tmp = (N/S)*(N%S);
				max = (max >= tmp)?max:tmp;
			}
			N = max;
			if(table[N] == true){
				FLG = true;
				break;
			}else{
				table[N] = true;
				count++;
			}
		}

		if(FLG){
			printf("-1\n");
		}else{
			printf("%d\n",count);
		}

	}

	return 0;
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

int f(int x) {
	string s = to_string(x);
	int ma = -1;
	rep(i, 1, s.size()) {
		string a = s.substr(0, i);
		string b = s.substr(i);
		ma = max(ma, stoi(a)*stoi(b));
	}
	return ma;
}

signed main() {
	int Q; cin >> Q;
	rep(i, 0, Q) {
		int N; cin >> N;
		int cnt = 0;
		int a = N;
		while (true) {
			a = f(a);
			if (a == -1)break;
			cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#include<algorithm>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

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

    vector<int> N(Q,0);
    REP(i,Q){
        cin >> N[i];
    }
    //入力終わり

    REP(i,Q){
        int ans=0;
        while(1){
            int n=N[i];
            int a[7];
            REP(j,7){
                a[j]=n%10;
                n=n/10;
            }
            //桁ごとに分離、桁数t

            if(N[i]/10==0)break;
            //一桁の時break;

            int maxi=0;
            FOR(t,1,6){
                int b=0,c=0;
                REP(j,t){
                    int a1=a[j];
                    REP(k,j){
                        a1=a1*10;
                    }
                    b+=a1;
                }
                FOR(j,t,7){
                    int a2=a[j];
                    REP(k,j-t){
                        a2=a2*10;
                    }
                    c+=a2;
                }
                maxi=max(maxi,b*c);
            }
            N[i]=maxi;
            ans++;
            //t-1通り計算して最大値が次のN[i]    
        }
        cout << ans << endl;
    }

    return 0;
}

//AOJ2015 ?:??:??

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=1<<29,MOD=1e9+7;

int main(){
	int q; cin>>q;
	rep(i,q){
		int n; cin>>n;
		int cnt=0;
		while(n>=10){
			int div=10,tmp=0;
			while(div<n){
				if((n/div)*(n%div)>tmp) tmp=(n/div)*(n%div);
				div*=10;
			}
			n=tmp; cnt++;
		}
		cout<<cnt<<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;
}