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 <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
	for(int q;cin>>q;) while(q--){
		string n; cin>>n;
		int i;
		for(i=0;n.size()>1;i++){
			int x=-1;
			for(int k=1;k<n.size();k++)
				x=max(x,atoi(n.substr(0,k).c_str())*atoi(n.substr(k).c_str()));
			char buf[9]; sprintf(buf,"%d",x);
			n=buf;
		}
		cout<<i<<endl;
	}
	
	return 0;
}

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

using namespace std;

int main(void)
{
	int q;
	int n;
	string s;
	string temp1,temp2;
	int num1,num2;
	int i1,i2;
	int max;
	int count;
	int check;

	cin >> q;

	for(i1=0;i1<q;i1++){
		cin >> n;

		vector<string> v;
		count = 0;
		check = 0;
		

		while(1){
			if(n/10==0) {
				check=1;
				break;
			}
			
			ostringstream ostr;
			ostr << n;
			s = ostr.str();

			if(!v.empty()){
				if(find(v.begin(), v.end(),s)!=v.end()) {
					check=8;
					break;
				}
			}

			v.push_back(s);
			max = 0;

			for(i2=1;i2<s.size();i2++){
				temp1 = s.substr(0,i2);
				temp2 = s.substr(i2);

				istringstream istr1(temp1);
				istr1 >> num1;
				istringstream istr2(temp2);
				istr2 >> num2;

				if(max<(num1*num2)) max = num1*num2;
			}

			n=max;
			count++;

		}

		if(check==8) cout << -1 << endl;
		else cout << count << endl;
	}
	return 0;
}

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

using namespace std;

inline int nextInt() { int d; cin >> d; return d; }

bool isUsed[(int)1e6 + 1];

int getNext(int n) {
  int ret = -1;
  for (int d = 10; d < n; d *= 10) {
    int n1 = n % d;
    int n2 = (n - n1) / d;
    ret = max(ret, n1 * n2);
  }

  return ret;
}

int solve(int n) {
  int step = 0;
  memset(isUsed, false, (int)1e6 + 1);
  while (true) {
    if (n < 10) {
      return step;
    }
    if (isUsed[n]) {
      return -1;
    }
    isUsed[n] = true;
    n = getNext(n);
    step++;
  }
  return 0;
}

int main() {
  int Q = nextInt();

  for (int i = 0; i < Q; i++) {
    int R = nextInt();
    int ans = solve(R);
    cout << ans << endl;
  }

  return 0;
}

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

long kakezan(long a){
	int d=0, num[7];
	long t=a;
	
	while(t>0){
		++d;
		t/=10; 
	}
	//printf("d=%d\n", d);
	t=a;
	for(int i=0; i<d; ++i){
		num[d-i-1]=t%10;
		t/=10;	
	}
	/*	
	for(int i=0; i<d; ++i)
		printf("num[%d]=%d\n", i,num[i]);
	*/
	long ret=0;
	
	for(int i=1; i<d; ++i){ //分割位置
		long x=0, y=0;
		
		for(int j=0; j<i; ++j){
			x += num[j]*pow(10, i-j-1);	
		}
		
		for(int j=i; j<d; ++j){
			y += num[j]*pow(10, d-1-j);	
		}
		
		if(ret<x*y) ret=x*y;
	} 
	
	return ret;
}

int main(){
	int q;	
	long lim=10000000;
	
	scanf(" %d", &q);
	for(int i=0; i<q; ++i){
		long n, count=0;
		scanf(" %ld", &n);
		
		while(n>9 && count<lim){
			n=kakezan(n);
			++count;
			//printf(" %ld\n", n);
		}	
		
		if(count==lim) printf("-1\n");
		else printf("%ld\n", count);
	}
	
	return 0;
}

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

int step(int n){
  int digit=1,tmp;
  tmp=n;
  int res=0;
  while((tmp=tmp / 10)>0)digit++;
  for(int i=1;i<digit;i++){
    int first,latter;
    first=n/(int)pow(10,i);
    latter=n%(int)pow(10,i);
    res=max(res,first*latter);
  }
  return res;
}

int main(){
  int q,n;
  cin>>q;
  for(int i=0;i<q;i++){
    int ans=0,prev=n;
    cin>>n;
    while(n>9){
      prev=n;
      n=step(n);
      if(n==prev){
	cout << -1 << endl;
	break;
      }
      ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<algorithm>

using namespace std;
typedef long long int lli;

lli tejun2(int s) {
    lli res=0;
    
    for(lli i=1; i<1e7; i*=10)
        res = max(res, (s%i)*(s/i));
    return res;
}

int main(void) {
    int q;
    scanf("%d", &q);
    for(int i=0; i<q; i++) {
        int n;
        scanf("%d", &n);

        set<lli> hist;
        lli last=n;
        for(int i=0; i<100000; i++) {
            if(last/10 == 0) {
                printf("%d\n", i);
                break;
            }
            if(hist.find((last = tejun2(last))) == hist.end()) {
                hist.insert(last);
            }
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

int Q, N, logn, r, l, turn;

int main(){
	cin >> Q;
	for (int i = 0; i < Q; i++){
		cin >> N;
		logn = int(log10(N)) + 1; //N????????°?????????
		if (logn == 1) cout << 0 << endl;
		else{
			turn = 0;
			while (logn != 1){
				int max = 0;
				for (int j = 0; j < logn - 1; j++){
					r = N % int(pow(10, j + 1)+0.1);
					l = N / int(pow(10, j + 1) + 0.1);
					if (max < r*l){
						max = r*l;
					}
				}
				N = max;
				logn = int(log10(N)) + 1; //N????????°?????????
				turn++;
			}
			return turn;
		}
	}
	return 0;
}

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

int main() {
	int q, n, m, i, j, a, b, d, cnt, max;

	cin >> q;

	for (i = 0; i < q; i++) {
		cnt = 0; 
		cin >> n;

		while (n / 10 != 0) {
			d = 1; m = n; max = 0;

			while (m / 10 != 0) {
				m /= 10;
				d++;
			}

			for (j = 1; j < d; j++) {
				a = n / pow(10, j);
				b = n - a * pow(10, j);
				if (a * b > max) {
					max = a * b;
				}
			}

			n = max;
			cnt++;
		}
		
		cout << cnt << endl;
	}
}