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 <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int Q;
string s;

int main() {
  cin>>Q;
  REP(i,0,Q){
    cin>>s;
    int ans = 0;
    set<string> se;
    while(1){
      if(se.find(s)!=se.end()){
        cout<<-1<<endl;
        break;
      }
      se.insert(s);
      if(s.size()==1){
        cout<<ans<<endl;
        break;
      }
      ans++;
      int m = 0;
      REP(pos,1,s.size()){
        string left = s.substr(0,pos);
        string right = s.substr(pos,s.size()-pos);
        m = max(m, stoi(left)*stoi(right));
      }
      s = to_string(m);
    }
  }

  return 0;
}

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

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n;
	cin >> n;
	while (n) {
		n--;
		string s;
		cin >> s;
		int cnt = 0;
		while (s.length() > 1) {
			cnt++;
			int ma = 0;
			REP(i, s.length() - 1) {
				int val1 = stoi(s.substr(0,i+1).c_str());
				int val2 = stoi(s.substr(i + 1,s.length()-(i+1) ).c_str());
				ma = max(ma, val1*val2);
			}
			s = to_string(ma);
		}
		cout << cnt << endl;
	}
}

C++: #include <stdio.h>
#include <math.h>
#include <vector>

//FILE *in = freopen("2424.txt", "r", stdin);
//FILE * out = freopen("outputA.txt", "w", stdout);


int main()
{
	int n, count, cut;
	int num, front, back, max, now;
	std::vector<int> prev;

	//while (scanf("%d", &n) > 0){
		scanf("%d", &n);
		for(int i = 0; i < n; i++){
			scanf("%d", &num);
			max = 0;
			count = 0;
			if(num < 10)
			{
				printf("%d\n", count);
				continue;
			}
			while(num >= 10){
				count++;
				back = 0;
				cut = 0;
				max = 0;
				int a = 1;
				while((front = num / 10) > 0){
					back += (num%10)*a;
					now = back * front;
					if(max < now)
						max = now;
					num/=10;
					a *= 10;
				}
				num = max;
				if(prev.size() != 0){
					for(int i = 0; i < prev.size(); i++)
						if(num == prev.at(i))
						{
							count = -1;
							goto out;
						}
				}
				prev.push_back(num);

			}
			out:
			printf("%d\n", count);
			prev.clear();
		}
	//}
	return 0;
}

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<stdio.h>
#include<math.h>
int ketasuu(int n){
    for(int i=6;i>=0;i--){
        if((int)n/pow(10,i)>=1) return i+1;
    }
    return -1;
}
int divide(int n,int m){
    return (int)(n/pow(10,m+1))*(int)(n%(int)pow(10,m+1));
}
int main(){
    int q;
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        int count=0,newn,n;
        scanf("%d",&n);
        while(ketasuu(n)>=2){
            newn=0;
            int l=ketasuu(n);
            for(int j=0;j<l-1;j++){
                if(newn<divide(n,j)) newn=divide(n,j);
            }
            n=newn;
            count++;
        }
        printf("%d\n",count);
    }
}