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 <map>
#include <set>
#include <list>
#include <cstdio>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define fr first
#define sc second
#define mp make_pair

typedef long long int64;
typedef pair< int, int > iP;
typedef pair< iP, int > iiP;

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

int main() {

    int Q;
    cin >> Q;
    while(Q--) {
        int cnt = 0;
        string R; cin >> R;
        string prev = R;
        while(true) {
            if(R.size() == 1 || !(~cnt)) break;
            int maxi = 0;
            for(int i = 1; i < R.size(); i++) {
                int f = atoi(R.substr(0, i).c_str()), s = atoi(R.substr(i, R.size() - i).c_str());
                maxi = max(maxi, f * s);
            }
            R = to_string(maxi);
            if(R == prev) cnt = -1;
            else cnt++;
        }
        cout << cnt << endl;
    }
}

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

using namespace std;

int main(){
	int q;
	cin >> q;
	for(int i=0;i<q;i++){
		int n;
		cin >> n;
		int c=0;
		while(n>=10){
			string s = to_string(n);
			n=0;
			for(int unsigned j = 1;j<s.size();j++){
				n = max(n,stoi(s.substr(0,j))*stoi(s.substr(j)));
			}
			c++;
		}
		cout << c << endl;
	}
	return 0;
}

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

int main() {
  int q;
  cin >> q;
  while(q--) {
    string s;
    cin >> s;
    int size = s.size();
    int res, ans = 0;
    bool f = true;
    set<int> set1;
    set1.insert(atoi(s.c_str()));
    while(size > 1) {
      res = 0;
      for(int i=0; i<size-1; i++) {
	string a = s.substr(0, i+1);
	string b = s.substr(i+1);
	res = max(atoi(a.c_str())*atoi(b.c_str()), res);
      }
      if(set1.count(res)) { f = false; break; }
      set1.insert(res);
      stringstream ss; ss << res; s = ss.str();
      size = s.size();
      ans ++;
    }
    cout << ( f ? ans : -1 ) << endl;
  }
  
  return 0;
}

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

int max(int a,int b){
	if(a>=b)return a;
	else return b;
}

int main(){

	int q;
	int ten[7]={10,100,1000,10000,100000,1000000};

	while(cin>>q){

		int cnt=0;

		for(int l = 0;l<q;l++){
			int r;
			cin>>r;
			cnt=0;
			while(1){
				if(r<10){
					cout<<cnt<<endl;
					break;
				}
				else{
					int length=0;
					for(int i=0;i<7;i++){
						if(ten[i]>=r){
							length = i;
						break;
						}
					}
		
					int next=0;
		
					for(int i=0;i<=length;i++){
		
						int a,b;
						a = r % ten[i];
						b = r / ten[i];

					//	cout<<"a="<<a<<"b="<<b<<endl;
		
						next = max(next,a*b);		

					}
					//cout<<next<<endl;	
					r = next;
					cnt++;
				}
			}
		}

		break;
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    bool used[1000010]={};
    int n;cin>>n;
    used[n]=true;
    bool flag=true;
    int cnt=0;
    while(n>=10){
      int a=n;
      int keta=0;
      while(a>0){a/=10;keta++;}
      int kake=10;
      int ma=-1;
      for(int i=1;i<keta;i++){
	if(n%kake<kake/10){kake*=10;continue;}
	ma=max(ma,(n/kake)*(n%kake));
	kake*=10;
      }
      n=ma;
      cnt++;
      if(used[ma]){cout<<-1<<endl;flag=false;break;}
    }
    if(flag)cout<<cnt<<endl;
  }
  return 0;
}

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

using namespace std;
#define int long long
bool used[2000000];

int f(int n){

   fill((bool*)used, (bool*)used+2000000, 0);
   used[n]=1;
   int cnt=0;
   while(n>=10){
      string s=to_string(n);
      int nex=0;
      for(int i=1; i<s.size(); i++){

         nex=max<int>(nex, stoll(s.substr(0, i))*stoll(s.substr(i)));
      }
      if(used[nex]) return -1;
      used[nex]=1;
      n=nex; cnt++;
   }

   return cnt;
}

signed main(){

   int Q;
   cin>> Q;
   for(int i=0; i<Q; i++){
      int N;
      cin>> N;
      cout<< f(N)<< 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;
    }
}