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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

int calc(int x){
    if (x < 10) return 0;
    string s = to_string(x);
    int res = 1, tmp = -1;
    rep((int)s.size()-1, i) {
        int a = stoi(s.substr(0, i+1)), b = stoi(s.substr(i+1));
        tmp = max(tmp, a*b);
    }
    res += calc(tmp);
    return res;
}

void solve(void){
    int Q;
    cin >> Q;
    rep(Q, i) {
        int a; cin >> a;
        cout << calc(a) << endl;
    }
}

int main(void){
  solve();
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12

int main(void)
{
  int q, n[105];
  cin >> q;
  REP(i, q) {
    cin >> n[i];
    int cnt = 0;
    while(n[i] > 9) {
      int maxret = -INF;
      string nstr = to_string(n[i]);
      FOR(j, 1, nstr.size()) {
        string left = nstr.substr(0, j), right = nstr.substr(j);
        maxret = max(maxret, stoi(left) * stoi(right));
        //cout << left << " " << right << " " << maxret << endl;
      }
      n[i] = maxret;
      cnt++;
      //cout << "cnt:" << cnt << endl;
      if(cnt > 10000000) {cnt = -1; break;}
    }
    cout << cnt << endl;
  }

  return 0;
}

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

int main(){
  map<int,bool> h;
  int q,n,cnt;
  cin >> q;
  while(q--){
    cin >> n;
    cnt = 0;
    h.clear();
    for(;;){
      int m = -1, k = 10;
      if(h[n]){
	cout << -1 << endl;
	break;
      }
      h[n] = true;
      if(n<10){
	cout << cnt << endl;
	break;
      }
      for(int i=0;i<5;i++){
	m = max(m,(n/k)*(n%k));
	k *= 10;
      }
      n = m; cnt++;
    }
  }
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 100000000
using namespace std;
int cnt = 0;
int divide(string num){
  int result = 0;
  for(int i=1; i<num.size(); i++){
    int left = atoi(num.substr(0,i).c_str());
    int right = atoi(num.substr(i,num.size()-i).c_str());
    //cout << left << " " << right << endl;
    result = max(result,left*right);
    //cout << result << endl;
  }
  cnt++;
  if(result>=10) return divide(to_string(result));
  else if(cnt==INF) return -1;
  else return 1;
}
int main(){
  int n;
  cin >> n;
  string num;
  rep(i,n){
    cin >> num;
    cnt = 0;
    if(atoi(num.c_str()) <= 9) cout << 0 << endl;
    else if(divide(num) == 1) cout << cnt << endl;
    else cout << -1 << endl;
  }
  return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int res[1000001];

int calc(int A){
    string strA = to_string(A);
    if(strA.length() == 1) return A;
    int ret = 0;
    for(int i = 1; i < strA.length(); i++){
        string S = strA.substr(0, i);
        string T = strA.substr(i);
        ret = max(ret, stoi(S, nullptr, 10) * stoi(T, nullptr, 10));
    }
    return ret;
}

int calc2(int A){
    if(A <= 9) return A;
    int ret = 0;
    int md = 10;
    while(md <= A){
        int a = A % md;
        int b = A / md;
        ret = max(ret, a*b);
        md *= 10;
    }
    return ret;
}

int solve(int A){
    int temp = calc2(A);
    if(res[temp] != -1) return res[A] = res[temp] + 1;

    if(A == temp) return res[A] = 0;
    else return res[A] = solve(temp) + 1;
}

int main(void){
    rep(i, 1000001) res[i] = -1;
    
    for(int i = 0; i <= 1000000; i++){
        //if(i % 10000 == 0) cout << i << endl;
        if(res[i] == -1) solve(i);
    }
    vector<int> ans;
    int Q;cin >> Q;
    rep(i, Q){
        int a; cin >> a;
        ans.push_back(res[a]);
    }
    rep(i, ans.size()) cout << ans[i] << endl;
    
    return 0;
}

C++: #include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)

int inf=1000200000;

int max(int N){
	int max =0;
	for(int i=10; N/i>0;i=i*10){
		int kouho;
		kouho = (N/i)*(N-(N/i)*i);
		if(kouho>max){
			max = kouho;
		}
	}
	return max;
}


int main() {
	int Q;
	cin>>Q;
	Rep(i,Q){
		int N;
		cin>>N;
		int count = 0;
		rep(i,inf){
			if(N<=9){
				cout<<count<<endl;
				break;
			}
			else if(i >= inf-1){
				cout<<-1<<endl;
				break;
			}
			else{
				N =max(N);
				count++;
			}
		}
	}

	return 0;
}