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<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>

using namespace std;

int keta(long long n)
{
	int cnt=0;
	while(true)
	{
		cnt++;
		n/=10;
		if(n<=0)break;
	}
	return cnt;
}

int main()
{
	int q;
	cin >> q;
	for(int i=0;i<q;i++)
	{
		long long n;
		cin >> n;
		long long cnt=0;
		while(true)
		{
			int ke=keta(n);
			if(ke<=1)
				break;
			cnt++;
			long long tmp=0;
			for(int j=0;j<ke;j++)
			{
				long long tmptmp;
				long long un,up;
				long long aa=1;
				for(int k=0;k<j;k++)
				{
					aa*=10;
				}
				un=n%aa;
				up=n/aa;
				tmptmp=un*up;
					
				if(tmp<tmptmp)tmp=tmptmp;

			}
			n=tmp;
		}

		cout << cnt << endl;


	}
}

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

int toInt(const string a){
  stringstream ss;
  ss<<a;
  int b;
  ss>>b;
  return b;
}

string toStr(const int a){
  stringstream ss;
  ss<<a;
  string b;
  ss>>b;
  return b;
}

int main(void){
  int q;cin>>q;
  for(int i=0;i<q;++i){
    int c=0;
    string s;cin>>s;
    set<string> p;
    p.insert(s);
    for(;s.size()!=1;){
      int max=0;
      for(int i=1;i<s.size();++i){
        int a=toInt(s.substr(i,s.size()-i)),b=toInt(s.substr(0,i));
        if(max<a*b) max=a*b;
      }
      ++c;
      s=toStr(max);
      if(p.find(s)!=p.end()){c=-1;break;}
      p.insert(s);
    }
    cout<<c<<endl;
  }
  return 0;
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const int INF = 10000;



int main(){
	int Q;
	cin>>Q;
	REP(T,Q){
		long N;
		cin>>N;
		int cnt=0;
		set<long>st;
		while(N>=10){
			string str=toString(N);
			long nN=0;
			FOR(i,1,SZ(str)){
				nN=max(nN,toLong(str.substr(0,i))*toLong(str.substr(i)));
			}
			if(st.find(nN)!=st.end()){
				cnt=-1;break;
			}
			st.insert(nN);
			N=nN;
			cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}