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 <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cmath>
#include <time.h>
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) ((c).rbegin(),(c).rend())
//#define sort(v,n) sort(v,v+n)
#define ll long long
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int q;

inline int digit(ll a) {
	int now = 0;
	while (a > 0) {
		a /= 10;
		now++;
	}
	return now;
}

inline int buunnkatsu(ll a) {
	ll res=-inf;
	int b[7];
	for (int i = 0; i < 7; i++)b[i] = 0;
	int n = digit(a);
	for (int i = n-1; i >=0; i--) {
		b[i] = (a % 10);
		a /= 10;
	}
	ll c=0, d=0;
	for (int i = 0; i < n; i++) {
		c = 0;
		d = 0;
		for (int j = 0; j <= i; j++) {
			c *= 10;
			c += b[j];
		}
		for (int j = i + 1; j < n; j++) {
			d *= 10;
			d += b[j];
		}
		//cout <<"i="<<i<< "c=" << c << "d=" << d << endl;
		res = max(res, c*d);
	}
	//cout <<"res="<< res << endl;
	return res;
}

int main() {
	cin >> q;
	for (int i = 0; i < q; i++) {
		ll a; int cont = 0;
		cin >> a;
		while (1) {
			if (cont > 100000) {
				break;
			}
			if (digit(a) > 1) {
				a = buunnkatsu(a);
			}
			else {
				break;
			}
			cont++;
		}
		if (cont > 100000)cout << -1 << endl;
		else
		cout << cont << endl;
	}
}

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

using std::cin;
using std::cout;
using std::endl;

int digit(int n, int d) {
	int m = (int)(n/pow(10,d)) * pow(10,d);
	return (n - m)/pow(10,d-1);
}

int check_digit(int n) {
	for (int i = 7; i > 0; i--) {
		if (digit(n, i) > 0) {
			return i;
		}
	}
	return 1;
}

int pri_num(int n, int p) {
	return (int)(n/pow(10,p));
}

int pos_num(int n, int p) {
	int ret = 0;
	for (int i = 1; i < p+1; i++) {
		ret += digit(n, i) * pow(10, i-1);
	}
	return ret;
}

bool check_vec(std::vector<int> v, int n) {
	for (std::vector<int>::iterator itr = v.begin(); itr != v.end(); ++itr) {
		if (*itr == n) {
			return true;
		}
	}
	return false;
}


int main(void) {
	int N;
	cin >> N;

	for (int t = 0; t < N; t++) {
		int R;
		cin >> R;

		std::vector<int> pro;
		int count = 0;
		int d = check_digit(R);
		while ( (d != 1) && (!(check_vec(pro,R))) ) {
			int pri,pos;
			int max_pro = 0;
			pro.push_back(R);
			for (int i = 1; i < d; i++) {
				pri = pri_num(R,i);
				pos = pos_num(R,i);
				if (max_pro < pri*pos) {
					max_pro = pri * pos;
				}
			}
			R = max_pro;
			d = check_digit(R);
			count++;
		}
		if (check_vec(pro,R)) {
			cout << -1 << endl;
		}
		else {
			cout << count << endl;
		}
	}

	return 0;
}

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

int next_n(int n) {
  int maximum = -1;
  for (int p = 1; pow(10, p) < n; p++) {
    int base = pow(10, p),
        right = n % base,
        left = (n - right) / base;
    maximum = max(maximum, right * left);
  }
  return maximum;
}

int main() {
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int N;
    cin >> N;

    int count = 0;
    while (N > 9) {
      N = next_n(N);
      count++;
    }
    cout << count << endl;
  }
}

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

int main() {

  int Q;
  cin >> Q;
  while(Q--) {
    string s;
    cin >> s;
    int cnt = 0;
    while(s.size() > 1) {
      int maxi = 0;
      for(int i = 1; i < s.size(); i++) {
        string left = s.substr(0, i), right = s.substr(i, s.size() - i);
        //cout << left << " " << right << endl;
        maxi = max(maxi, atoi(left.c_str()) * atoi(right.c_str()));
      }
      s = to_string(maxi);
      cnt++;
    }
    cout << cnt << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
	int q, n;
	cin >> q;
	for(int i = 0; i < q; ++i){
		cin >> n;
		int cnt = 0;
		while(cnt < 1000){
			if(n <= 9)
				break;
			string base = to_string(n);
			int next = 0;
			for(int i = 1; i < base.size(); ++i){
				string t = base;
				int l = stoi(t.substr(0, i));
				int r = stoi(t.substr(i, t.size() - i));
				next = max(next, l * r);
			}
			n = next;
			cnt++;
		}
		if(cnt >= 1000)
			cout << "-1" << endl;
		else
			cout << cnt << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int memo[1000001];
int calc(int n) {
    if(memo[n]!=-1) return memo[n];
    if(n<10) return 0;
    string s=to_string(n);
    int to=0;
    for(int i=1;i<=s.size()-1;i++) {
        to=max(to,stoi(s.substr(0,i))*stoi(s.substr(i)));
    }
    return memo[n]=calc(to)+1;
}
int main() {
    int Q,N;
    scanf("%d",&Q);
    memset(memo,-1,sizeof(memo));
    for(int i=0;i<Q;i++) {
        scanf("%d",&N);
        printf("%d\n",calc(N));
    }
}