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 <bits/stdc++.h>
using namespace std;

string str;
int cnt;
int inf;

string solve(string x){
  int ret = INT_MIN;
  string a;
  string ans;

  // cout << x << " " << cnt << endl;
  if(x.size() == 1) return x;
  if(inf <= atoi(x.c_str()) && cnt != 0){
    cnt = -1;
    return 0;
  }
  for(int i = 0; i < (int)x.size(); i++){
    string b;
    a+=x[i];
    for(int j = i+1; j < (int)x.size(); j++){
      b += x[j];
    }
    int c = atoi(a.c_str())*atoi(b.c_str());
    if(ret < c){
      ret = max(ret,c);
    }
  }
  stringstream s;
  s << ret;
  s >> ans;
  cnt++;
  return solve(ans);

}

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

  for(int i = 0; i < q; i++){
    cnt = 0;
    cin >> str;
    inf = atoi(str.c_str());
    solve(str);
    cout << cnt << endl;
  }


}

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

int Q;

int max_kakezan(int n){
    int dec = 1;
    int front,back;
    int max = -1000;
    while(n/dec != 0) {
        front = n/dec;
        back = n%dec;
        if (max < front * back){
            max = front * back;
        }
        dec *= 10;
    }
    return max;
}

int  how_many_kakezan(int n){
    int times = 0;
    while (n/10 != 0) {    //もしnが1桁ならば、終了,それ以外は続行
        n = max_kakezan(n);
        times++;
    }
    return times;
}

int main(){
    cin >> Q;
    for (int q = 0; q < Q; q++){
        int n;
        cin >> n;
        cout << how_many_kakezan(n) << endl;
    }
}

C++: #include <cstdio>
#include <cstdint>
#include <string>
#include <algorithm>
#include <vector>

intmax_t f(intmax_t r) {
  std::string s = std::to_string(r);
  intmax_t res = 0;
  for (size_t i = 1; i < s.length(); ++i) {
    std::string s0 = s.substr(0, i);
    std::string s1 = s.substr(i);
    intmax_t r0 = std::stoi(s0);
    intmax_t r1 = std::stoi(s1);
    res = std::max(res, r0*r1);
  }
  if (res > 1e9) return -1;
  return res;
}

int testcase_ends() {
  intmax_t R;
  scanf("%jd", &R);

  int res = 0;
  while (R > 9) {
    R = f(R);
    ++res;
  }
  printf("%d\n", res);
  return 0;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) testcase_ends();
}

C++: #include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
int N,Q;

int calc(int i,int n){
    int num = 0;
    if(n<10){
        return i;
    }else{
        int ten = 10;
        while(ten<= n){
            int temp = (n/ten) * (n%ten);
            if (num<temp)num=temp;
            ten *= 10;
        }
    }
    return calc(i+1,num);
}

int main(){

    cin >>Q ;
    for (int i=0;i<Q;i++){
        cin >> N;
        int ans = calc(0,N);
        cout << ans <<endl;
    }
}

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

int a[7]={1,10,100,1000,10000,100000,1000000};
int ans;

int solve(int n){
    int res=0;
    if(n<10) return n;
    ans++;
    for(int i=0;a[i]<n;i++){
        res=max(res,(n/a[i])*(n%a[i]));
    }
    return solve(res);
}

int main(){
    int q;
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        int n;
        ans=0;
        scanf("%d",&n);
        solve(n);
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define LIMIT 1000000

int len(int n) {
    int count = 0;
    while (n) {
        count++;
        n /= 10;
    }
    return count;
}

int power(int n) {
    int p = 1;
    for (int i = 0; i < n; i++) {
        p *= 10;
    }
    return p;
}

int main() {
    int q;
    cin >> q;
    while (q--) {
        int n;
        cin >> n;
        int count = 0;
        while (len(n) > 1 && count < LIMIT) {
            int next = 0;
            for (int i = 1; i < len(n); i++) {
                int res = power(len(n) - i);
                int a = n / res;
                int b = n % res;
                next = max(next, a * b);
            }
            n = next;
            count++;
        }
        if (count == LIMIT) cout << -1 << endl;
        else cout << count << 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 };

  int n;
  cin >> n;
  vector<int> in;
  
  for (int i=0; i<n; ++i) {
    int v;
    cin >> v;
    in.push_back( stoi(v) );
  }
  
  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;
}

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

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)

using namespace std;
typedef long long int ll;

int main(void){
	ll Q;
	cin>>Q;
	while(Q--){
		string str;
		int cnt = 0;
		cin>>str;
		vector<int> n(str.size());
		rep(i,str.size())n[i]=str[i]-'0';
		while(n.size()>1){
			double num=0;
			if(n[0]<=n[n.size()]){
				loop(i,1,n.size())num=num*10+(n[i]);
				num = num * (n[0]);
			}else{
				rep(i,n.size()-1){
					num=num*10+n[i];		
				}num = num * (n[n.size()-1]);
			}
			int size=1;
			rep(i,n.size()-1)size*=10;
			n.clear();
			if((int)num/size==0)size/=10;
			while(num!=0){
				int no=(int)num/size;
				num=(int)num%size;
				size=size/10;
				n.push_back(no);
			}
			cnt++;
		}
		cout<<cnt<<endl;
	}
}