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

int main(void){
  int n;
  string num;
  cin >> n;
  for(int i = 0; i < n; i++){
    int cnt = 0;
    cin >> num;
    while(num.size() > 1){
      int maxn = 0;
      for(int i = 0; i < num.size() - 1; i++){
        string op1(num, i + 1, num.size() - i), op2(num, 0, i + 1);
        int n = stoi(op1) * stoi(op2);
        if(n > maxn) maxn = n;
      }
      num = to_string(maxn);
      cnt++;
      if(cnt > 1000000) break;
    }
    if(cnt <= 1000000) cout << cnt << endl;
    else cout << -1 << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int maxi(int n)
{
    if (n <= 9) return (0);
    
    int b = 1;
    int c = 0;
    int ma = 0;
    while (n > 9){
        c += (n % 10) * b;
        b *= 10;
        n /= 10;
        ma = max(ma, n * c);
    }
    
    return (maxi(ma) + 1);
}

int main()
{
    int Q;
    
    scanf("%d", &Q);
    
    while (Q--){
        int n;
        
        scanf("%d", &n);
        
        printf("%d\n", maxi(n));
    }
    
    return (0);
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	int q,n,ans=0,cnt=0;
	VI N;

	cin >> q;
	
	for(int i=0;i<q;i++){
		cin >> n;
		N.PB(n);
	}

	for(int j=0;j<q;j++){
		while(1){
			if(N[j]<10){
				break;
			}
			double k=1.0;
			while(1){
				int b=(int)pow(10.0,k);
				if((N[j]/b)==0){
					break;
				}
				ans=max(ans,((N[j]/b) * (N[j]%b)));
				k++;
			}
			cnt++;
			N[j]=ans;
			ans=0;
		}
		cout << cnt << endl;
		cnt=0;
	}
	return 0;
}

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

map<int, int> mem;

int main()
{
  int Q, n;
  cin >> Q;
  for(int q = 0; q < Q; q++)
  {
    cin >> n;
    int m = 0;
    while(n >= 10)
    {
      m++;
      mem[n] = 1;
      int tmp = 0;
      for(int j = 10; ; j *= 10)
      {
        int a, b;
        a = n / j;
        b = n % j;
        if(!a)
          break;
        tmp = max(tmp, a * b);
      }
      n = tmp;
      if(mem.count(n))
      {
        cout << -1 << endl; 
        goto end;
      }
    }
    cout << m << endl;
end:;
  }
}

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;


string toStr(int n){
    string str;
    if(n == 0) return "0";
    int len = static_cast<int>(log10(n));
    int K = 1;
    rep(i,len) K*=10;
    rep(i,len + 1){
        if(n / K == 0) str+= '0';
        else str+= ('0' + n / K);
        n%=K; K/=10;
    }
    return str;
}

int toNum(string str){
    int num = 0, K = 1;
    for(int i = str.size() - 1; i >= 0; i--){
        num+=(str[i] - '0') * K;
        K*=10;
    }
    return num;
}

int kakezan(string a, string b){
    return toNum(a) * toNum(b);
}

int main(){
    int n;
    cin >> n;
    rep(i,n){
        int maxi;
        int k = 0;
        string s;
        cin >> s;
        while(k != 1000000){
            maxi = 0;
            if(s.size() == 1) break;
            range(j,1,s.size()){
                maxi = max(maxi, kakezan(s.substr(0,j), s.substr(j, s.size()  - j)));
            }
            s = toStr(maxi);
            k++;
        }
        if(k == 1000000) cout << -1 << endl;
        else cout << k << endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<algorithm>
#include<complex>
#include<cstdlib>
#include<cctype>

#define REP(i,n) for(int i = 0;i < (n);i++)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cout << v[i] << ' ';cout << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cout << v[a][b] << ' ';cout << endl;}cout << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

ll function(ll n)
{
	string str;
	
	while(n > 0)
	{
		str.PB('0' + n%10);
		n /= 10;
	}
//	cout << str << endl;
	reverse(ALL(str));
//	cout << str << endl;
	int cou = str.size();
	int ret = 0;
	for(int i = 1;i < cou;i++)
	{
		int tmp1 = atoi(str.substr(0,i).c_str());
		int tmp2 = atoi(str.substr(i,str.size()-1).c_str());
		ret = max(ret,tmp1*tmp2);
//		cout << tmp1 << ' ' << tmp2 << endl;
	}
	
	return ret;
}

int main()
{
	int qq;
	cin >> qq;
	
	REP(aaa,qq)
	{
		ll n;
		cin >> n;
		int _out = 0;
		while(n >= 10 && _out < 1000000)
		{
			n = function(n);
			_out++;
		}
		
		if(_out < 1000000)
			cout << _out << endl;
		else
			cout << -1 << endl;
		
	}
	
	return 0;
}