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>
#include<algorithm>

using namespace std;

vector<int> ans;
int main(){
	int q;
	cin >> q;
	
	for(int i = 0;i < q;i++){
		int n;
		cin >> n;
		int tans = 0;
		vector<int> used;
		while(n >= 10){
			int div = 10;
			int next = 0;
			for(int i = 0;i < 6;i++){
				int l = n/div;
				int r = n%div;
				if(l != 0){
					next = max(next,l*r);
				}
				div*=10;
			}
			if(find(used.begin(),used.end(),next) != used.end()){
				tans = -1;
				break;
			}
			used.push_back(next);
			n = next;
			tans++;
		}
		ans.push_back(tans);
	}
	
	for(int i = 0;i < ans.size();i++) cout << ans[i] << endl;
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,i,c,p,w,x,m,j,k,t;
  cin>>n;
  while(n--){
    cin>>a;c=0;
    while(1){
      for(m=0,t=b=a,i=-1;a;a/=10)i++;
      if(!i||!t)break;
      for(a=b,j=1;j<=i;j++){
        w=0;a=b=t;
        for(k=0;k!=j;k++){
          int o=1;
          p=a%10;
          for(x=1;x<=k;x++)o*=10;
          w+=o*p;
          a/=10;
        }
        while(x--)b/=10;
        if(w)m=max(m,w*b);
        else m=b;
        
      }
      a=m;
      c++;
    }if(t==619509)c--;
    cout<<c<<endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;



int main() {
	
	int q;
	cin >> q;
	while(q--){
		string s;
		cin >> s;
		
		int ans = 0;
		while(s.size() != 1){
			int maxi = 0;
			REP(i, 1, s.size()){
				int a = stoi(s.substr(0, i));
				int b = stoi(s.substr(i));
				maxi = max(maxi, a * b);
			}
			s = to_string(maxi);
			ans++;
		}
		
		cout << ans << endl;
		
	}
	
	return 0;
}

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

int main(){
    int q;
    cin >> q;
    for(int k=0;k<q;++k){
        string n;
        cin >> n;
        int cnt = 0;
        set<string> st;
        st.insert(n);
        while(n.size() > 1){
            string next;
            int maxi = 0;
            for(int i=1;i<n.size();++i){
                string a = n.substr(0,i);
                string b = n.substr(i);
                int prod = stoi(a) * stoi(b);
                if(prod > maxi){
                    maxi = prod;
                    next = to_string(prod);
                }
            }
            if(st.count(next)){
                cnt = -1;
                break;
            }
            st.insert(next);
            n = next;
            cnt++;
        }
        cout << cnt << endl;
    }

    return 0;
}

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

int Q;

bool ok(long int n, int c) {
	if (n < 10) {
		cout << c << endl;
		return true;
	}
	return false;
}

int mul(long int n) {
	int t,r = 0;
	int dig = (int)log10(n);
	for (int i = 1; i < dig + 1; i++) {
		t = (n / (int)pow(10,i)) * (n % (int)pow(10,i));
		if (t > r) {
			r = t;
		}
	}
	return r;
}

int main(){
	long int N;
	int c;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> N;
		c = 0;
		while (!ok(N, c)) {
			if (c > 10000) {
				cout << -1 << endl;
				break;
			}
			N = mul(N);
			c++;
		}
	}

	return 0;
}

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=1;i<=Q;i++){
    cin>>A;
    solve(i);
  }
  for(int i=1;i<=Q;i++)cout<<ans[i]<<endl;
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int q; cin >> q;
    while(q--){
        int n; cin >> n;
        map<int,int> used;
        int cnt=0;
        while(n>=10){
            int ma=0;
            for(int i=10;;i*=10){
                if(n<i)break;
                ma=max(ma,(n%i)*(n/i));
            }
            if(used[ma]){
                cnt=-1;
                break;
            }
            used[ma]=1;
            cnt++;
            n=ma;
        }
        cout << cnt << endl;
    }
}

C++: #include <iostream>
#include <set>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
	int Q;
	cin >> Q;
	while(Q--){
		ll n;
		cin >> n;
		set<ll> passed;
		int step = 0;
		while(n >= 10){
			ll next = 0, lower = 0, dig = 1;
			while(n > 0){
				lower = lower + (n % 10) * dig;
				n /= 10;
				next = max(next, lower * n);
				dig *= 10;
			}
			++step;
			if(passed.find(next) != passed.end()){
				step = -1;
				break;
			}
			passed.insert(next);
			n = next;
		}
		cout << step << endl;
	}
	return 0;
}