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 "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;



int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> M;
		string s = to_string(M);
		int cnt = 0;
		while (s.size() > 1) {
			cnt++;
			K = s.size();
			K--;
			int ans = 0;
			for (int j = 0; j < K; j++) {
				string t, u;
				for (int k = 0; k <= j; k++) {
					t += s[k];
				}
				for (int k = j + 1; k <= K; k++) {
					u += s[k];
				}
				int box = 0;
				for (auto k : t) {
					box *= 10;
					box += k - '0';
				}
				int bag = 0;
				for (auto k : u) {
					bag *= 10;
					bag += k - '0';
				}
				ans = max(ans, box*bag);
			}
			s = to_string(ans);
		}
		cout << cnt << endl;
	}
	return 0;
}

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

int q, i, ans, n, p, r, b;
bool f;
int main(){
        cin >> q;
        for (i = 0; i < q; i++){
                f = 1;
                ans = 0;
                map<int, int> mp;
                cin >> n;
                mp[n]++;
                while(1){
                        if (n < 10) break;
                        int j = 10;
                        b = 0;
                        while (n / j > 0){
                                p = n / j;
                                r = n % j;
                                b = max(b, p * r);
                                j *= 10;
                        }
                        n = b;
                        //cout << n << endl;
                        if (mp[n] > 0){
                                f = 0;
                                break;
                        }
                        mp[n]++;
                        ans++;
                }
                cout << (f ? ans : -1) << endl;
        }
        return 0;
}

C++: #include<iostream>
#include<set>
#include<cstdio>
#include <sstream>
#include <string>
using namespace std;
int main()
{
  int s;
  cin>>s;
  for(;s--;)
    {
      
      int n,c=0;
      cin>>n;
      set<int> hash;
      for(;n>9;)
	{
	  if(hash.find(n) != hash.end())
	    {
	      c=-1;
	      break;
	    }
	  hash.insert(n);
	  int max=0;
	  stringstream ss;
	  ss << n;
	  string tmp= ss.str();

	  for(int i=1;i<tmp.size();i++)
	    {
	      int a=0,b=0;
	      for(int j=0;j<tmp.size();j++)
		{
		  if(j<i)
		    {
		      a*=10;
		      a+=tmp[j]-'0';
		    }
		  else
		    {
		      b*=10;
		      b+=tmp[j]-'0';
		    }
		}
	      
	      //	      cout<<"i:"<<i<<" a:"<<a<<" b:"<<b<<" a*b:"<<a*b<<endl;
	      if(a*b>max)
		max=a*b;
	    }
	  
	  //	  cout<<"max:"<<max<<endl;
	  n=max;
	  c++;
	}
      	cout<<c<<endl;
    }
}

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

int main ()
{
    int q;
    cin >> q;
    while (q--) {
        int n, res = 0;
        cin >> n;
        set<int> t;
        while (n / 10) {
            t.insert(n);
            res++;
            int MAX = 0;
            int j = 1, k = 0;
            while (n) {
                k += j * (n % 10);
                n /= 10;
                MAX = max(MAX, k * n);
            }
            n = MAX;
            if (t.find(n) != t.end()) {
                res = -1;
                break;
            }
        }
        cout << res << endl;
    }

    return 0;
}

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

int main(){
  int q;
  int n;
  int count;
  int max;
  cin >> q;
  for(int i=0;i<q;i++){
    cin >> n;
    count=0;
    while(n/10>=1){
      count+=1;
      max=0;
      for(int j=1;j<6;j++){
	int t=pow(10,j);
	int tmp=(n/t)*(n%t);
	if(max<tmp) max=tmp;
      }
      n=max;
    }
    cout<<count<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif

#define INF 1e9;

int ch[1000001];

int culc(int pos, int r)
{
	if (r < 10) return 0;
	if (ch[r] == pos) return -INF;
	ch[r] = pos;
	int ma = 0;
	for (int i = 10; r / i > 0; i *= 10) {
		ma = max((r / i) * (r % i), ma);
	}
	return culc(pos, ma) + 1;
}

int main()
{
	CIN(int, q);
	reps(i, 1, q+1) {
		CIN(int, r);
		cout << max(culc(i, r), -1) << endl;
	}
}