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>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

ll STOL(string s){
    ll ret=0;
    rep(i,0,s.size()){
        ret+=(s[s.size()-i-1]-'0')*pow(10,i);
    }
    return ret;
}

int main(){
    int n;
    cin>>n;
    rep(i,0,n){
        int ans=0;
        int x; cin>>x;
        while(1){
            
            string s=to_string(x);
            if(s.size()==1){
              cout<<ans<<endl;
              break;
            }
            ll max_num=0;
            rep(i,1,s.size()){
                max_num=max(max_num,STOL(s.substr(0,i))*STOL(s.substr(i,s.size()-i)));
            }
            x=max_num;
            ans++;
            if(ans==1000000){
                cout<<-1<<endl;
                break;
            }
        }
    }
    
    return 0;
}

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

int main() {

  int n;
  cin >> n;

  for(int q=0;q<n;q++) {

    int s;
    cin >> s;
    
    int t = s;
    int a[2],max;
    int count = 0;
    while(t >= 10) {
      count++;
     
      a[0] = t % 10;
      t /= 10;
      a[1]  = t;
      max = a[0] * a[1];
      int k = 10;
      // cout << a[0] <<"&"<< a[1] << "||"<<a[0]*a[1]<<endl;
      while(t) {
	a[0] += k*(t%10);
	k *=10;
	t /= 10;
	a[1] = t;
	//	cout << a[0] <<"&"<< a[1] << "||"<<a[0]*a[1]<<endl;
	if(a[0] * a[1] > max) max = a[0]*a[1];

      }
      t = max;

      if(count > 50000) break;

    }

    if(t < 10) cout << count << endl;
    else cout << -1 << endl;

  }

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int memo[1000001];
int calc(int n) {
    if(memo[n]!=-1) return memo[n];
    if(n<10) return 0;
    string s=to_string(n);
    int to=0;
    for(int i=1;i<=s.size()-1;i++) {
        to=max(to,stoi(s.substr(0,i))*stoi(s.substr(i)));
    }
    return memo[n]=calc(to)+1;
}
int main() {
    int Q,N;
    scanf("%d",&Q);
    memset(memo,-1,sizeof(memo));
    for(int i=0;i<Q;i++) {
        scanf("%d",&N);
        printf("%d\n",calc(N));
    }
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int DivideMul(int N,int a){
  int L=N%(int)pow(10,a);
  int U=(N-L)/pow(10,a);
  return L*U;
}

int Next(int N){
  int n=0;
  double s=log(N)/log(10);
  for(int i=1;i<s;++i){
      n=max(n,DivideMul(N,i));
  }
  return n;
}


int main(){
  int T;
  cin >> T;
  for(int i=0; i<T; ++i){
    
    int N;
    cin >> N;
    if(N==0){
      cout << 0 << endl;;
      break;
    }

    int j=0;
    for( j=0; N>9 ; ++j){
      N=Next(N);
      //cout <<N<<endl;
    }
   
    cout << j << endl;;
  }
}

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

using namespace std;

int main() {
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int value, source_value, count = 0;

		cin >> source_value;
		value = source_value;

		while (value >= 10) {
			count++;

			string str = to_string(value);
			int len = str.size(), max = 0;

			for (int j = 1; j < len; j++) {
				int temp1, temp2;

				temp1 = stoi(str.substr(0, j));
				temp2 = stoi(str.substr(j));

				if (max < temp1 * temp2) {
					max = temp1 * temp2;
				}
			}

			value = max;

			if (value == source_value) {
				cout << -1 << endl;
				goto TO;
			}
		}

		cout << count << endl;
	TO:;
	}

	return 0;
}

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

int main()
{
  int q,n,i,j,max,can;

  cin>>q;
  for(i=0;i<q;i++){
    cin>>n;
    j=0;
    for(;n>9;){
      max=0;
      for(int d=10;n%d!=n;){
	can=(n%d)*(int)((n-(n%d))/d);
	if(can>max) max=can;
	d*=10;
      }
      j++; n=max;
    }
    cout<<j<<endl;
  }
}

C++: #include <iostream>
using namespace std;
int main(){
  int Q, N;
  cin >> Q;
  while(Q--){
    cin >> N;

    int count = 0;
    while(N >= 10){
      count++;
      int best = 0;
      int p = 1;
      while(p < N){
        best = max(best, (N % p) * (N / p));
        p *= 10;
      }
      N = best;
    }
    cout << count << endl;
  }
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int main() {
  int Q; cin >>Q;
  REP(q, Q){
    int ans = -1, cnt = 0;
    string s; cin >>s;
    set<string> S;
    while(S.find(s) == S.end()){
      if((int)s.length() == 1){
        ans = cnt;
        break;
      }
      ++cnt;
      S.insert(s);
      int tmp = 0;
      FOR(i, 1, (int)s.length()){
        int a = atoi(s.substr(0, i).c_str()), b = atoi(s.substr(i).c_str());
        tmp = max(tmp, a * b);
      }
      stringstream ss; ss <<tmp;
      s = ss.str();
    }
    cout <<ans <<endl;
  }
  return 0;
}