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 <cmath>
using namespace std;

int main(){
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
        int x,max,cnt=0;
        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;
            cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cmath>

using namespace std;

long Q, N;

long multip(long n, long keta){
	long maxn = 0;
	long left ,right;
	for(long i=keta-1;i>=1;i--){
		left = n / pow(10,i);
		right = n - left*pow(10,i);
		long mul = left * right;
		if(mul > maxn) maxn = mul;
	}
	return maxn;
}
		
int getketa(int n){
	int i=0;
	int keta = 1;
	for(i=1;keta>0;i++){
		keta = n / pow(10,i);
	}
	return i-1;
}

int main(){
	cin >> Q;
	for(long i=0;i<Q;i++){
		cin >> N;
		long keta;
		long count = 0;
		while(keta = getketa(N),keta != 1 && count < 10000){
			N = multip(N, keta);
			//cout << N << endl;
			count ++;
		}
		cout << count << endl;
	}
	
	return 0;
}

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

int main() {
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        string s; cin >> s;
        int c = 0;
        while (s.length() >= 2) {
            int vm = -1;
            for (int j = 1; j < s.length(); ++j) {
                int t1 = atoi(s.substr(0, j).c_str());
                int t2 = atoi(s.substr(j, s.length()-j).c_str());
                vm = max(vm, t1*t2);
            }
            ++c;
            s = to_string(vm);
        }
        cout << c << endl;
    }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<sstream>

using namespace std;

vector<string> V;

bool find(string s){
  sort(V.begin(),V.end());
  return binary_search(V.begin(),V.end(),s);
}

int StoI(string s, int pos){

  string s1 = "", s2 = "";
  
  for(int i = 0; i < pos; i++)
    s1 += s[i];
  
  for(int i = pos; i < s.length(); i++)
    s2 += s[i];

  stringstream ss1(s1), ss2(s2);
  int n1,n2;
  ss1 >> n1;
  ss2 >> n2;
  return n1*n2;
}

string ItoS(int n){
  string out = "";
  if(n == 0) out = "0";

  while(n){
    out += n%10+'0';
    n /= 10;
  }
  reverse(out.begin(),out.end());
  return out;
}

string make(string n){
  int out = 0;

  for(int i = 1; i < n.length(); i++)
     out = max(out,StoI(n,i));

  return ItoS(out);
}

int solve(string n){
  
  int rev = 0;

  while(1){
    
    if(find(n)) return -1;
    else V.push_back(n);

    if(n.length() == 1) return rev;

    n = make(n);
    rev++;
  }
}

int main(){
  int n;
  cin >> n;
  while(n--){
    V.clear();
    string in;
    cin >> in;
    cout << solve(in) << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <map>
#include <sstream>
using namespace std;
int main(){
	int Q;
	cin >>Q;
	while(Q--){
		int n;
		cin >>n;
		map<int,int>memo;
		int ans = 0;
		while(!memo[n] && n >= 10){
			memo[n] =true;
			int next = 0;
			stringstream ss;
			ss << n;
			string t =ss.str();
			for(int i = 0 ; i < t.size()-1 ; i++){
				string a = t.substr(0,i+1);
				string b = t.substr(i+1);
				int A = atoi(a.c_str());
				int B = atoi(b.c_str());
				next = max(next,A*B);
			}
			ans++;
			n = next;
		}
		if( n >= 10 ){
			cout << -1 << endl;
		}else{
			cout << ans << endl;
		}
	}
}

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

int main(void){
  int n;
  string num;
  cin >> n;
  for(int i = 0; i < n; i++){
    int cnt = 0;
    cin >> num;
    while(num.size() > 1){
      int maxn = 0;
      for(int i = 0; i < num.size() - 1; i++){
        string op1(num, i + 1, num.size() - i), op2(num, 0, i + 1);
        int n = stoi(op1) * stoi(op2);
        if(n > maxn) maxn = n;
      }
      num = to_string(maxn);
      cnt++;
      if(cnt > 1000000) break;
    }
    if(cnt <= 1000000) cout << cnt << endl;
    else cout << -1 << endl;
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int calc(int x) {
	int maxi = -1;
	for (int y = 10; y <= x; y *= 10)
		maxi = max(maxi, (x / y) * (x % y));
	if (maxi == -1) maxi = x;
	return maxi;
}

int main() {
	int Q; cin >> Q;
	while (Q--) {
		int N; cin >> N;
		int cnt = 0;
		while (calc(N) != N) {
			cnt++;
			N = calc(N);
		}
		cout << cnt << endl;
	}
}

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

int main() {
  int q;
  cin >> q;
  while(q--) {
    string s;
    cin >> s;
    int size = s.size();
    int res, ans = 0;
    while(size > 1) {
      res = 0;
      for(int i=0; i<size-1; i++) {
	string a = s.substr(0, i+1);
	string b = s.substr(i+1);
	res = max(atoi(a.c_str())*atoi(b.c_str()), ans);
      }
      stringstream ss; ss << res; s = ss.str();
      size = s.size();
      ans ++;
      if(ans > 10) break;
    }
    if(ans > 10) cout << -1 << endl;
    else cout << ans << endl;
  }
  
  return 0;
}