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++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

constexpr int pows(int a, int b) {
  int c = 1;
  while (b) {
    if (odd(b)) c *= a;
    b >>= 1;
    a *= a;
  }
  return c;
}

int f(int x) {
  int c = -INF;
  int n = to_string(x).size();
  loop(i, 1, n) {
    int a = x / pows(10, i);
    int b = x % pows(10, i);
    cmax(c, a * b);
  }
  return c;
}

void solve() {
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    int c = 0;
    set<int> s;
    while (n >= 10) {
      n = f(n);
      c++;
      if (s.count(n)) {
        cout << -1 << endl;
        goto next;
      }
      s.insert(n);
    }
    cout << c << endl;
  next:;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;int n,q,X,A,i,j,s,t;int main(){cin>>n;for(i=0;i<n;i++){s=0;cin>>q;X=q;while(X>9){A=0;for(j=1;j<10;j++){t=pow(10.0,j);if(q/t<1){break;}A=max((X/t)*(X%t),A);}s++;if(s>=1000){s=-1;break;}X=A;}cout<<s<<endl;}}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 100000000
using namespace std;
int cnt = 0;
int divide(string num){
  int result = 0;
  for(int i=1; i<num.size(); i++){
    int left = atoi(num.substr(0,i).c_str());
    int right = atoi(num.substr(i,num.size()-i).c_str());
    //cout << left << " " << right << endl;
    result = max(result,left*right);
    //cout << result << endl;
  }
  cnt++;
  if(result>=10) return divide(to_string(result));
  else if(cnt==INF) return -1;
  else return 1;
}
int main(){
  int n;
  cin >> n;
  string num;
  rep(i,n){
    cin >> num;
    cnt = 0;
    if(atoi(num.c_str()) <= 9) cout << 0 << endl;
    else if(divide(num) == 1) cout << cnt << endl;
    else cout << -1 << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
ll rec(ll a){
	ll m=-1,k=10;
	while(1){
		if(a/k==0)break;
		m=max(m,a/k*(a%k));
		k*=10;
	}
	return m;
}
int main(){
	ll q,n;
	cin>>q;
	while(q--){
		int cnt=0;
		cin>>n;
		while(n>=10){
			n=rec(n);
//			cout<<n<<endl;
			cnt++;
		}
		cout<<cnt<<endl;
	}
}

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

int q;
std::string str, b, e;

int solve(int m) {
	int cnt = 0;
	while (1) {
		str = std::to_string(m);
		if (str.size() == 1)
			break;
		b.clear();
		e = str;
		int l, r, max = 0;
		for (int i = 0; i < str.size() - 1; ++i) {
			b += str[i];
			e.erase(e.begin());
			l = std::stoi(b);
			r = std::stoi(e);
			max = std::max(max, l*r);
			m = max;
		}
		++cnt;
	}
	return cnt;
}

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