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 conv(string s){
    int res=0;
    for(int i=0;i<(int )s.length();i++){
        res*=10;
        res+=(s[i]-'0');
    }
    return res;
}

int solve(string s){
    string s2=s;
    int res=0;
    int val=conv(s);
    set<int> st;
    while(val>=10){
        int ma=-1;
        for(int i=1;i<(int )s2.length();i++){
            string a=s2.substr(0,i),b=s2.substr(i);
            int v1=conv(a),v2=conv(b);
            ma=max(ma,v1*v2);
        }
        //cout<<ma<<endl;
        if(st.find(ma)!=st.end()){
            res=-1;
            break;
        }
        st.insert(ma);
        val=ma;
        s2=to_string(ma);
        res++;
    }
    return res;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int q;cin>>q;
  for(int i=0;i<q;i++){
      string n;cin>>n;
      cout<<solve(n)<<endl;
  }
  return 0;
}

C++: #include <string>
#include <cstdio>
#include <cstdlib>
char S[9];main(){int q,n,r,i;std::string s;for(scanf("%d",&q);q--;printf("%d\n",r))for(r=0,scanf("%d",&n);n>9;r++)for(sprintf(S,"%d",n),s=S,n=0,i=1;i<s.length();i++)n=std::max(n,atoi(s.substr(0,i).c_str())*atoi(s.substr(i).c_str()));}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define INF 1010001000
#define EPS 1e-10
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef pair<int, int> i_i;
typedef long long int llong;
typedef pair<llong, llong> ll_ll;
typedef struct edge {int f, t;}Edge;

int q;

int main()
{
    cin >> q;
    rep(lp, q) {
        int n, cnt = 0;
        cin >> n;
        char data[20] = "";
        sprintf(data, "%d", n);
        while (strlen(data) != 1 && cnt < 101000) {
            int len = strlen(data), ret = -1;
            for (int i = 1; i < len; i++) {
                int a = atoi(data);
                a /= pow(10, (len - i));
                int b = atoi(&data[i]);
                ret = max(ret, a*b);
            }
            sprintf(data, "%d", ret);
            cnt++;
        }
        if (cnt < 101000) {
            cout << cnt << endl;
        } else {
            cout << -1 << endl;
        }
    }

    return 0;
}