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 <deque>
#include <cstdlib>
#include <cmath>
#include <climits>

using namespace std;

bool exist( int n, deque<int> l ){
  for( deque<int>::iterator it = l.begin(); it != l.end(); it++ ){
    if( *( it ) == n ){ return true; }
  }
  return false;
}

int proc( int n, int c, deque<int> l ){
  if( n < 10 ){ return c; }
  if( exist( n, l ) ){ return -1; }
  
  // Dividors number == [log10( n )]
  int dn = floor( log10( n )  );
  int max = INT_MIN;
  for( int i = 1; i <= dn; i++ ){
    int dv = pow( 10.0, i * 1.0 );
    int a = n / dv;
    int b = n % dv;
    if( max < a * b ){ max = a * b; }
  }
  l.push_back( n );
  return proc( max, c + 1, l );
}

int main(){
  int q;
  deque<int> l;
  cin >> q;
  for( int i = 0; i < q; i++ ){
    int n;
    cin >> n;
    cout << proc( n, 0, l ) << endl;
  }
  return EXIT_SUCCESS;
}

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;
}

int stoi(const std::string& str, std::size_t* idx = NULL, int base = 10) {
	const char* p = str.c_str();
	char* end;
	errno = 0;
	long x = std::strtol(p, &end, base);
	if (p == end) {
		throw std::invalid_argument("stoi");
	}
	if (errno == ERANGE || x < INT_MIN || x > INT_MAX) {
		throw std::out_of_range("stoi");
	}
	if (idx != NULL) {
		*idx = static_cast<std::size_t>(end - p);
	}
	return static_cast<int>(x);
}
int stoi(const std::wstring& str, std::size_t* idx = NULL, int base = 10) {
	const wchar_t* p = str.c_str();
	wchar_t* end;
	errno = 0;
	long x = std::wcstol(p, &end, base);
	if (p == end) {
		throw std::invalid_argument("stoi");
	}
	if (errno == ERANGE || x < INT_MIN || x > INT_MAX) {
		throw std::out_of_range("stoi");
	}
	if (idx != NULL) {
		*idx = static_cast<std::size_t>(end - p);
	}
	return static_cast<int>(x);
}
std::string to_string(long long int val)
{
	char buffer[std::numeric_limits<long long int>::digits10 + 2]; // '-' + NULL
	std::sprintf(buffer, "%lld", val);
	return buffer;
}

// 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;
	}
}