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 REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

//-----------------------------------------------------------------------
int calc(int a){
    string s=to_string(a);
    int res=0;
    for(int i=1;i<s.size();i++){
        int t=stoi(s.substr(0,i))*stoi(s.substr(i));
        res=max(res,t);
    }
    return res;
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin>>n;
    REP(i,n){
        int a; cin>>a;
        int cnt=0;
        while(10<=a){
            a=calc(a);
            cnt++;
        }
        cout<<cnt<<endl;
    }
}

C++: #include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int n;
void solve(){
  int i=0;
  for(;n/10>0;i++){
    int s=n,n_=0;
    for(int j=10;;j*=10){
      int u=s/j;
      if(u==0)break;
      int l=s%j;
      n_=max(n_,u*l);
    }
    n=n_;
  }
  cout<<i<<endl;
}

int main(){ _;
  int q;cin>>q;
  REP(i,q){
    cin>>n;
    solve();
  }
}

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

#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main()
{
    int q;
    cin >> q;
    loop(q,i) {
        int n;
        cin >> n;
        int org = n;
        int ans = 0;
        while (n > 10) {
            string s = to_string(n);
            int m = 0;
            loop(s.size()-1, j) {
                int f = stoi(s.substr(0,j+1));
                int l = stoi(s.substr(j+1));
                //cout << j << ':' << f << ' ' << l << " = " <<  f*l << endl;
                m = max(m, f*l);
            }
            n = m;
            if (n == org) {
                ans = -1;
                break;
            }
            //cout << '=' << n << endl;
            ans++;
        }
        cout << ans << endl;
    }
}

C++: #include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int q;
    scanf("%d", &q);
    while(q--){
        string n;
        cin >> n;
        set<string> S;
        int cnt = 0;
        while(n.size() > 1){
            if(S.find(n) != S.end()){
                cnt = -1;
                break;
            }
            S.insert(n);
            int tmp = 0;
            For(i, 1, n.size()){
                chmax(tmp, stoi(n.substr(0, i)) * stoi(n.substr(i)));
            }
            ++cnt;
            n = to_string(tmp);
        }
        printf("%d\n", cnt);
    }
}

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

int Q,N,s,m,i;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> Q;
    for (;Q--;){
        cin >> N;
        for(i=0;N>10;++i){
            s=10,m=0;
            while(s<N){
                m=max(m,(N/s)*(N%s));
                s*=10;
            }
            N=m;
        }
        cout << i << '\n';
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int Q;
    cin >> Q;
    rep(_, Q) {
        int n;
        cin >> n;
        int ans = 0;
        while (n >= 10) {
            int D = log10(n);
            int ma = -1;
            while (D > 0) {
                int l = n / pow(10, D);
                int r = n % (int)pow(10, D);
                ma = max(ma, l * r);
                D--;
            }
            n = ma;
            ans++;
        }
        cout << ans << endl;
    }

}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main() {
	int q; scanf("%d", &q);
	rep(i, q) {
		int n; scanf("%d", &n);
		map<int, bool>mp;
		for (int cnt = 0;; cnt++) {
			if (n < 10) {
				printf("%d\n", cnt);
				break;
			}
			mp[n] = true;
			int Max = 0;
			string s = to_string(n);
			for (int i = 1; i < s.size(); i++) {
				string s1, s2;
				rep(j, i)s1 += s[j];
				for (int j = i; j < s.size(); j++)s2 += s[j];
				Max = max(Max, stoi(s1)*stoi(s2));
			}
			if (mp[Max]) {
				puts("-1");
				break;
			}
			n = Max;
		}
	}
}