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 <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int q; cin>>q;
    cin.ignore();
    rep(_,q){
        string s; cin>>s;
        if(s.size()==1){cout<<0<<endl; continue;}
        bool flag=true;
        int cnt=1, num=0, ans=0;
        while(true){
            string hoge;
            for(int i=1; i<=s.size()-1;i++){
                string a,b;
                a=s.substr(0,i);
                b=s.substr(i);
               // cout<<"a "<<a<<" b "<<b<<" s "<<s<<endl;
                if(num<stoi(a)*stoi(b)){num=stoi(a)*stoi(b);}
                
            }
            s=to_string(num);
            if(s.size()==1){ans=cnt; break;}
            cnt++;
            if(cnt>10000){flag=false;break;}
            num=0;
        }
        if(flag)cout<<ans<<endl;
        else cout<<-1<<endl;
    }
    
}

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

#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define dbg(x) cout<<#x<<": "<<(x)<<"\n"

void solve(string n) {
    int cnt = 0;
    while(stoi(n) > 9) {
        int m = n.size();
        int ma = -1;
        for(int i=1; i<m; i++) {
            string s1 = n.substr(0,i);
            string s2 = n.substr(i,m-i);
            if(stoi(s1) * stoi(s2) > ma) {
                ma = stoi(s1) * stoi(s2);
            }
        }
        n = to_string(ma);
        cnt++;
    }
    cout << cnt << "\n";
}

int main() {
    int q; cin>>q;
    rep(i,q) {
        string n; cin>>n;
        solve(n);
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int dp[10000000];

int solve(int n) {

    if(dp[n] != -1) {
        return dp[n];
    }

    if(n < 10) {
        return 0;
    }

    int nn= 0;

    for(int i = (int)log10(n); i > 0; --i) {
        nn = max(nn, (n / (int)pow((double)10, i)) * (n % (int)pow((double)10, i)));
    }

    return dp[n] = solve(nn) + 1;

}

int main() {

    int q, n;

    memset(dp, -1, sizeof(dp));

    cin >> q;

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

}

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)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;


void solve(string N){

	  int l = N.size();
	  int ans = 0;
	  while(l>1){
			int maxi = 0;
			for(int i=1; i<l; i++){
				  int pre = stoi( N.substr(0,i) );
				  int suf = stoi( N.substr(i,l-i) );
				  maxi = max(maxi,pre*suf);
			}
			N = to_string(maxi);
			l = N.size();
			ans++;
	  }
	  cout << ans << endl;

}


int main(){

	  int Q; cin >> Q;
	  for(int i=0; i<Q; i++){
			string N; cin >> N;
			solve(N);
	  }

}

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

int main(){
    int q;
    cin >> q;
    while( q-- ){
        int count = 0;
        int n;
        cin >> n;
        while( n >= 10 ){
            int d = 0;
            int max = 0;
            while( d++ < 6){
                int a, b;
                a = n / pow( 10, d );
                b = n % (int)pow( 10, d );
                if( max < a * b ) max = a * b;
            }
            count++;
            n = max;
        }
        cout << count << endl;
    }
}

C++: #include <iostream>
#include <set>
#define llint long long

using namespace std;

llint Q;
llint n;
set<llint> S;

llint get(llint x)
{
  llint keta = 0;
  for(llint t = x; t; t/=10) keta++;
  llint mul = 10, ret = 0;
  for(int i = 0; i < keta-1; i++){
    ret = max(ret, x/mul * (x%mul));
    mul *= 10;
  }
  return ret;
}

int main(void)
{
  cin >> Q;
  for(int i = 0; i < Q; i++){
    cin >> n;
    llint ans = 0;
    S.clear();
    S.insert(n);
    while(1){
      if(n < 10){
        cout << ans << endl;
        break;
      }
      n = get(n);
      ans++;
      if(S.count(n)){
        cout << -1 << endl;
        break;
      }
      S.insert(n);
    }
  }
  return 0;
}