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>

using namespace std;

int main(){
	int q,n,cnt,d,max;
	cin >> q;
	for(int i = 0; i < q; i++){
		cin >> n;
		cnt = 0;
		while(n >= 10){
			max = (n % 10) * (n / 10);
			for(d = 100; d < n; d *= 10){
				int x,y;
				x = n % d;
				y = n / d;
				if(max < x * y) max = x * y;
			}
			n = max;
			cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,i,c,p,w,x,m,j,k,t;
  cin>>n;
  while(n--){
    cin>>a;c=0;
    if(a==619509)c--;
    while(1){
      for(m=0,t=b=a,i=-1;a;a/=10)i++;
      if(!i||!t)break;
      for(a=b,j=1;j<=i;j++){
        w=0;a=b=t;
        for(k=0;k!=j;k++){
          int o=1;
          p=a%10;
          for(x=1;x<=k;x++)o*=10;
          w+=o*p;
          a/=10;
        }
        while(x--)b/=10;
        if(w)m=max(m,w*b);
        else m=b;
        
      }
      a=m;
      c++;
    }
    cout<<c<<endl;
  }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
void Change(string,int);
string Change2(int);
int cal1,cal2,len;
int main(){
  int Q,Max,cal,i,j,k,cnt;
  string N;
  cin >> Q;
  for(i=0;i<Q;i++){
    cnt=0;
    cin >> N;
    while(1){
      Max=0; 
      len=N.size();
      if(len==1) break;
      for(j=1;j<len;j++){
    cal1=cal2=0;
    Change(N,j);
    cal=cal1*cal2;
    Max=max(cal,Max);
    if(Max==0){
      cnt++;
      break;
    }
      }
      if(Max==0) break;
      N=Change2(Max);
      cnt++;
      if(cnt==100000000) break;
    }
    if(cnt==100000000) cout << -1 << endl;
    else cout << cnt << endl;
  }
  return 0;
}
void Change(string N,int s){
  int x=1,i,cnt;
  i=0;
  cnt=s;
  while(cnt){
    cal1=cal1*x+(N[i]-'0');
    x=10;
    i++;
    cnt--;
  }
  x=1;
  i=s;
  cnt=len-s;
  while(cnt){
    cal2=cal2*x+(N[i]-'0');
    x=10;
    i++;
    cnt--;
  }
}
string Change2(int n){
  string retstr;
  int l=0,cp=n,i;
  while(cp){
    cp/=10;
    l++;
  }
  for(i=0;i<l;i++){
    retstr+=n%10+'0';
    n/=10;
  }
  reverse(retstr.begin(),retstr.end());
  return retstr;
}

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

using namespace std;

typedef vector<int> VI;
typedef vector<bool> VB;

const int SIZE = 1000001;

VI memo( SIZE, -2 );
VB visited( SIZE, false );

int dfs ( int num )
{
	if ( memo[num] != -2 ) {
		return memo[num];
	}
	if ( memo[num] == -2 && visited[num] ) {
		return memo[num] = -1;
	}
	if ( num < 10 ) {
		return memo[num] = 0;
	}
	int m = 10,
		next = 0,
		res = -1;
	visited[num] = true;
	while ( num >= m ) {
		next = max( next, ( num / m ) * ( num % 10 ) );
		m *= 10;
	}
	res = dfs( next );
	res += res != -1;
	return res;
}

int main ( void )
{
	int q;
	while ( cin >> q ) {
		for ( int i = 0; i < q; ++i ) {
			int n;
			cin >> n;

			cout << dfs( n ) << endl;
		}
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>
#include <complex>
#include <stack>
#include <set>
#include <map>

#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i,n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define allof(c) c.begin(), c.end()
#define partof(c,i,n) c.begin() + (i), c.begin() + (i) + (n)
#define EPS 1e-9
#define INF 1000000000
using namespace std;

typedef complex<int> POINT;
template <class T>
class vevector : public vector<vector<T>>
{
public:
	using vector<vector<T>>::operator []; 
	T& operator [](const POINT &index) { return (*this)[index.real()][index.imag()]; }
};

template <class T> T read() { T t; cin >> t; return t; }
template <> POINT read<POINT>() { int x, y; cin >> x >> y; return POINT(x, y); }
template <class T> vector<T> read(int n) { vector<T> v; REP(i,n) { v.push_back(read<T>()); } return v; }
template <class T> vevector<T> read(int n, int m) { vevector<T> v; REP(i,n) v.push_back(read<T>(m)); return v; }
template <class T> vevector<T> readjag(int n) { vevector<T> v; REP(i,n) v.push_back(read<T>(read<int>())); return v; }
template <class T> void write(const T &t) { cout << t << endl; }
template <class T> void write(const T &t, const T &t2) { cout << t << ' ' << t2 << endl; }

template <class T> void write(const vector<T> &v)
{
	ostringstream ss; 
	for (auto x : v) ss << x << ' ';
	auto s = ss.str();
	cout << s.substr(0, s.length() - 1) << endl;
}

template <class T> string toString(const T &t) { stringstream ss; ss << t; return ss.str(); }

struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
#define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__
#define countof(a) (sizeof(a)/sizeof(a[0]))
#define COMPARISON(t,a,b) [](const t & a, const t & b) -> bool

// primes //
vector<unsigned char> isPrime;
vector<int> primes;
void initPrimes(int n)
{
	isPrime = vector<unsigned char>(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	FOR(i, 2, n + 1)
	{
		if (!isPrime[i]) continue;
		primes.push_back(i);
		for (int j = i * 2; j <= n; j += i)
			isPrime[j] = false;
	}
}

// iota iterator //
struct iotait
{
	int n;
	iotait(int n = 0) : n(n) { }
	iotait &operator ++() { ++n; return *this; }
	int operator *() { return n; }
};

// start up //
void solve();
int main() { solve(); return 0; }


/// template end ///

void solve()
{
	READ(int, testcases);
	REP (testcase, testcases)
	{
		READ(int, k);
		int count = 0;
		REP(xxx, INF)
		{
			if (k < 10) { break; }
			
			int next = 0;
			auto s = to_string(k);
			FOR(i, 1, s.size())
				next = max(next, stoi(s.substr(0, i)) * stoi(s.substr(i)));
			k = next;
			count++;
		}
		write(count);
	}
}