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;

int stoi(string& s){
	int ret=0;
	for(unsigned int i=0;i<s.length();++i){
		ret+=s[i]-'0';
		ret*=10;
	}
	return ret/=10;
}

int stoi(string& s,int a , int b){
	string tmp=s.substr(a , b);
	return stoi(tmp);
}

int stoi(string&s , int n){
	string tmp=s.substr(0,n);
	return stoi(tmp);
}



int main(){
	int q;
	cin >> q;
	for(int i=0;i<q;++i){
		int cnt=0;
		string s;
		int org;
		cin >> s;
		org=stoi(s);
		int mul1,mul2;
		bool b=true;
		while(s.size()!=1){
			int mx=0;
			for(unsigned int j=1;j<s.size();++j){
			mul1=stoi(s,j);
			mul2=stoi(s,j,s.size()-j);
			mx=max(mx,mul1*mul2);
			}
			if(mx==org){
				b=false;
				break;
			}
			s=to_string(mx);
			cnt++;
		}
		cout << (b ?cnt:-1) << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int num,cnt=0;
    cin>>num;
    while(1){
      int max=0;
      if(num/10==0)break;
      for(int j=10;num/j>0;j*=10){
        int a=num/j,b=num%j;
        if(a*b>max)max=a*b;
      }
      num=max;
      cnt++;
    }
    cout<<cnt<<endl;
  }
  return 0;
}

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

int main(){
	int q,n,count,a,b,res;
	string s,s1,s2;

	cin >> q;
	for(int i = 0;i < q;i++){
		cin >> n;
		count = 0;
		while(1){
			res = 0;
			if(n/10 == 0)break;
			s = to_string(n);
			for(int j = 1;j < s.size();j++){
				s1.assign(s,0,j);
				s2.assign(s,j,s.size()-j);
				a = stoi(s1);
				b = stoi(s2);
				res = max(res,a*b);
			}
			n = res;
			count++;
		}
		cout << count << endl;
	}

	return 0;
}

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

using namespace std;

vector<int> ans;
int main(){
	int q;
	cin >> q;
	
	for(int i = 0;i < q;i++){
		int n;
		cin >> n;
		int tans = 0;
		vector<int> used;
		while(n >= 10){
			int div = 10;
			int next = 0;
			for(int i = 0;i < 6;i++){
				int l = n/div;
				int r = n%div;
				if(l != 0){
					next = max(next,l*r);
				}
			}
			if(find(used.begin(),used.end(),next) != used.end()){
				tans = -1;
				break;
			}
			used.push_back(next);
			n = next;
			tans++;
		}
		ans.push_back(tans);
	}
	
	for(int i = 0;i < ans.size();i++) cout << ans[i] << endl;
	return 0;
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int q;
	scanf("%d",&q);
	rep(tt,q){
		int n,cnt=0;
		scanf("%d",&n);
		while(true){
			int d[7]={},tmp=n,i,mx=-1;
			for(i=0;tmp>0;i++){
				d[i]=tmp%10;
				tmp/=10;
			}
			if(i<=1) break;
			for(int j=1;j<i;j++){
				int l=0,r=0;
				rep(k,j) l=10*l+d[j-1-k];
				rep(k,i-j) r=10*r+d[i-1-k];
				mx=max(mx,l*r);
			}
			n=mx;
			cnt++;
		}
		printf("%d\n",cnt);
	}
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double PI = 3.14159265358979;
const double E = 2.718281828459045;
const double root2 = sqrt(2);
typedef pair<int, int> P;
typedef unsigned int ui;
string tra(string x) {
	int len = x.length();
	int ma = 0;
	for (int i = 1; i < len; i++) {
		string u = x.substr(0, i);
		string v = x.substr(i, len - i);
		int sum = stoi(u)*stoi(v);
		ma = max(ma, sum);
	}
	return to_string(ma);
}
int main() {
	int q; cin >> q;
	string n; int cnt;
	for (int i = 0; i < q; i++) {
		cin >> n;
		for (cnt = 0; cnt < 100000; cnt++) {
			if (n.length()==1)break;
			n = tra(n);
		}
		if (cnt == 100000)cout << -1 << endl;
		else cout << cnt << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<math.h>
using namespace std;
int tejun(int inp,int r);

int main(){
  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int num;
    cin >> num;
    int r=0;
    r = tejun(num,r);
    cout << r << endl;
  }
}

int tejun(int inp,int r){
  if(inp>9){
    int max=0;
    for(int j=1;pow(10,j)<inp;j++){
      int kake=(inp/(int)pow(10,j))*(inp%(int)pow(10,j));
      if(kake>max){
	max=kake;
      }
    }
    return tejun(max,r+1);
  }
  return r;
}

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

int main(){
  int len,n,num1,num2,max,suji,temp,cnt2=1,result;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> suji;
    temp = suji;
    len = cnt2;
      int cnt = 0;
      // cout << "len" << len << endl;
     while(suji >= 10){
       max = -1;
       cnt2 = 1;
       while(temp > 0){
	 cnt2++;
	 temp/=10;
       }
       len = cnt2;
       int waru_num = 1;
      for(int j = 1; j < len; j++){
	waru_num *= 10;
	//cout << "waru_num" << waru_num << endl;
	num1 = suji / waru_num;
	//cout << "num1 " << num1 << endl;
	num2 = suji % waru_num;
	//cout << "num2 " << num2 << endl;
	result = num1 * num2;
	if(max < result){
	  max = result;
	  //cout << "max" << max << endl;
	}
      }
      suji = max;
      temp = suji;
      cnt++;
    }
     if(cnt > 10000000)cout << "-1" << endl;
     else cout << cnt << endl;
       
     }
    
  return 0;
}

C++: #include<iostream>
#include<string>
#include<math.h>
using namespace std;
int main(){
	int n,s;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s;
		int count=0;
		while(true){
			if(s/10==0)
				break;
			int best=0,check=10;
			for(int j=1;j<6;j++){
				if((s/check)*(s%check)>best)
					best=(s/check)*(s%check);
				check*=10;
			}
			s=best;
			count++;
		}
		cout<<count<<endl;
	}
	return 0;
}