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 <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int calc(string S, int s, int t) {
    int res = 0;
    FOR(i, s, t) {
        res *= 10;
        res += S[i] - '0';
    }
    return res;
}

void solve(int Q) {
    while (Q--) {
        int cnt = 0;
        string R; cin >> R;
        int num = atoi(R.c_str());
        for (;num >= 10; cnt++) {
            num = atoi(R.c_str());
            int newnum = 0;
            FOR(i, 1, R.length()) {
                int buf = calc(R, 0, i) * calc(R, i, R.length());
                ///DEBUG(buf)
                newnum = max(newnum, buf);
            }
            R = to_string(newnum);
            if (R.size() == 1) {
                cnt++;
                break;
            }
            if (newnum >= num) {
                cnt = -1;
                break;
            }
        }
        cout << cnt << endl;
    }
    return;
}

signed main(void) {
    int n, m, p, a, b, c, x, y, z, q;
    string s;
    bool f = false;
    while (cin >> n) {
        solve(n);
        return 0;
    }
}

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

int solve(int n){
  int res = 0;

  while(n >= 10){
    int maxVal = 0;

    for(int i = 10; i <= n; i *= 10){
      maxVal = max(maxVal, (n / i) * (n % i));
    }

    n = maxVal;
    res++;
  }

  return res;
}

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

  while(T--){
    int n;
    cin >> n;
    cout << solve(n) << endl;
  }
}

C++: #include<iostream>
#include<algorithm>
#include<set>
using namespace std;
int main()
{
	int q; cin>>q;
	while(q--) 
	{
		int n; cin>>n;
		//set<int> used;
		bool used[1000001];
		fill(used,used+1000001,0);
		int ans=0;
		//while(used.find(n)==used.end()&&9<n)
		while(!used[n]&&9<n)
		{
			int next=0,r=0;
			//used.insert(n);
			used[n]=true;
			int mul=1;
			while(1)
			{
				r+=n%10*mul;
				n/=10;
				mul*=10;
				if(n==0) break;
				next=max(next,r*n);
			}
			n=next;
			ans++;
		}
		if(n<=9) cout<<ans<<endl;
		else cout<<-1<<endl;
	}
  return 0;
}

C++: #include<iostream>
#include<cmath>
#include<set>

using namespace std;

int main(){

	long long Q,N,M;
	long long max;
	int cnt;
	set<long long> inf;

	cin>>Q;

	while(Q--){

		cin>>N;

		if(!inf.empty()) inf.clear();

		cnt=0;
		while(N/10!=0){
			M=0;
			max=-1;
			for(int i=0;N!=0;i++){
				M+=N%10*pow(10.0,i);
				N/=10;
				if(M*N>max) max=N*M;
			}
			if(inf.find(max)!=inf.end()){
				cnt=-1;
				break;
			}
			inf.insert(max);
			N=max;
			cnt++;
		}

		cout<<cnt<<endl;

	}
}