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

int power10[8];

int next(int n) {
	int ret = 0;
	for (int i = 1; i < 7; i++) {
		int a = n / power10[i];
		int b = n % power10[i];
		ret = max(ret, a * b);
	}
	return ret;
}

int main() {
	int q, n;
	
	power10[0] = 1;
	for (int i = 1; i < 8; i++) power10[i] = power10[i - 1] * 10;
	
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> n;
		for (int j = 0; ; j++) {
			if (n < 10) {
				cout << j << endl;
				break;
			}
			n = next(n);
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1e18
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
typedef pair<int, int> P;
const int mod = 1000000007;

int calc(int n){
    int res = 0;
    int m = 0, tmp = 1;
    while(n > 0){
        int x = n % 10;
        n /= 10;
        m = tmp * x + m;
        tmp *= 10;
        res = max(res, n * m);
    }
    return res;
}


signed main(){

    int q;
    cin >> q;
    while(q--){
        int n;
        cin >> n;
        int cnt = 0;
        while(n >= 10){
            n = calc(n);
            //cout << n << endl;
            cnt++;
        }
        cout << cnt << endl;
    }
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

#define LIMIT 1000000
int strtoi(string s){
    stringstream ss;
    int n;
    ss << s;
    ss >> n;
    return n;
}

string itos(int n){
    stringstream ss;
    string s;
    ss << n;
    ss >> s;
    return s;
}

int main(){
    int q;
    string s;
    cin >> q;
    for(int i=0;i<q;++i){
        int n, m;
        set<int> hist;
        int cnt=0;
        cin >> s;
        for(int k=0;;++k){
            vector<int> v;
            if(strtoi(s) < 10) break;
            for(int j=1;j<s.size();++j){
                n = strtoi(s.substr(0,j));
                m = strtoi(s.substr(j));
                v.push_back(n*m);
            }
            s = itos(*(max_element(v.begin(), v.end())));
            if(hist.find(strtoi(s))!=hist.end()||k>=LIMIT){
                cnt = -1;
                break;
            }
            hist.insert(strtoi(s));
            ++cnt;
        }
        cout << cnt << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
    unsigned long Q;
    cin >> Q;
    for(unsigned long iter = 0; iter < Q; ++iter){
        unsigned long N;
        cin >> N;
        unsigned long cnt{0};
        while(N > 9){
            unsigned long mx{0};
            for(unsigned long i = 10; i <= N; i *= 10)mx = max(mx, (N / i) * (N % i));
            ++cnt;
            N = mx;
        }
        cout << cnt << endl;
    }
}

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

using namespace std;

void solve()
{
	int Q;
	cin >> Q;
	while(Q--)
	{
		int N;
		cin >> N;
		int count = 0;
		set<int> isExist;
		while(true)
		{
			if(N < 10)
			{
				cout << count << endl;
				break;
			}
			int digit = 0;
			int NBuf = N;
			while(NBuf)
			{
				NBuf /= 10;
				++digit;
			}
			int max = 0;
			int a = 10;
			for(int i = 1; i < digit; ++i)
			{
				int left = N / a;
				int right = N % a;
				if(left * right > max)
				{
					max = left * right;
				}
				a *= 10;
			}
			if(isExist.find(max) == isExist.end())
			{
				isExist.insert(max);
			}
			else
			{
				cout << -1 << endl;
				break;
			}
			N = max;
			++count;
		}
	}
}

int main()
{
	solve();
	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 <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
const int DX[8]={-1,0,1,0,-1,-1,1,1},DY[8]={0,-1,0,1,-1,1,-1,1};


int main(){
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		ll n;
		cin>>n;
		int t=0;
		while(n>=10){
			auto s=to_string(n);
			ll mx=0,m=s.size();
			for(int i=1;i<m;i++){
				auto s1=s.substr(0,i),s2=s.substr(i,m-i);
				mx=max(mx,atoll(s1.c_str())*atoll(s2.c_str()));
			}
			n=mx;
			t++;
		}
		cout<<t<<endl;
	}
}