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>
using namespace std;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int q;
bool vis[1111111];

int dfs(int n,int d){
	if(n<10)return d;
	if(vis[n])return -1;
	vis[n]=true;
	string s=to_string(n);
	int res=0;
	rep(i,s.length()-1){
		maxch(res,stoi(s.substr(0,i+1))*stoi(s.substr(i+1,s.length()-i-1)));
	}
	return dfs(res,d+1);
}

int main(){
	cin.sync_with_stdio(false);
	cin>>q;
	rep(i,q){
		int n;
		cin>>n;
		memset(vis,0,sizeof(vis));
		cout<<dfs(n,0)<<endl;
	}
	return 0;
}

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

int size (int n) {
    int s = 0;
    for (int j = 0;; j++) {
        if (n == 0) {
            s = 1;
            break;
        }
        else if ((pow(10, j)) <= n and n < (pow(10, j + 1))) {
            s++;
            break;
        }
        else s++;
    }
    return s;
}

int main () {
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int n;
        cin >> n;
        int res = 0;
        while (size(n) != 1) {
            vector<int> v;
            for (int j = 1; j < size(n); j++) {
                int a, b;
                a = n % int(pow(10, j));
                b = n / int(pow(10, j));
                v.push_back(a * b);
            }
            n = *max_element(v.begin(), v.end());
            res++;
        }
        cout << res << endl;
    }
}

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

int c;

int seisu_1(int n){
    if(0<=n && n<10) return c;
    else{    
    int nmax=(n/10)*(n%10), m;
    for(int j=10; j<=n; j*=10){
        m = (n/j)*(n%j);
        if(nmax<m)  nmax = m;
    }
    c++;
    return seisu_1(nmax);
    }
}


int main(void){
    int Q, n;
    cin >> Q;
    for(int i=1; i<=Q; i++){
        c = 0;
        cin >> n;
        cout << seisu_1(n) << endl;
    }
    
    return 0;
}

C++: #include <stdio.h>
#define max(a,b) a > b ? a : b

int main(void){
	int max, t, i, k, n, count, m;
	scanf("%d",&m);
	for(k = 0;k < m;k++){
		scanf("%d",&n);
		count = 0;
		while(n / 10){
			max = 0x80000000;
			for(i = 10;n / i != 0;i*=10){
				t = (n / i) * (n - (n / i) * i);
				max = max(t,max);
			}
			n = max;
			count++;
		}
		printf("%d\n",count);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
void calc() {
    string s; cin >> s;
    int max = 0;
    int cnt = 0;
    while (1) {
        if (s.size() == 1) {
            cout << cnt << endl;
            return;
        }
        cnt++;
        if (cnt == 1e9) {
            cout << -1 << endl;
            return;
        }
        for (int i = 1; i < s.size(); ++i) {
            int a = stoi(s.substr(0, i));
            int b = stoi(s.substr(i, s.size() - i));
            //cout << a * b << endl;
            max = max > a * b ? max : a * b;
        }
        s = to_string(max);
        max = 0;
        //cout << "s " << s << endl;
    }
}
int main() {
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        calc();
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int Q;
    cin >> Q;
    for(int q=0; q<Q; q++){
        int N;
        cin >> N;
        int cnt = 0;
        while(N >= 10){
            string S = to_string(N);
            int mx = 0;
            for(int i=1; i<S.size(); i++){
                int temp = stoi(S.substr(0,i)) * stoi(S.substr(i));
                chmax(mx,temp);
            }
            N = mx;
            // cout << N << enld;
            cnt++;
        }
        cout << cnt << enld;
    }
    return 0;
}