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<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
long long m[100000];
int main() {
	int n;
	cin >> n;
	for (int z = 0; z < n; z++) {
		long long a;
		cin >> a;
		int sum = 0;
		while (to_string(a).length() != 1) {
			string h = to_string(a), c, d;
			long long b = 0;
			for (int i = 0; i < h.length() - 1; i++) {
				c = h.substr(0, i+1);
				d = h.substr(i+1, h.length()-i-1);
				b = max((stoll(c)*stoll(d)), b);
			}
			a = b;
			int s = 0, e = sum - 1, t;
			while (e - s > 1) {
				t = (e + s) / 2;
				if (m[t] >= a) s = t;
				if (m[t] < a) e = t;
			}
			if ((m[s] == a || m[e] == a)&&s>=0&&e>=0) {
				sum = -1;
				break;
			}
			m[sum] = a;
			sort(m, m + sum);
			sum++;
		}
		cout << sum << endl;
	}
}

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

int rec(int n, int count) {
    if (n < 10) return count;
    int mx = 0;
    for (int i=10; i<=1000000; i*=10) {
        mx = max(mx, (n / i) * (n % i));
    }
    return rec(mx, count + 1);
}

int main() {
    int q, n;
    cin >> q;
    for (int i=0; i<q; ++i) {
        cin >> n;
        cout << rec(n, 0) << 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++;
    }
    cout<<c<<endl;
  }
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

int kakezan(string n, int times) {
    if (n.size() == 1) return times;
    int maxi = 0;
    repl(i, 1, n.size()) {
        int a = stoi(n.substr(0, i)), b = stoi(n.substr(i, n.size() - i));
        maxch(maxi, a * b);
    }
    return kakezan(to_string(maxi), times + 1);
}


int main(){
    cin.sync_with_stdio(false);
    int q;
    cin >> q;
    rep(i, q) {
        string n;
        cin >> n;
        cout << kakezan(n, 0) << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>

using namespace std;

int solve(int n,int ans){
    int pp=1;//N????????°
    while(true) {
        if (pow(10,pp)>n) {
            break;
        }else{
            pp++;
        }
    }
    if (pp==1) {
        return ans;
    }else{
        ans++;
    }
   // cout << pp<<"|";
    
    int mm=0;
    for (int i=1; i<pp; i++) {
        int zen,go;
        go = n % (int)pow(10,i);
        zen =(n-go)/(int)pow(10,i);
       // cout << zen <<"^"<<go<<"~~";
        mm=max(mm,zen*go);
    }
   // cout << mm<<",";
    return solve(mm,ans);
}


int main(){
    int Q;
    cin >> Q;
    for(int i=0;i<Q;i++){
        int N;
        cin >> N;
        cout << solve(N, 0) <<endl;
        continue;
    }
    
}

C++: #include <iostream>
#include <algorithm> 
#define MAX(a,b) a>b?a:b
#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;

int main(){
    int Q;
    int N;
    scanf("%d",&Q);
    rep(i,Q){
        int count = 0;
        scanf("%d",&N);
        while(N>=10){
            int temp = N;
            int digit = 0;
            while(temp>0){
                digit++;
                temp/=10;
            }
            count++;
            temp = 10;
            int max = 0;
            rep(i,digit-1){
                max = MAX(max,(N/temp)*(N%temp));
                temp*=10;
            }
            N = max;
        }
        printf("%d\n",count);
    }
    return 0;
}

C++: #include "bits/stdc++.h"
#define pb push_back
#define mt make_tuple
#define all(a) (a).begin(),(a).end()
#define frep(i,a,n) for(int i=(a);i<(n);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define rrep(i, n) for(int i=n-1;i>=0;--i)
#define debug(x) cout << #x << " : " << x << " ------------ " << endl;
using namespace std;
int main()
{
    int q;
    cin >> q;
    while (q--) {
        int n, count = 0;
        cin >> n;
        map<int, bool> h;
        while (1) {
            if (floor(n/10) == 0) break;
            string s = to_string(n);
            vector<int> p;
            frep(i, 1, s.length()) {
                int tmp = stoi(s.substr(0, i)) * stoi(s.substr(i));
                p.pb(tmp);
                if (tmp == 0) break;
            }
            int m = *max_element(all(p));
            if (h[m]) {
                count = -1;
                break;
            }
            n = m;
            h[m] = true;
            ++count;
        }
        
        cout << count << endl;
    }
    return EXIT_SUCCESS;
}