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 <string>
#include <sstream>

std::string toStr(int i) {
    std::stringstream ss;
    
    ss << i;
    
    return ss.str();
}

int toInt(const std::string& str) {
    int i;
    
    std::stringstream(str) >> i;
    
    return i;
}


int main() {
    int q, n;
    
    std::cin >> q;
    while(q--) {
        std::cin >> n;
        int cnt = 0;
        
        while(1) {
            if(n < 10) break;
            
            ++cnt;
            auto str = toStr(n);
            
            int max = 0;
            for(unsigned int i = 1; i < str.size(); ++i) {
                max = std::max(
                          toInt(str.substr(0, i)) * toInt(str.substr(i)),
                          max
                      );
            }
            n = max;
        }
        
        std::cout << cnt << std::endl;
    }
}

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

using namespace std;

typedef vector<int> VI;
typedef vector<bool> VB;

const int SIZE = 1000001;

VI memo( SIZE, -2 );
VB visited( SIZE, false );

int dfs ( int num )
{
	if ( memo[num] != -2 ) {
		return memo[num];
	}
	if ( memo[num] == -2 && visited[num] ) {
		return memo[num] = -1;
	}
	if ( num < 10 ) {
		return memo[num] = 0;
	}
	int m = 10,
		next = 0,
		res = -1;
	visited[num] = true;
	while ( num >= m ) {
		next = max( next, ( num / m ) * ( num % m ) );
		m *= 10;
	}
	res = dfs( next );
	res += res != -1;
	return memo[num] = res;
}

int main ( void )
{
	int q;
	while ( cin >> q ) {
		for ( int i = 0; i < q; ++i ) {
			int n;
			cin >> n;

			cout << dfs( n ) << endl;
		}
	}
	return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>
#include <complex>

#define INF 100000000
#define EPS 1e-9

using namespace std;

typedef long long ll;

vector<int> ans_list;

bool dp[1000001];

int main(){

	int Q;
	cin >> Q;

	memset(dp, 0, sizeof(dp));

	while (Q){
		Q--;
		int N;
		cin >> N;
		int ans = 0;
		memset(dp, 0, sizeof(dp));

		while (N/10 > 0){
			if (dp[N]){
				ans = -1;
				break;
			}
			int tmp = 0;
			for (int i = 1; N/pow(10,i) > 0; i++){
				tmp = max(tmp, (N / (int)pow(10, i)) * (N % (int)pow(10, i)) );
			}
			dp[N] = false;
			N = tmp;
			ans++;
		}

		ans_list.push_back(ans);

	}
	
	for (int i = 0; i < ans_list.size(); i++){
		cout << ans_list[i] << endl;
	}

	return 0;

}

C++: #include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int fnc(int n){
	if(n<10)return 0;
	int ans=0;
	for(int i=1;(int)pow(10,i)<n;i++){
		int pre=n/(int)pow(10,i),la=n%((int)pow(10,i));
		ans=max(ans,pre*la);
	}
	return fnc(ans)+1;
}

int main(){
	int q;
	cin>>q;
	int num;
	rep(p,q){
		cin>>num;
		cout<<fnc(num)<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
typedef pair<int,int> P;

int main() {
  int T;
  cin >> T;
  while(T--) {
    string s;
    cin >> s;
    int cnt=0;
    while(s.size()>1) {
      int ans=0;
      REP(i,1,s.size()) {
	int x,y;
	stringstream ss1,ss2;
	ss1 << s.substr(0,i);
	ss2 << s.substr(i);
	ss1 >> x;
	ss2 >> y;
	ans=max(ans,x*y);
      }
      stringstream ss;
      string t;
      ss << ans;
      ss >> t;
      if(s==t) {
	cnt=-1;
	break;
      }
      s=t;
      cnt++;
    }
    pr(cnt);
  }
  return 0;
}

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

int main(){
	int q,n,count,a,b,res;
	string s,s1,s2;

	cin >> q;
	for(int i = 0;i < q;i++){
		cin >> n;
		count = 0;
		while(1){
			res = 0;
			if(n/10 == 0)break;
			s = to_string(n);
			for(int j = 1;j < s.size();j++){
				s1.assign(s,0,j);
				s2.assign(s,j,s.size()-j);
				a = stoi(s1);
				b = stoi(s2);
				res = max(res,a*b);
			}
			n = res;
			count++;
		}
		cout << count << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
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;
	}
}