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 <iostream>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
  int q;
  cin >> q;
  for(int i=0; i<q; i++){
    int n;
    cin >> n;
    int count=0;
    set<int> memo;
    memo.insert(n);
    bool bloop = false;
    while(n > 9){
      int next = 0;
      for(int j=10; j<n; j*=10){
        int a = n/j;
        int b = n%j;
        next = max(next,a*b);
      }
      if(!memo.insert(next).second){
        bloop = true;
        break;
      }
      n = next;
      count++;
    }
    if(bloop) cout << -1 << endl;
    else cout << count << endl;
  }
  return 0;
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	int Q;
	cin >> Q;
	
	REP(i, Q) {
		int N;
		cin >> N;

		int cnt = 0;
		while(N/10) {
			string str = toString(N);
			int tmp, max = 0;
			int size = str.size()-1;
			FOR(j, 1, size) {
				tmp = toInt(str.substr(0, j)) * toInt(str.substr(j));
				if(tmp > max) {
					max = tmp;
				}
			}
			N = max;
			cnt++;
		}

		cout << cnt << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30

using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;

    rep(q,n) {

        string s;
        cin >> s;

        int ans = 0;

        while(s.size() != 1) {
            int res = -INF;
            rep(i,s.size()) {
                if(i == 0) continue;
                
                stringstream ss;
                rep(j,i) ss << s[j];

                int a;
                ss >> a;

                stringstream ss2;
                REP(j,i,s.size()) ss2 << s[j];

                int b;
                ss2 >> b;

                // cout << a << " " << b << endl;

                if(res < a*b) {
                    res = a*b;
                }
            }

            stringstream ret;
            ret << res;
            s = ret.str();
            ans++;
        }

        cout << ans << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);

    int Q;
    cin >> Q;
    
    for(int i = 0; i<Q; i++){
        string suji;
        cin >> suji;
        
        int len = suji.length();
        int cnt = 0;
        while(std::stoi(suji) >= 10)
        for(int j = 1; j<len; j++){
            int num1;
            int num2;
            int tot;
            num1 = std::stoi(suji.substr(0, j));
            num2 = std::stoi(suji.substr(j, len-1));
            cnt ++;
            tot = num1 + num2;
            suji = std::to_string(tot);
        }
        cout << cnt << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int DivideMul(int N,int a){
  int L=N%(int)pow(10,a);
  int U=(N-L)/pow(10,a);
  return L*U;
}

int Next(int N){
  int n=0;
  double s=log(N)/log(10);
  for(int i=1;i<s;++i){
      n=max(n,DivideMul(N,i));
  }
  return n;
}


int main(){
  int T;
  cin >> T;
  for(int i=0; i<T; ++i){
    
    int N;
    cin >> N;
    if(N==0){
      cout << 0;
      break;
    }

    int j=0;
    for( j=0; N>9 ; ++j){
      N=Next(N);
      //cout <<N<<endl;
    }
   
    cout << j << endl;;
  }
}

C++: #include<stdio.h>

int main(){

int n;

scanf("%d",&n);if(n==0)break;
int x;
for(int i=0;i<n;i++)
{scanf("%d",&x);
int c=0;int d=10;int w=0,y=0;int max=0;
while(x/10!=0){
for(int j=0;j<6;j++)
{
w=x/d;y=x%d;d*=10;
if(j==0)max=w*y;
else if(w*y>max)max=w*y;}
x=max;c++;d=10;}
printf("%d\n",c);
}}
return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<string>
#include<sstream>
#include<algorithm>
using namespace std;
int Solve(int n)
{
	if(n<10)
		return 0;
	stringstream ss;
	ss<<n;
	string s=ss.str();
	int t=0;
	for(int i=1;i<s.size();++i)
		t=max(t,atoi(s.substr(0,i).c_str())*atoi(s.substr(i).c_str()));
	return 1+Solve(t);
}

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