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;

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

int f(int n, int cnt) {
	string s = to_string(n);
	if (s.size() == 1)return cnt;
	int ret = 0;
	rep(i, 1, s.size()) {
		string a = s.substr(0, i), b = s.substr(i);
		dump(a);
		dump(b);
		ret = max(ret, stoi(a)*stoi(b));
	}
	return f(ret, cnt + 1);
}

signed main() {
	int Q; cin >> Q;
	vector<int> N(Q); rep(i, 0, Q) { cin >> N[i]; }
	rep(i, 0, Q) {
		cout << f(N[i], 0) << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<fstream>
#include<string>

#define fin cin

using namespace std;

int search(int num){
    if(num < 10)return 0;

    auto log = 10;
    auto v = 0;
    while(log < num)
    {
        auto tmp = (num % 10) * (num / 10);
        v = max(tmp, v);
        log *= 10;
    }

    return 1 + search(v);

}


int main(){
   // ifstream fin("in.txt");

    auto n = 0;
    fin >> n;

    for(auto i = 0; i < n; i++){
        auto num = 0;
        fin >> num;
        cout << search(num) << endl;
    }

    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
using namespace std; 

// #define int long long // debug
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef map<int, int> Mii;
typedef vector<int> Vi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;



int main()
{
	int n;
	cin >> n;
	rep(i,0,n) {
		int t;
		cin >> t;
		int cnt = 0;
		bool f = true;
		while (f && t>=10) {
			Vi q;
			f = false;
			for (int i=1; t/i; i*=10) {
				int a = t/i;
				int b = t%i;
				q.pb(a*b);
			}
			sort(all(q));
			//debug(q[len(q)-1]);
			if (len(q) && q[len(q)-1] >= 10) f = true;
			cnt++;
			t = q[len(q)-1];
		}
		cout << cnt << endl;
	}

	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 
#include <sstream>
#include <algorithm>
#include <cstdlib>
 
using namespace std;
 
int func(string str, int cnt);
 
string InToString(int number);
 
int main()
{
    int Q, ans;
    string str;
    cin >> Q;
    for(int i = 0; i < Q; i++){
        cin >> str;
        ans = func(str, 0);
        cout << ans << endl;
        }
    return 0;
}
 
int func(string str, int cnt)
{
    int l = (int)str.size();
    if(l < 2) return cnt;
    else {
        string a, b;
        int c, d, e;
        int max = 0;
        for(int j = 1; j < l; j++){
            a = str.substr(0, j);
            b = str.substr(j, l-j);
            c = stoi(a);
            d = stoi(b);
            e = c * d;
            if(e > max) max = e;
        }
        cnt++;
        return func(InToString(max), cnt);
    }
}
 
string InToString(int number)
{
    stringstream ss;
    ss << number;
    return ss.str();
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int p(int r) {
	int ans = -1;
	for (int i = 10; i <= r; i *= 10) {
		ans = max(ans, ((r - r % i) / i)*(r % i));
	}
	return ans;
}
int main() {
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		int k; cin >> k;
		int cnt = 0;
		while (k >= 10) { k = p(k); cnt++; }
		cout << cnt << endl;
	}
}

C++: #include <iostream>
#include <string>
#include <cmath>
#include <sstream>

using namespace std;

long long int keisan(string a, string b) {
	long long int aa, bb;
	stringstream ss;
	ss << a;
	ss >> aa;
	ss.clear();
	ss << b;
	ss >> bb;
	//cout << aa << ' ' << bb << ' ' << aa*bb << endl;
	return aa*bb;
}

string kaiseki(string a) {
	long long int count = 0;
	for (int i = 1; i < a.size(); i++) {
		count = max(count, keisan(a.substr(0, i), a.substr(i)));
	}
	//cout << count << endl;
	string b;
	stringstream ss;
	ss << count;
	ss >> b;
	return b;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string a;
		cin >> a;
		int count = 0;
		while (a.size() != 1) {
			a = kaiseki(a);
			//cout << a << endl;
			count++;
		}
		cout << count << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
  int Q;
  cin >> Q;
  while(Q--){
    int N;
    cin >> N;
    for(int i = 0; i <= 1000000; i++){
      if(N / 10 == 0){
	cout << i << endl;
	break;
      } else if(i == 1000000){
	cout << -1 << endl;
	break;
      }
      int fore, back;
      int next = -1;
      for(int j = 10; j <= N; j *= 10){
	fore = N / j;
	back = N % j;
	next = max(next, fore*back);
      }
      N = next;
    }
  }
  return 0;
}