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 <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int stoi (string s ){
	stringstream ss (s );
	int res;
	ss >> res;
	return res;
}

string itos (int n ){
	stringstream ss;
	ss << n;
	return ss.str();
}
	
int main()
{
	ios_base::sync_with_stdio(0);
	int Q; cin >> Q;

	while (Q--){
		string n = ""; cin >> n;
		int res = 0;
		set<int> same; same.clear();
		while (n.length() != 1 ){
			int cur = 0;
			rep (i, n.length() - 1 ){
 				string s = n.substr (0, i+1), t = n.substr(i+1);
				int sn = stoi (s ), tn = stoi (t );
//				cerr << "sn: " << sn << " tn: " << tn << endl;
				cur = max (cur, sn*tn );
			} // end rep
			if (!same.count (cur ) ){
				same.insert(cur );
			}else{
				res = -1;
				break;
			} // end if
			n = itos (cur );
			res++;
		} // end while
		cout << res << endl;

	} // end while
		
	return 0;
}

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

int Pow(int t){
	int ret = 1;
	for(int i = 0; i < t; i++) ret *= 10;
	return ret;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int r;
		cin >> r;
		int cnt = 0;
		while(true){
			if(r < 10) break;
			int x = 10;
			int rank;
			for(int i = 2;;i++){
				x *= 10;
				if(x > r){
					rank = i;
					break;
				}
			}
			int nr = 0;
			for(int i = 1; i <= rank-1; i++){
				int y = (r%Pow(i))*(r/Pow(i));
				if(y > nr) nr = y;
			}
			r = nr;
			cnt++;
		}
		cout << cnt << endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.out


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    int q;
    cin>>q;
    rep(i,q){
        string n;
        cin>>n;
        int ans=0;
        while(n.length()>1){
            int maxans=0;
            for(int j=0;j<n.length()-1;j++){
                string s,t;
                s=n.substr(0,j+1);
                t=n.substr(j+1);
                maxans=max(maxans,STI(s)*STI(t));
            }
            n="";
            while(maxans>0){
                n+=maxans%10+'0';
                maxans/=10;
            }
            ans++;
            reverse(n.begin(),n.end());
        }
        cout<<ans<<endl;
    }
//////////////////////////////////////////////////////
return 0;}

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

using namespace std;
typedef unsigned long long ull;


int main()
{
	int q;

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

			int sum = 0;
			set<ull> f;

			while (1)
			{
				ull tmp = atoi(n.c_str());
				if (f.count(tmp))
				{
					cout << -1 << endl;
					break;
				}
				else
				{
					f.insert(tmp);
				}
				
				if (sum >= 1e5)
				{
					cout << -1 << endl;
					break;
				}

				if (n.size() == 1)
				{
					cout << sum << endl;
					break;
				}
				else
				{
					ull Max = 0;
					for (int j = 1; j < n.size(); j++)
					{
						ull tmp = atoi(n.substr(0, j).c_str());
						ull tmp2 = atoi(n.substr(j, n.size() - j).c_str());
						Max = max(Max, tmp*tmp2);
					}
					stringstream nextN;
					nextN << Max;
					n = nextN.str();

					sum++;
				}
			}


		}
	}
	

	return 0;
}

C++: #include <iostream>
#include <map>
#include <algorithm>
using namespace std;
//http://hadrori.hateblo.jp/entry/aoj2424
//10の累乗で割った余りと商を掛けて次の数にするだけ。

int main(){
	int q;
	for(cin>>q;q;q--){
		int n;
		cin>>n;
		int t=n;
		int cnt=0;
		while(t/10>0){
			int d=10;
			int mx=0;
			while(t/d>0){
				mx=max(mx,(t/d)*(t%d));
				d*=10;
			}
			t=mx;
			if(t==n){
				cnt=n;
				break;
			}
			cnt++;
		}
		cout<<cnt<<endl;
		
	}
	
	return 0;
}