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 <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int mx(int n){
    string s = to_string(n);
    int m = s.size();
    string t,u;
    int ret = 0;
    REP(i,1,m){
        t = s.substr(0,i);
        u = s.substr(i);
        chmax(ret, stoi(t)*stoi(u));
    }
    return ret;
}

int main(){
    int q; cin >> q;
    while(q--){
        int n; cin >> n;
        int ans = 0;
        while(n >= 10){
            ans++;
            ll t = mx(n);
            n = t;
        }
        cout << ans << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

int main(void){
    int p;
    cin>>p;
    rep(lp,p){
        string n;cin>>n;
        int ans=0;
        while(n.length()!=1){
            int mx=-1;
            range(i,1,n.length()){
                string a=n.substr(0,i);
                string b=n.substr(i);
                mx=max(mx,stoi(a)*stoi(b));
            }
            n=to_string(mx);
            ans++;
        }
        cout<<ans<<endl;
    }
}

C++: #include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int q;
	cin >> q;
	REP(i, q) {
		int n;
		cin >> n;
		int cnt = 0;
		while (n>=10) {
			ll cmax = -1, res = 1;
			int a=n;
			while (a > 0) {
				res *= 10;
				a /= 10;
			}
			res /= 10;


			REP(j, log10(n)-1) {
				cmax = max(cmax, (n / res)*(n%res));
				res /= 10;
			}
			cnt++;

			if (cmax == n) {
				cnt = -1;
				break;
			}
			n = cmax;
		}
		cout << cnt << endl;
	}
	return 0;
}

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

string To_string(int i) {
    stringstream ss;
    ss << i;
    return ss.str();
}

int GetDigit(int num) {
    return To_string(num).length();
}


int Q;

int main() {
    cin >> Q;
    for(int i=0; i<Q; ++i) {
        int n;
        cin >> n;
        int digit = GetDigit(n); 
        int count = 0; 
        while(1) {
            int max = 0;
            if(n >= 0 && n <= 9) {
                cout << count << endl;
                break;
            } else {
                for(int j=1; j<=digit-1; ++j) {
                    int op1 = n / int(pow(10,j));
                    int op2 = n % int(pow(10,j));
                    //cout << "op1: " << op1 << ", op2: " << op2 << endl;
                    if(op1*op2 > max) { max = op1*op2; }
                    //cout << "max at loop" << j << ": " << max << endl;
                }
                ++count;
                //cout << "max: " << max << ", count: " << count << endl;
                
                if(max >= 0 && max <= 9) {
                    cout << count << endl;
                    break;
                } else if(count > 100) {
                    cout << "-1" << endl;
                    break;
                } else {
                    n = max;
                }
            }
        }
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int q,n;
  cin>>q;
  while(q--){
    cin>>n;
    int c=0;
    while(n/10&&c<1000000){
      c++;
      int a=-1;
      for(int i=10;i<n;i*=10)a=max(a,(n/i)*(n%i));
      n=a;
    }
    if(c==1000000)cout<<-1<<endl;
    else cout<<c<<endl;
  }
  return 0;
}