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 range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    int q;
    cin >> q;
    rep (i, q) {
        string n;
        cin >> n;

        map <string, bool> strToBool;
        strToBool[n] = true;

        int cnt = 0;

        while(n.size() != 1) {

            int max_index = -1,
                max_num = -1;

            range (j, 1, n.size()) {
                string pre = "",
                       sub = "";

                rep (k, j) pre += n[k];
                range (k, j, n.size()) sub += n[k];

                if (max_num < stoi(pre.c_str()) * stoi(sub.c_str())) {
                    max_num = stoi(pre.c_str()) * stoi(sub.c_str());
                    max_index = j;
                }
            }

            string pre = "",
                   sub = "";

            rep (j, max_index) pre += n[j];
            range (j, max_index, n.size()) sub += n[j];

            n = to_string(stoi(pre.c_str()) * stoi(sub.c_str()));
            cnt++;

            if (strToBool[n]) {
                cnt = -1;
                break;
            }
        }

        cout << cnt << endl;
    }

    return 0;
}

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

int size (int n) {
    int s = 0;
    for (int j = 0;; j++) {
        if (n == 0) {
            s = 1;
            break;
        }
        else if ((pow(10, j)) <= n and n < (pow(10, j + 1))) {
            s++;
            break;
        }
        else s++;
    }
    return s;
}

int main () {
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int n;
        cin >> n;
        int res = 0;
        while (size(n) != 1) {
            vector<int> v;
            for (int j = 1; j < size(n); j++) {
                int a, b;
                a = n % int(pow(10, j));
                b = n / int(pow(10, j));
                v.push_back(a * b);
            }
            n = *max_element(v.begin(), v.end());
            res++;
        }
        cout << res << endl;
    }
}

C++: #include <iostream>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <numeric>
#include <bitset>
#include <stack>
#include <cstring>
using namespace std;

const int INF = 1 << 30;
const double EPS = 1e-10;

int main()
{
  int Q;
  while (cin >> Q) {
    while (Q--) {
      long long R;
      cin >> R;
      
      int ans = 0;
      set<long long> visited;
      while (R/10 > 0 && visited.find(R) == visited.end()) {
        visited.insert(R);

        long long next = -1;
        for (int i = 10; R/i > 0; i *= 10) {
          long long a = R / i;
          long long b = R % i;
          next = max(next, a*b);
        }
        R = next;
        ++ans;
      }

      if (visited.find(R) != visited.end())
        ans = -1;
      cout << ans << endl;
    }
  }
  return 0;
}

C++: #include <stdio.h>
#include <set>
#include <math.h>
#include <algorithm>
using namespace std;

int maxNum(int N){
  int maxInt=0,i=1,a,b;
  int lenN=(int)log10(N)+1;
  while (i<lenN){
    a=N/(int)pow(10.0,(double)lenN-i);
    b=N%(int)pow(10.0,(double)lenN-i);
    maxInt=max(maxInt,a*b);
    i++;
  }
  return maxInt;
}

int main(){
  int Q,cnt,N;
  set<int> S;
  scanf("%d",&Q);
  for (int i=0;i<Q;i++){
    scanf("%d",&N);
    cnt=0;
    while (true){
      set<int>::iterator iti=S.find(N);
      if (N<10){
        printf("%d\n",cnt);
        break;
      }else if (iti!=S.end()){
        printf("-1\n");
        break;
      }else{
        S.insert(N);
        N=maxNum(N);
        cnt++;
      }
    }
  }
  return 0;
}

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

int main(){
  int q;
  cin>>q;
  for(int x=0;x<q;x++){
    int n;
    cin>>n;
    int ans=0;
    while(n/10>0){
      int nn=0;
      string s=to_string(n);
      for(int i=1;i<s.size();i++){
        string a,b;
        for(int j=0;j<i;j++)a.push_back(s[j]);
        for(int j=i;j<s.size();j++)b.push_back(s[j]);
        nn=max(nn,stoi(a)*stoi(b));
        n=nn;
      }
      ans++;
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<algorithm>

using namespace std;

int dfs(int n){
	if(n<10) return 0;
	int res=0,a,ten=1;
	for(a=n%10,n/=10;n>0;ten*=10,a+=n%10*ten,n/=10) res=max(res,a*n);
	return dfs(res)+1;
}

int main(){
	int q; scanf("%d",&q);
	while(q--){ int n; scanf("%d",&n); printf("%d\n",dfs(n)); }
	return 0;
}

C++: #include <iostream>
#include <cassert>
#define REP(i,l,n) for(int i=l;i<n;++i)
#define rep(i,n) REP(i,0,n)
int ans;
int Q,n;
using namespace std;
int main() {
  cin >> Q;
  rep(i,Q){
    cin >> n;
    ans = 0;
    while(n > 9){
      ans++;
      int max = 0,div = 1;
      rep(j,5){
        div *= 10;
        int post = (n/div)*(n%div);
        if(post>max) max = post;
      }
      n = max;
    }
    cout << ans << endl;
  }
  return 0;
}

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

int step(int n){
  int digit=1,tmp;
  tmp=n;
  int res=0;
  while((tmp=tmp / 10)>0)digit++;
  for(int i=1;i<digit;i++){
    int first,latter;
    first=n/(int)pow(10,i);
    latter=n%(int)pow(10,i);
    res=max(res,first*latter);
  }
  return res;
}

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