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;

int solve(int N, int cnt) {
    if (N < 10) return cnt;
    cnt++;
    if (cnt == 10000000) return -1;
    int syou, amari;
    int mn = -1;
    for (int i = 10; i < 10000000; i *= 10) {
        syou = N / i;
        if (!syou) break;
        amari = N % i;
        mn    = max(mn, syou * amari);
    }
    cnt = solve(mn, cnt);
    return cnt;
}

int main() {
    int Q;
    cin >> Q;
    int N;
    vector<int> ans;
    for (int i = 0; i < Q; i++) {
        cin >> N;
        int cnt = 0;
        ans.push_back(solve(N, cnt));
    }
    for (int i : ans) cout << i << endl;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    int res = 0;
    while (n >= 10) {
      auto s = to_string(n);
      int m = s.size(), mx = -1;
      for (int i = 1; i < m; ++i) {
        mx = max(mx, stoi(s.substr(0, i)) * stoi(s.substr(i)));
      }
      n = mx;
      ++res;
    }
    cout << res << '\n';
  }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
void Change(string,int);
string Change2(int);
int cal1,cal2,len;
int main(){
  int Q,Max,cal,i,j,k,cnt;
  string N;
  cin >> Q;
  for(i=0;i<Q;i++){
    cnt=0;
    cin >> N;
    while(1){
      Max=0; 
      len=N.size();
      if(len==1) break;
      for(j=1;j<len;j++){
	cal1=cal2=0;
	Change(N,j);
	cal=cal1*cal2;
	Max=max(cal,Max);
	if(Max==0){
	  cnt++;
	  break;
	}
      }
      if(Max==0) break;
      N=Change2(Max);
      cnt++;
      if(cnt==100000000) break;
    }
    if(cnt==100000000) cout << -1 << endl;
    else cout << cnt << endl;
  }
  return 0;
}
void Change(string N,int s){
  int x=1,i,cnt;
  i=0;
  cnt=s;
  while(cnt){
    cal1=cal1*x+(N[i]-'0');
    x=10;
    i++;
    cnt--;
  }
  x=1;
  i=s;
  cnt=len-s;
  while(cnt){
    cal2=cal2*x+(N[i]-'0');
    x=10;
    i++;
    cnt--;
  }
}
string Change2(int n){
  string retstr;
  int l=0,cp=n,i;
  while(cp){
    cp/=10;
    l++;
  }
  for(i=0;i<l;i++){
    retstr+=n%10+'0';
    n/=10;
  }
  reverse(retstr.begin(),retstr.end());
  return retstr;
}

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

int solve(int n) {
    int c = 0;
    set<int> vis;
    while (n >= 10 && vis.count(n) == 0) {
        vis.insert(n);
        int nx = 0, d = 10;
        while (d <= n) {
            nx = max(nx, (n%d)*(n/d));
            d *= 10;
        }
        n = nx;
        c++;
    }
    if (n < 10) return c;
    return -1;
}

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

C++: #include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                                                  it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))

typedef long long ll;
typedef complex<double> point;

// up right down left
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};

const double EPS = 1e-9;
const int days[]     = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

int main(){
    int Q;
    cin >> Q;
    rep(i,Q){
        ll N;
        cin >> N;
        int R=0;
        set<ll> S;
        S.insert(N);
        bool ok = true;
        while(N >= 10){
            stringstream ss;
            ss << N;
            string s;
            ss >> s;
            ll maxi = -1;
            for(int i=1;i<s.length();i++){
                string front = s.substr(0,i);
                string back = s.substr(i);
                ll ifront,iback;
                stringstream ss;
                ss << front;
                ss >> ifront;
                ss.clear();
                ss << back;
                ss >> iback;
                maxi = max(maxi,ifront*iback);
            }
            N = maxi;
            R++;
            if(!S.insert(N).second){
                ok = false;
                break;
            }
        }
        if(ok){
            cout << R << endl;
        }else{
            cout << -1 << endl;
        }
    }
    return 0;
}

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

int q, r, ten, ma, cnt;

int main() {
  cin >> q;
  for(int a = 0; a < q; ++a) {
    map<int, bool> mp;
    cin >> r;
    cnt = 0;
    while(r >= 10) {
      ma = 0;
      ten = 10;
      while(r / ten > 0) {
        if(ma < (r / ten) * (r % ten)) ma = (r / ten) * (r % ten);
        ten *= 10;
      }
      if(mp.find(ma) != mp.end()) {
        cnt = -1;
        break;
      }
      mp[ma] = 1;
      r = ma;
      ++cnt;
    }
    cout << cnt << endl;
  }
  return 0;
}