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>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for(int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for(ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

int q;

int main() {
	std::cin >> q;
	rep(i, q) {
		int n;
		std::cin >> n;
		int cnt = 0;
		while (true) {
			int max = 0;
			std::string str = std::to_string(n);
			if (str.size() == 1)break;
			REP(i, 1, str.size()) {
				max = std::max(max, std::atoi(str.substr(0, i).c_str()) * std::atoi(str.substr(i, str.size() - i).c_str()));
			}
			n = max;
			cnt++;
		}
		std::cout << cnt << std::endl;
	}

	return 0;
}

C++: 
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stdlib.h>

using namespace std;

unsigned long long int power(unsigned long long int x, unsigned long long int n) {
	if(n == 0) return 1;
	if(n == 1) return x;
	if(x == 0) return 0;
	if(n % 2 == 1) {
		unsigned long long int y;
		y = power(x, (n - 1) / 2);
		return x*y*y;
	} else {
		unsigned long long int y;
		y = power(x, n / 2) ;
		return y*y;
	}
	return -1;
}

int main(void){
//	FILE* fp_in = freopen("data.txt", "r", stdin);

	int Q;
	cin >> Q;
	vector<int> N;
	vector<int> ans;
	for(int i = 0; i < Q; i++) {
		unsigned long long int n_i;
		unsigned long long int p;
		int ans = 0;
		cin >> n_i;
		p = n_i;

		while( p > 9 ) {

			stringstream ss;
			ss << p;
			int max = 0;

			for(int i = 1; i < ss.str().length() ; i++) {
				unsigned long long int tmp;
				unsigned long long int div1, div2;
				tmp = power(10, i);
				div1 = p / tmp;
				div2 = p % tmp;
//				cout << div1 << ":" << div2 << "@" << div1*div2 << endl;
				if(div1 * div2 >= max) {
					max = div1 * div2;
				}
			}
			ans ++;
			p = max;
			if( p > n_i ) {
				ans = -1;
				p = -1;
			}

		}
		cout << ans << endl;
	}


	
//	while(1){}
	return 0;
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;
bool v[1000001];
int d[7];
int main(){
	int a;
	scanf("%d",&a);
	while(a--){
		for(int i=0;i<1000001;i++)v[i]=0;
		int ret=0;
		int b;
		scanf("%d",&b);
		while(1){
			v[b]=true;
			if(b<10)break;
			int c=b;
			int i=0;
			while(c){
				d[i++]=c%10;
				c/=10;
			}
			int to=0;
			for(int j=0;j<i-1;j++){
				int e=0;
				int f=0;
				for(int k=j;k>=0;k--){
					e*=10;
					e+=d[k];
				}
				for(int k=i-1;k>j;k--){
					f*=10;
					f+=d[k];
				}
				to=max(to,e*f);
			}
			if(v[to]){
				ret=-1;
				break;
			}
			b=to;
			ret++;
		}
		printf("%d\n",ret);
	}
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int multi_max(int n)
{
	int k = 10;
	int maxi=0;
	while(n/k > 0){
		maxi = max(maxi, (n/k)*(n-n/k*k));
		k *= 10;
	}
	return maxi;
}

int main(void)
{
	int q;
	cin >> q;
	while(q--){
		int n, ans=0;
		cin >> n;
		while(n >= 10){
			n = multi_max(n);
			ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n,m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

int main()
{
	cin >> n;
	vi v(n);
	REP(i, n) cin >> v[i];
	REP(i, n)
	{
		cnt = 0;
		while (v[i] > 9) {
			ans = 0;
			ll digit = log10(v[i]);
			REP(j, digit)
			{
				ll b = pow(10, j + 1);
				ll a = (v[i] / b)*(v[i] % b);
				ans = max(ans, a);
			}
			cnt++;
			v[i] = ans;
		}
		cout << cnt << endl;
	}
}

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

int max(int a,int b){
	if(a>=b)return a;
	else return b;
}

int main(){

	int q;
	int ten[7]={10,100,1000,10000,100000,1000000};

	while(cin>>q){

		int cnt=0;

		for(int l = 0;l<q;l++){
			int r;
			cin>>r;
			cnt=0;
			while(1){
				if(r<10){
					cout<<cnt<<endl;
					break;
				}
				else{
					int length=0;
					for(int i=0;i<7;i++){
						if(ten[i]>=q){
							length = i;
						break;
						}
					}
		
					int next=0;
		
					for(int i=0;i<=length;i++){
		
						int a,b;
						a = r % ten[i];
						b = r / ten[i];
		
						next = max(next,a*b);		

					}
	
					r = next;
					cnt++;
				}
			}
		}

		break;
	}

	return 0;
}