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(void){
    int q, n;
    cin >> q;
    for(int i = 0; i < q; i++){
        cin >> n;
        int cnt = 0;
        while(n >= 10){
            int d = 10;
            int ma = 0;
            while(int s = n / d){
                ma = max(s * (n - s * d), ma);
                d *= 10;
            }
            n = ma;
            cnt++;
        }
        cout << cnt << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
int check_digit(int t){
    int res=0;
    while(t!=0){
        t/=10;
        res++;
    }
    return res;
}
int sol(int t){
    int cd=check_digit(t);
    int c10=10;
    int res=0;
    for(int i=1;i<cd;i++){
        int t1=t%c10;
        int t2=t/c10;
        res=max(res,t1*t2);
        c10*=10;
    }
    return res;
}
int main(void){
    // Your code here!
    int q;
    cin>>q;
    int n[110];
    for(int i=0;i<q;i++){
        cin>>n[i];
        int ans=0;
        while(n[i]/10!=0){
            n[i]=sol(n[i]);
            ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)

int main(){
	int n;
	cin>>n;
	lp(z,n){
		int a,b=0,count=0;
		cin>>a;
		vector<int> lis;
		while(1){
			if(a/10==0) break;
			int i=1;
			while(1){
				if(a/10==0) break;
				b+=a%10*i;
				a/=10;
				lis.push_back(b*a);
				i*=10;
			}
			b=0;
			sort(lis.begin(),lis.end());
			reverse(lis.begin(),lis.end());
			a=lis[0];
			lis.clear();
			count++;
		}
		cout<<count<<endl;
	}
	return 0;
}

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

int size (int n) {
    int s = 0;
    for (int j = 0;; j++) {
        if (n == 0) {
            s = 1;
            break;
        }
        else if ((pow(10, j)) <= n and n < (pow(10, j + 1))) {
            s++;
            break;
        }
        else s++;
    }
    return s;
}

int main () {
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int n;
        cin >> n;
        int res = 0;
        while (size(n) != 1) {
            int max = 0;
            for (int j = 1; j < size(n); j++) {
                int a, b;
                a = n % int(pow(10, j));
                b = n / int(pow(10, j));
                if (max < a * b) {
                    max = a * b;
                }
            }
            n = max;
            res++;
        }
        cout << res << endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for(int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for(ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

int q;

int main() {
	std::cin >> q;
	rep(i, q) {
		int n;
		std::cin >> n;
		int cnt = 0;
		while (true) {
			int max = 0;
			std::string str = std::to_string(n);
			REP(i, 1, str.size() + 1) {
				max = std::max(max, std::atoi(str.substr(0, i).c_str()) * std::atoi(str.substr(i, str.size() - i).c_str()));
			}
			if (max != 0) {
				n = max;
				cnt++;
			}
			else break;
		}
		std::cout << cnt << std::endl;
	}

	return 0;
}

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

int q, n;

int keta(int n){
  int count=1;
  while (1){
    if (n>=10){
      count++;
      n = n/10;
    }
    else break;
  }
  return count;
}

int maain(){
  cin >> q;
  for (int i=0;i<q;i++){
    cin >> n;
    cout << keta(n) << endl;
  }
  return 0;
}

int main(){
  int a,b;
  cin >> q;
  for (int i=0;i<q;i++){
    cin >> n;
    int ans=0;
    while (n>=10){
      int max=0;
      int ket=keta(n);
      for (int j=1;j<ket;j++){
	a=n/pow(10,j);
	b=n-a*pow(10,j);
	if (a*b>max) max=a*b;
      }
      n=max;
      ans++;
    }
    cout << ans << endl;
  }
  return 0; 
}

C++: #include <iostream>
#include <sstream>
#include <string>

using namespace std;

int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

int main(void)
{
	int q;
	cin >> q;
	while (q--){
		int n;
		cin >> n;
		int maxnum = n;
		int cnt = 0;
		while (cnt < 10000){
			string str = toString(maxnum);
			if (toString(maxnum).length() == 1){
				cout << cnt << endl;
				break;
			}
			maxnum = 0;
			for (int i = 0; i < str.length(); i++){
				string a = str.substr(0, i), b = str.substr(i);
				// cout << a << " " << b << endl;
				int tmp = toInt(a) * toInt(b);
				maxnum = max(maxnum, tmp);
			}
			// cout << maxnum << endl;
			cnt++;
		}
		if (cnt == 10000) cout << -1 << endl;
	}

	return 0;
}