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>
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<map>
using namespace std;

int main(){
  map<int,bool> h;
  int q,n,cnt;
  cin >> q;
  while(q--){
    cin >> n;
    if(n<10){
      cout << n << endl;
      continue;
    }
    cnt = 0;
    h.clear();
    h[n] = true;
    while(true){
      int m = -1, k = 10;
      cnt++;
      for(int i=0;i<5;i++){
	m = max(m,(n/k)*(n%k));
	k *= 10;
      }
      if(h[m]){
	cout << -1 << endl;
	break;
      }
      if(m<10){
	cout << cnt << endl;
	break;
      }
      n = m;
      h[m] = true;
    }
  }
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int p(int r) {
	int ans = -1;
	for (int i = 10; i <= r; i *= 10)
		ans = max(ans, ((r - r % 10) / 10)*(r % 10));
	return ans;
}
int main() {
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		int k; cin >> k;
		int cnt = 0;
		while (k >= 10) { k = p(k); cnt++; }
		cout << cnt << endl;
	}
}

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

string i2s(int n){
  stringstream a;
  a << n;
  return a.str();
}

int s2i(string s){
  stringstream a;
  int res;
  a << s;
  a >> res;
  return res;
}

int main(void){
  int n;
  string init_num;
  cin >> n;
  while(n--){
    cin >> init_num;
    string nums = init_num;
    int cnt = 0;
    while(1){
      if(s2i(nums) / 10 == 0){
	cout << cnt << endl;;
	break;
      }
      int nextnum = 0;
      for(int i=1; i < nums.length(); i++){
	int prenum, postnum;
	prenum = s2i(nums.substr(0, i));
	postnum = s2i(nums.substr(i, nums.length() - i));
	nextnum = max(nextnum, prenum * postnum);
      }
      cnt++;
      nums = i2s(nextnum);
      if(nums == init_num){
	cout << -1 << endl;
	break;
      }
    }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
string to_str(ll A){
    stringstream ss;
    ss << A;
    return ss.str();
}
int func(string s){
    if(s.length() == 1)return 0;
    ll maxi = 0;
    rep(i,1,s.length()){
        ll num = stoi(s.substr(0,i) ) * stoi(s.substr(i) );    
        maxi = max(maxi, num);
    }
    return 1 + func(to_str(maxi));
}

main(){
    int N;
    cin >> N;
    rep(i,0,N){
        int num;
        cin >> num;
        cout << func(to_str(num) ) << endl;
    }
}

C++: #include <cstdio>

int p10[10];
int max(int a,int b){return a>b?a:b;}

int tejun2(int n){
  int ans=-1;
  for(int i=1; p10[i]<n; i++)
    ans=max(ans,(n/p10[i])*(n%p10[i]));
  return ans;
}

int main(){
  p10[0]=1;
  for(int i=1; i<10; i++)p10[i]=p10[i-1]*10;

  int Q,N;

  scanf("%d",&Q);
  for(int i=0; i<Q; i++){
    int cnt;
    scanf("%d",&N);
    for(cnt=0; N>=10&&cnt<100000; cnt++){
      N=tejun2(N);
    }
    if(cnt==100000)
      printf("-1\n");
    else
      printf("%d\n",cnt);
  }
}

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

int main(){
    int Q;
    cin>>Q;
    string now;
    for(int i=0;i<Q;i++){
        cin>>now;
        int ans=0;
        for(;;){
            if(now.size()==1) break;
            int ma=0;
            for(int j=1;j<now.size();j++){
                ma=max(ma,stoi(now.substr(0,j))*stoi(now.substr(j,now.size()-j)));
            }
            now=to_string(ma);
            ans++;
        }
        cout<<ans<<endl;
    }
}

C++: //B
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<cmath>
using namespace std;
string itos(int n){
stringstream ss;
ss<<n;
return ss.str();
}
int main(){
	int Q;
	cin>>Q;
for(int i=0;i<Q;i++){
	vector<string>x(0);
	string n;
	cin>>n;
	string tn=n;
	int next=0;
	int ans=0;
	while(true){
	if(tn.size()==1)break;
	int f=0;
	for(int j=0;j<x.size();j++)if(x[j]==tn)f=1;
	if(f){
	ans=-1;
	break;
	}
	x.push_back(tn);
	next=0;
	for(int j=0;j<tn.size()-1;j++){//jで分割
		int a1=0,a2=0;
		int cnt=0;
		for(int k=j;k>=0;k--){
		a1+=(tn[k]-'0')*pow(10,cnt);
		cnt++;
		}
		cnt=0;
		for(int k=tn.size()-1;k>j;k--){
		a2+=(tn[k]-'0')*pow(10,cnt);
		cnt++;
		}
		//cout<<a1<<" "<<a2<<endl;
		next=max(a1*a2,next);
	}
	tn=itos(next);

	ans++;
	}
	cout<<ans<<endl;
}

	return 0;
}

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

void steps(int n);
int step(int n);

int main()
{
    int q;
    cin >> q;
    int n;
    for(int i = 0; i < q; i++){
        cin >> n;
        steps(n);
    }
    return 0;
}

void steps(int n)
{
    int count = -1;
    while(n != -1){
        n = step(n);
        count++;
    }
    cout << count << endl;
}

int step(int n)
{
    if(n < 10){
        return -1;
    }
    int fst = n;
    int snd = 0;
    int m = 10;
    int max = 0;
    while(fst > 0){
        fst /= 10;
        snd = n % m;
        m *= 10;
        if(max < fst * snd){
            max = fst * snd;
        }
    }
    return max;
}