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<sstream>
#include<string>
#include<set>
using namespace std;
int main(){

  int Q;
  string str;
  
  cin >>Q;
  
  for(int i=0 ; i < Q ; i++){
    
    cin >>str;

    int cnt=0;
    
    while(1){

      stringstream ss1;
      set<string> s;
      
      ss1<<str;
      int str_num;
      ss1>>str_num;
      
      //cout <<str_num<<endl;
      
      if(str_num >= 0 && str_num <= 9){
	break;
      }else if(s.find(str) != s.end()){
	cnt = -1;
	break;
      }
      
      s.insert(str);
      
      int max=-1;
      
      for(int j=1 ; j < str.size() ; j++){

	int n1,n2;
	stringstream ss2,ss3;
	string sub1,sub2;
	
	sub1=str.substr(0,j);
	sub2=str.substr(j);
	ss2<<sub1;
	ss3<<sub2;
	ss2>>n1;
	ss3>>n2;
	if(max < n1*n2)max=n1*n2;
      }

      stringstream ss4;
      
      ss4<<max;
      ss4>>str;
      
      cnt++;
    }
    
    cout <<cnt<<endl;
  }
  
  return 0;
}

C++: #include <iostream>

int judge ( int );

int main()
{
    int q;
    std::cin >> q;
    for ( int cnt = 0; cnt < q; cnt ++ )
    {
        int n;
        std::cin >> n;
        std::cout << judge(n) << std::endl;
    }
}

int judge ( int n )
{
    // log使うのが面倒くさい
    int tmp;
    int d = 0;
    int max = 0;
    int step = 0;
    int o[10000];
    
    for ( int i = 0; i < 10000; i++ )
    {
        o[i] = 0;
    }
    
    while(true)
    {
    
//    std::cout << "3 " << n << std::endl;
    tmp = n;
    d = 0;
    do
    {
        tmp /= 10;
        d ++;
    } while ( tmp != 0 );
    
    if ( d == 1 )
    {
        break;
    }
    
    tmp = 1;
    max = 0;
    for ( int i = 0; i < d-1; i ++ )
    {
        tmp *= 10;
//        std::cout << "    " << i << " " << (n/tmp) * (n%tmp) << std::endl;
        if ( max < (n/tmp) * (n%tmp) )
        {
            max = (n/tmp) * (n%tmp);
        }
    }
    
    o[step] = n;
    n = max;
    for ( int i = 0; i < step+1; i ++ )
    {
        if ( o[i] == n )
        {
            step = -1;
            break;
        }
    }
    step ++;
    
    }
    
    return step;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

ll calc(string s){
	ll ans = 0;
	ll x,y;
	FOR(i,1,s.size()){
		x = stoi(s.substr(0,i));
		y = stoi(s.substr(i,s.size()-i));
		ans = max(ans,x*y);
	}
	return ans;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll Q;
	cin >> Q;
	FOR(t,0,Q){
		ll R;
		cin >> R;
		ll ans = 0;
		while(R>=10){
			R = calc(to_string(R));
			++ans;
		}
		cout << ans << endl;
	}
}

C++: #include<iostream>
#include<set>
using namespace std;
int main(){
  int Q,N;
  int ans;
  cin>>Q;
  for(int i=0;i<Q;i++){
    cin>>N;
    set<int>used;
    bool ok=true;
    ans=0;
    while(N/10){
      if(used.count(N)){
        ans=-1;
        break;
      }
      used.insert(N);
      ans++;
      int max=0;
      for(int p=1;p<N;p*=10){
        if((N/p)*(N%p)>max)max=(N/p)*(N%p);
      }
      N=max;
    }
    cout<<ans<<endl;
  }
}

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

int q;
int n;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> q;
	while(q--){
		int n;
		cin >> n;
		int r = 0;
		set<int> s;
		for(r=0; n>9; ++r){
			int ma = -1;
			int tmp = n;
			int d = 0;
			while(tmp > 0){
				tmp /= 10;
				++d;
			}
//			cout << n << " " << d << "\n";
			for(int i=1; i<d; ++i){
				int a = 0, b = 0;
				int t = n;
				for(int j=0; j<d; ++j){
					if(j >= i){
						int m = t % 10;
						for(int k=0; k<j-i; ++k)
							m *= 10;
						b += m;
						t /= 10;
					}else{
						int m = t % 10;
						for(int k=0; k<j; ++k)
							m *= 10;
						a += m;
						t /= 10;
					}
				}
//				cout << n << " " << ma << " " << a*b << "\n";
				ma = max(ma, a*b);
			}
			if(s.find(ma) != s.end()){
				r = -1;
				break;
			}else{
				s.insert(ma);
			}
			n = ma;
		}
		cout << r << "\n";
	}
}

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

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long int ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back


int solve(int n){
    string s=to_string(n);
    
    int maxi=-1;
    rep(i,s.size()-1){
        int tmp;
        tmp=stoi( s.substr(0,i+1) ) * stoi( s.substr(i+1,s.size()-i) );
        maxi=max(maxi,tmp);
    }
    
    return maxi;
}

int main(){
    int abcde;
    cin>>abcde;
    rep(i,abcde){
        int n;
        cin>>n;
        
        int c=0;
        for(int i=0;i<1000000;i++){
            if(i==1000000-1)c=-1;
            
            if(n<10)break;
            n=solve(n);
            c++;
        }
        cout<<c<<endl;
    }
    
    return 0;
}