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<cmath>
#define Number 1000001
using namespace std;

int getDigit(int num){
  int cnt=0;
  do{
    cnt++;
    num*=0.1;
  }while(num!=0);
  return cnt;
}

int getMax(int num){
  int digit=getDigit(num);
  int max=0;
  for(int i=1;i<digit;i++){
    int sp=pow(10,i);
    int l=num/sp;
    int r=num%sp;
    if(max < l*r) max = l*r;
  }
  return max;
}

int solve(int num){
  bool table[Number]={false};
  int cnt=0;
  if(num >= Number) return 0;
  table[num]=true;
  while(true){
    if(num < 10) return cnt;
    num=getMax(num);
    if(num >= Number) return 0;
    if(table[num]) return 0;
    else{
      cnt++;
      table[num]=true;
    }
  }

}

int main(){
  int n;
  cin>>n;
  while(n--){
    int q;
    cin>>q;
    cout<<solve(q)<<endl;
  }
  return 0;
}

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

string nxt(string s) {
    int ma = -1;
    for (int i = 1; i < s.length(); i++) {
        string s1 = s.substr(0, i);
        string s2 = s.substr(i);
        int mul = stoi(s1) * stoi(s2);
        ma = max(ma, mul);
    }
    return to_string(ma);
}

int solve(string s) {
    int cnt = 0;
    set<string> his;
    while (s.length() > 1) {
        cnt++;
        his.insert(s);
        s = nxt(s);
        if (his.count(s)) return -1;
    }
    return cnt;
}

int main() {
    int Q; cin >> Q;
    while (Q--) {
        string N; cin >> N;
        cout << solve(N) << endl;
    }
    return 0;
}

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

using namespace std;

vector<long long int> list,oddlist;
int listcnt, oddlistcnt;

int oddrec(int target, int sum, int cnt, int maxcnt) {
    int res=0xFFFF;
    if(maxcnt<cnt) return 0xFFFE;
    if(sum == target) return cnt;
    for(int i=oddlistcnt-1; 0<=i; i--) {
        if(sum+oddlist[i] > target) continue;
        res = min(res, oddrec(target, sum+oddlist[i], cnt+1, maxcnt));
        if(res==0xFFFE) break;
    }
    return res;
}

int ress;
void mama(int x){
    if(x==0) return;
    int tmp[oddlistcnt];
    memset(tmp,0,sizeof(tmp));
    for(int i=0;i<oddlistcnt;i++){
        tmp[i]=x/oddlist[i];
        if(tmp[i]==0) {
            ress+=tmp[i-1];
            mama(x%tmp[i-1]);
            break;
        }
    }
}


int main(void) {
    for(long long int i=1; i*(i+1)*(i+2)/6<1e6; i++) {
        list.push_back(i*(i+1)*(i+2)/6);
        if(i*(i+1)*(i+2)/6 % 2)
            oddlist.push_back(i*(i+1)*(i+2)/6);
    }


    listcnt = list.size();
    oddlistcnt = oddlist.size();
    while(true) {
        int n;
        scanf("%d",&n);
        if(!n) break;

        int res=5, oddres=1000;
        for(int i=listcnt-1; 0<=i; i--) {
            if(list[i]>n) continue;
            if(list[i]==n){ res=1; break; }
            if(res<=2) continue;
            for(int j=listcnt-1; 0<=j; j--) {
                if(list[i] + list[j]>n) continue;
                if(list[i] + list[j]==n) res=2;
                if(res<=3) continue;
                for(int k=listcnt-1; 0<=k; k--) {
                    if(list[i] + list[j] + list[k]>n) continue;
                    if(list[i] + list[j] + list[k]==n) res=3;
                    if(res<=4) continue;
                    for(int l=listcnt-1; 0<=l; l--) {
                        if(list[i] + list[j] + list[k] + list[l]>n) continue;
                        if(list[i] + list[j] + list[k] + list[l]==n) res=4;
                        if(res<=4) break;
                    }
                }
            }
        }

        if((oddres=oddrec(n, 0, 0, 1))>=0xFFFE) {
            for(int i=2; ; i=i*3/2) {
                if((oddres=oddrec(n, 0, 0, i))<0xFFFE)
                    break;
            }
        }

        printf("%d %d\n",res,oddres);
/*
        ress=0;
        mama(n);
        printf("%d %d\n",res,ress);*/
    }





    return 0;
}

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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

bool G[1000000];

int main() {
    int Q;
    cin >> Q;
    REP(_i, Q) {
        fill_n(G, 1000000, false);
        int n;
        cin >> n;
        int cnt = 0;
        while (n > 10) {
            G[n] = true;
            int m = 10;
            int ma = 0;
            int a, b;
            while ((a = n / m) != 0) {
                b = n % m;
                ma = max(ma, a*b);
                m *= 10;
            }
            cnt++;
            n = ma;
            if (G[n]) {
                cout << -1 << endl;
                goto END;
            }
            if (n < 10) break;
        }
        cout << cnt << endl;
END: {}
    }
}