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 <map>
#include <set>
#include <list>
#include <cstdio>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define fr first
#define sc second
#define mp make_pair

typedef long long int64;
typedef pair< int, int > iP;
typedef pair< iP, int > iiP;

const int INF = 2 << 28;
const double EPS = 1e-10;

int main() {

    int Q;
    cin >> Q;
    while(Q--) {
        int cnt = 0;
        string R; cin >> R;
        string prev = R;
        while(true) {
            if(R.size() == 1 || !(~cnt)) break;
            int maxi = 0;
            for(int i = 1; i < R.size(); i++) {
                int f = atoi(R.substr(0, i).c_str()), s = atoi(R.substr(i, R.size() - i).c_str());
                maxi = max(maxi, f * s);
            }
            R = to_string(maxi);
            if(R == prev) cnt = -1;
            else cnt++;
        }
        cout << cnt << endl;
    }
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>

using namespace std;

const int INF = (1<<30) - 1;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int Q; cin >> Q;
    while(Q--){
        int R; cin >> R;
        int ans = 0;
        while(R >= 10){
            int next = 0;
            for(int x=10; x<=R; x*=10){
                next = max(next, (R/x) * (R%x));
            }
            R = next;
            ans++;
        }
        cout << ans << endl;
    }
    
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;

int main(void) {
  int q, n;
  cin >> q;
  for(int i=0; i<q; i++){
    cin >> n;
    int cnt = 0;
    while( n >= 10 ){
      int tmp = -1;
      string ns = to_string(n);
      for(int i=0; i<ns.size()-1; i++){
        cerr << ns.substr(0, i+1) << " " << ns.substr(i+1) << endl;
        tmp = max(tmp, stoi(ns.substr(0, i+1)) * stoi(ns.substr(i+1)) );
      }
      // cerr << tmp << endl;
      n = tmp;
      cnt++;
    }
    cout << cnt << endl;
  }

  return 0;
}

// EOF

C++: #include <iostream>
#include <algorithm>
#include <sstream>
using namespace std;
int memo[1000001];
string tostr(int x){
  stringstream ss;
  ss << x;
  string s;
  ss >> s;
  return s;
}
int toint(string s){
  int x;
  stringstream ss;
  ss << s;
  ss >> x;
  return x;
}

int solve(int n){
  if(n<10) return 0;
  if(memo[n]) return memo[n];
  string s = tostr(n);
  int nxt = -1;
  for(int i=1;i<=s.length()-1;++i){
    string a = s.substr(0,i);
    string b = s.substr(i,s.length()-i);
    nxt = max(nxt,toint(a)*toint(b));
  }
  return memo[n]=solve(nxt)+1;
}
int main(){
  int q;
  cin >> q;
  while(q--){
    int n;
    cin >> n;
    cout << solve(n) << endl;
  }
  return 0;
}

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

using namespace std;

int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

int main(void)
{
	int q;
	cin >> q;
	while (q--){
		int n;
		cin >> n;
		
		int cnt = 0;
		while (cnt < 50000){
			string str = toString(n);
			if (str.length() == 1) break;
			long long maxnum = 0;
			for (int i = 1; i < str.length(); i++){
				int a = toInt(str.substr(0, i)), b = toInt(str.substr(i));
				maxnum = max(maxnum, (long long)a * b);
				// cout << a << " " << b << endl;
			}
			n = maxnum;
			cnt++;
		}
		if (cnt == 50000) cout << -1 << endl;
		else cout << cnt << endl;
	}

	return 0;
}

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

using namespace std;

int main()
{
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int n;
        cin >> n;

        int count = 0;
        auto process = [](int n) {
            auto s = to_string(n);
            if (s.size() == 1) {
                return n;
            }
            int max_ = 0;
            for (int j = 0; j < s.size() - 1; ++j) {
                auto l = stoi(s.substr(0, j + 1));
                auto r = stoi(s.substr(j + 1));
                max_ = max(max_, l * r);
            }
            return max_;
        };
        while (true) {
            if (0 <= n && n <= 9) {
                break;
            }
            n = process(n);
            count += 1;
        }
        cout << count << endl;
    }
}

C++: #include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int Q, N;

int next(int x) {
    string s = to_string(x);
    int res = 0;
    for (int i = 1; i < s.size(); ++i) {
        int a = stoll(s.substr(0, i));
        int b = stoll(s.substr(i, s.size() - i));
        res = max(res, a * b);
    }
    return res;
}

void solve() {
    cin >> N;
    set<int> st;
    int ans = 0;
    while (N >= 10) {
        if (st.count(N)) {
            ans = -1;
            break;
        }
        st.insert(N);
        N = next(N);
        ans++;
    }
    cout << ans << endl;
}

void _main() {
    cin >> Q;
    REP (i, Q) solve();
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}