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 <cstdio>
#include <string>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int const MOD = 1000000007;

int main() {
    int q; cin >> q;
    rep(i,0,q) {
        string s; cin >> s;
        int cnt = 0;
        while(1) {
            // cout << s << endl;
            if(s.length() == 1) break;
            else {
                int ma = 0;
                repq(i,1,s.length()) {
                    string s1 = s.substr(0,i);
                    string s2 = s.substr(i,s.length() - i);
                    ma = max(ma, atoi(s1.c_str()) * atoi(s2.c_str()));
                }
                s = to_string(ma);
                cnt++;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

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

int main(){
	int q;
	cin >> q;

	for(int p=0; p < q; p++){
		int num;
		int count = 0;
		cin >> num;

		while(num / 10 != 0){
			int n, m, maxNum = 0;
			for(int d = 10; num / d != 0; d *= 10){
				maxNum = max(maxNum, (num/d) * (num % d));
			}
			num = maxNum;
			count++;
		}
		cout << count << endl;
	}
}

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

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)

using namespace std;
typedef long long int ll;

int main(void){
	ll Q;
	cin>>Q;
	while(Q--){
		string str;
		int cnt = 0;
		cin>>str;
		vector<int> n(str.size());
		rep(i,str.size())n[i]=str[i]-'0';
		while(n.size()>1){
			double num=0;
			if(n[0]<=n[n.size()]){
				loop(i,1,n.size())num=num*10+(n[i]);
				num = num * (n[0]);
			}else{
				rep(i,n.size()-1){
					num=num*10+n[i];		
				}num = num * (n[n.size()-1]);
			}
			int size=1;
			rep(i,n.size()-1)size*=10;
			n.clear();
			if((int)num/size==0)size/=10;
			while(num!=0){
				int no=(int)num/size;
				num=(int)num%size;
				size=size/10;
				n.push_back(no);
			}
			cnt++;
		}
		cout<<cnt<<endl;
	}
}

C++: #include<iostream>
#include<set>
using namespace std;int Q,N,a,p,M,t;main(){for(cin>>Q;Q--;cout<<a<<endl){set<int>u;for(cin>>N,a=0;N/10&&~a;N=M)for(u.count(N)&&(a=-2),u.insert(N),a++,p=M=1;p<N;p*=10,M=t>M?t:M)t=(N/p)*(N%p);}}

C++: #include <bits/stdc++.h>
using namespace std;
int f(int x){
  string S = to_string(x);
  int N = S.size();
  int ans = 0;
  for (int i = 1; i < N; i++){
    ans = max(ans, stoi(S.substr(0, i)) * stoi(S.substr(i)));
  }
  return ans;
}
int main(){
  vector<int> r(1000001, 0);
  for (int i = 10; i <= 1000000; i++){
    r[i] = r[f(i)] + 1;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++){
    int N;
    cin >> N;
    cout << r[N] << endl;
  }
}

C++: #include <iostream>
#include <string>

using namespace std;

int main() {
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int value, source_value, count = 0;

		cin >> source_value;
		value = source_value;

		while (value >= 10) {
			count++;

			string str = to_string(value);
			int len = str.size(), max = 0;

			for (int j = 1; j < len; j++) {
				int temp1, temp2;

				temp1 = stoi(str.substr(0, j));
				temp2 = stoi(str.substr(j));

				if (max < temp1 * temp2) {
					max = temp1 * temp2;
				}
			}

			value = max;
		}

		cout << count << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

int calc(int x){
    if (x < 10) return 0;
    string s = to_string(x);
    int res = 1, tmp = -1;
    rep((int)s.size()-1, i) {
        int a = stoi(s.substr(0, i+1)), b = stoi(s.substr(i+1));
        tmp = max(tmp, a*b);
    }
    res += calc(tmp);
    return res;
}

void solve(void){
    int Q;
    cin >> Q;
    rep(Q, i) {
        int a; cin >> a;
        cout << calc(a) << endl;
    }
}

int main(void){
  solve();
  return 0;
}