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 <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */

/** Problem2424 : Kakezan **/
ll toInt(string N) {
	ll res;
	stringstream ss(N);
	ss >> res;
	return res;
}

string toStr(ll N) {
	string res;
	stringstream ss;
	ss << N;
	ss >> res;
	return res;
}

int main()
{
	int Q;
	string N;
	cin>>Q;
	rep(i, Q) {
		cin>>N;
		int cnt=0;
		
		bool used[1000001]={0};
		
		while (1) {
			if (!used[toInt(N)]) {
				used[toInt(N)] = true;
			} else {
				cout << -1 << endl;
				break;
			}
			
			if (N.size()==1) {
				cout << cnt << endl;
				break;
			}
			
			ll tmp = 0;
			for (int j=1; j<=N.size()-1; j++){
				ll a = toInt(N.substr(0, j));
				ll b = toInt(N.substr(j));
				tmp = max(tmp, a*b);
			}
			
			N = toStr(tmp);
			cnt++;
		}
	}
}

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

using namespace std;

int
main() {
  // int a = std::stoi("123");
  // int a {std::stoi("0123") };
  // vector<int> in { 9, 99, 123 };

  int n;
  cin >> n;
  vector<int> in;
  
  for (int i=0; i<n; ++i) {
    string v;
    cin >> v;
    in.push_back( stoi(v) );
  }
  
  for (auto i:in ) {
    int a = i, cnt=0;;
    string s{};
    while (a >= 10) {
      auto enum_int = [&] {
	s = to_string(a);
	vector<pair<string,string> > xs;    
	for (int i=1;i<s.size(); i++) {
	  xs.push_back( std::make_pair( s.substr(0,i), s.substr(i) ) );
	}
	return xs;
      };
      auto && xs = enum_int();
      int m = 0;
      for (auto & x : xs) {
	m = max(m, std::stoi(x.first) * std::stoi(x.second) );
      }
      a = m;
      cnt++;
    }
    cout << cnt << endl;    
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////

ll pow10(ll x) {
	ll ret = 1;
	if (x == 0) return ret;
	else {
		repi(i, 0, x) ret *= 10;
		return ret;
	}
}

int main() {
	ll Q;
	rd(Q);
	repi(i, 0, Q) {
		ll N, ans = 0;
		rd(N);
		while (N / 10 != 0) {
			ll tc = 1;
			ll tv = N / 10;
			ll tr = N % pow10(tc);
			ll maxt = 0;
			while (1) {
				maxt = max(maxt, tv*tr);
				if (tv / 10 == 0) break;
				tv /= 10;
				tc++;
				tr = N % pow10(tc);
			}
			N = maxt;
			ans++;
		}
		wrln(ans);
	}
	return 0;
}