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<bits/stdc++.h>
using namespace std;

int divider(string str){
  int maxi=-1;
  for(int k=0;k < str.size();k++){
    string s1 = str.substr(0,k);
    string s2 = str.substr(k);
    maxi = max(maxi, atoi(s1.c_str())*atoi(s2.c_str()));
  }
  if(maxi/10) return maxi;
  else return 0;
}

string changer(int a){
  stringstream ss;
  ss << a;
  return ss.str();
}

int main()
{
  int n;
  cin >> n;
  for(int i=0;i < n;i++){
    string str;
    cin >> str;
    
    int cnt=0;
    int judge;
    string ss=str;
    
    while(judge = divider(ss)){
      ss = changer(judge);
      cnt++;
    }
    if(str.size() != 1){
      cout << cnt+1 << endl;
    }
    else cout << cnt << endl;
  }
  return 0;
}

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

int main(){
  int q,n,cnt;
  cin >> q;
  while(q--){
    cin >> n;
    cnt = 0;
    for(;;){
      int m = -1, k = 10;
      if(n<10){
	cout << cnt << endl;
	break;
      }
      for(int i=0;i<5;i++){
	m = max(m,(n/k)*(n%k));
	k *= 10;
      }
      n = m; cnt++;
    }
  }
}

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

typedef long long ll;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int dy[] = { 0, 0, 1, -1 };
int dx[] = { 1, -1, 0, 0 };

ll A, B, C, D, E, F, G, H, I, J, K, L, M,
N, O, P, Q, R, S, T, U, V, W, X, Y, Z;

struct Card {
	ll number;
	char color;
} Card_t;

namespace aojKakezan { void aojKakezan(); }
int main()
{
	aojKakezan::aojKakezan();
	return 0;
}

//* ?????????n??????????????\??????????????????????????????????????????
template <typename T>
vector<T> INP(ll n)
{
	vector<T> x;
	REP(i, n) {
		T tmp; cin >> tmp;
		x.push_back(tmp);
	}
	return x;
}
//* n??????1????????????????????\?????????????????????????????¨??????????????????
vector<char> SPRIT_STRING(ll n)
{
	string str; cin >> str;
	vector<char> cs(n);
	REP(i, n) cs[i] = str[i];
	return cs;
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2424
namespace aojKakezan {
	void aojKakezan() {
		cin >> Q;
		REP(i, Q) {
			string current; cin >> current;
			ll cnt = 0;
			while (current.size() > 1) {
				ll maxNext = 0;
				REP(p, current.size() - 1) {
					ll a = stoi(current.substr(0, p+1));
					ll b = stoi(current.substr(1 + p, current.size() - (p+1)));
					maxNext = max(maxNext, a * b);
				}
				current = to_string(maxNext);
				cnt++;
			}
			cout << cnt << endl;
		}
	}
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2102&lang=jp
namespace aojRummy {
	bool comp(const Card& a, const Card& b)
	{
		return a.number < b.number;
	}

	bool rummyCheck(vector<Card> cards)
	{
		if (cards.size() == 0) return true;
		if (cards.size() % 3 != 0) return false;
		sort(cards.begin(), cards.end(), comp);
		bool okay = false;
		do {
			int repNum = cards.size() / 3;
			bool localOkay = true;
			REP(i, repNum) {
				ll zero = cards[i * 3].number;
				ll one = cards[i * 3 + 1].number;
				ll two = cards[i * 3 + 2].number;
				if (not((zero == one and one == two) or ((zero + 1) == one and (one + 1) == two)))
					localOkay = false;
			}
			if (localOkay)
				okay = true;
		} while (next_permutation(cards.begin(), cards.end(), comp));
		return okay;
	}

	void aojRummy()
	{
		cin >> T;

		N = 9;
		REP(t, T) {
			vector<Card> cards(N);
			REP(i, 9) cin >> cards[i].number;
			REP(i, 9) cin >> cards[i].color;

			vector<Card> red, green, blue;
			REP(i, N) {
				Card c = cards[i];
				if (c.color == 'R') red.push_back(c);
				else if (c.color == 'G') green.push_back(c);
				else blue.push_back(c);
			}

			if (rummyCheck(red) and rummyCheck(blue) and rummyCheck(green))
				cout << 1 << endl;
			else
				cout << 0 << endl;
		}
	}
}

//* http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1129
void aojHanafudaShuffle()
{
	N = R = 1;
	while (true) {
		cin >> N >> R;
		if (N == 0 and R == 0) break;

		vector<ll> cards(N);
		REP(i, N) cards[i] = i + 1;

		REP(i, R) {
			cin >> P >> C;
			rotate(cards.begin() + (N - (C + P - 1)), cards.begin() + (N - (P - 1)), cards.end());
			//vector<ll> tmp(C);
			//copy(cards.begin() + (N - (C + P - 1)), cards.begin() + N - (P - 1), tmp.begin());
			//copy(cards.begin() + (N - (P - 1)), cards.end(), cards.begin() + (N - (C + P - 1)));
			//copy(tmp.begin(), tmp.end(), cards.begin() + (N - C));
		}

		cout << cards[cards.size() - 1] << endl;
	}
}

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

vector<long long int>memo;
set<long long int>S;

long long int saiki( long long int N ) {
	if( S.find( N ) != S.end() ) {
		return memo[N] = -1;
	}
	S.insert( N );
	if( N < 10 ) {
		return 0;
	}
	if( memo[N] != -1 ) {
		return memo[N];
	}
	long long int now = 1;
	long long int ret = INT_MAX;
	long long int next = 0;
	while( true ) {
		now *= 10;
		long long int a = N / now;
		long long int b = N%now;
		if( a == 0 ) {
			break;
		}
		next = max( next, a*b );
	}
	ret = min( ret, saiki( next ) + 1 );
	return memo[N] = ret;
}

int main() {
	long long int Q;
	cin >> Q;
	memo = vector<long long int>( 1e6 + 1, -1 );
	for( size_t i = 0; i < Q; i++ ) {
		long long int N;
		S.clear();
		cin >> N;
		cout << saiki( N ) << endl;
	}
}