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>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
int calc(int x) {
  string s = to_string(x);
  int ans = 0;
  for (int i = 1; i < s.length(); i++) {
    int a = stoi(s.substr(0, i));
    int b = stoi(s.substr(i));
    ans = max(ans, a*b);
  }
  return ans;
}

signed main() {
  int Q; cin >> Q;
  for (int i = 0; i < Q; i++) {
    int N; cin >> N;
    int ans = 0;
    while (N >= 10) {
      N = calc(N);

      ans++;
      if (ans > 100100) break;
    }
    if (N < 10) {
      cout << ans << endl;
    } else {
      cout << -1 << endl;
    }
  }
}

C++: #include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int q;
    scanf("%d",&q);
    while(q--){
        bool memo[1000001];
        fill(memo,memo+1000001,false);
        int n;
        scanf("%d",&n);
        for(int i=0;true;i++){
            if(n/10==0){
                printf("%d\n",i);
                break;
            }
            int ma=0;
            for(int j=10;n/j;j*=10){
                int v1=n/j,v2=n%j;
                ma=max(ma,v1*v2);
            }
            if(memo[ma]){
                puts("-1");
                break;
            }
            memo[ma]=true;
            n=ma;
        }
    }
    return 0;
}

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

string str;
int cnt;
int inf;

string solve(string x){
  int ret = INT_MIN;
  string a;
  string ans;

  if(x.size() == 1) return x;
  if(inf <= atoi(x.c_str()) && cnt != 0){
    cnt = -1;
    return 0;
  }
  for(int i = 0; i < (int)str.size(); i++){
    string b;
    a+=x[i];
    for(int j = i+1; j < (int)str.size(); j++){
      b += x[j];
    }
    int c = atoi(a.c_str())*atoi(b.c_str());
    if(ret < c){
      ret = max(ret,c);
    }
  }
  stringstream s;
  s << ret;
  s >> ans;
  cnt++;
  return solve(ans);

}

int main(){
  int q;
  cin >> q;
  string ans;

  for(int i = 0; i < q; i++){
    cnt = 0;
    cin >> str;
    inf = atoi(str.c_str());
    solve(str);
    cout << cnt << endl;
  }


}

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


using namespace std;

int main()
{
  int q;
  cin >> q;
  while(1){
	if (q <= 0) break;
	int n ;
	cin >> n;
	int count = 0;
	string hoge;
	hoge = to_string(n);
	while(1){
	  int max = 0;
	  int l = hoge.length();
	  if(l <= 1) break;
	  int i;
	  
	  for (i = 1; i < l; i++) {
		string a,b;
		int c,d;
		a = hoge.substr(0,i);
		b = hoge.substr(i);
		// cout << a << endl;
		// cout << b << endl;
		c = stoi(a);
		d = stoi(b);
		if(max < c * d) max  = c * d;
		// cout << max << endl;	
	  }
	  
	  count++;
	  if(max >= 10) hoge = to_string(max);
	  else break;
	}
	cout << count << endl;
	q--;
  }  
  return 0;
}

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

int q;
std::string str, b, e;

int solve(int m) {
	int cnt = 0;
	while (1) {
		str = std::to_string(m);
		if (str.size() == 1)
			break;
		b.clear();
		e = str;
		int l, r, max = 0;
		for (int i = 0; i < str.size() - 1; ++i) {
			b += str[i];
			e.erase(e.begin());
			l = std::stoi(b);
			r = std::stoi(e);
			max = std::max(max, l*r);
			m = max;
		}
		++cnt;
	}
	return cnt;
}

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

C++: #include<iostream>
#include<math.h>
using namespace std;

int ans(int n){
	if(n/10==0)return 0;
	int ma=0;
	for(int i=0;i<=6;i++){
		int tmp=pow(10,i);
		ma=max(ma,(n/tmp)*(n%tmp));
	}
	return ans(ma)+1;
}

int main(){
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		int n;
		cin>>n;
		cout<<ans(n)<<endl;
	}
}

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

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
using namespace std;

int main(){
  int q;
  scanf("%d", &q);
  while(q--){
    int n, i = 0;
    vector<int>v;
    scanf("%d", &n);
    v.push_back(n);
    while(n/10){
      int lerge = 0, split = 10;
      while(n / split){
	lerge = max(lerge, (n / split) * (n % split));
	split*=10;
      }
      n = lerge;
      if(find(v.begin(), v.end(), n) != v.end()){
	i = -1;
	break;
      }
      v.push_back(n);
      i++;
    }
    printf("%d\n", i);
  }
  return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>
#include <complex>

#define INF 100000000
#define EPS 1e-9

using namespace std;

typedef long long ll;

vector<int> ans_list;

int dp[10000000];

int main(){

	int Q;
	cin >> Q;

	memset(dp, 0, sizeof(dp));

	while (Q){
		Q--;
		int N;
		cin >> N;
		int ans = 0;
		while (N/10 > 0){
			if (dp[N] != 0){
				N = dp[N];
				continue;
			}
			int tmp = 0;
			for (int i = 1; N/pow(10,i) > 0; i++){
				tmp = max(tmp, (N / (int)pow(10, i)) * (N % (int)pow(10, i)) );
			}
			dp[N] = tmp;
			N = tmp;
			ans++;
		}

		ans_list.push_back(ans);

	}
	
	for (int i = 0; i < ans_list.size(); i++){
		cout << ans_list[i] << endl;
	}

	return 0;

}