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 <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>

typedef long long ll;

using namespace std;


int pow(int n, int k){
	int res = 1;
	for(int i=0;i<k;i++){
		res *= n;
	}
	
	return res;
}

bool solve(){
	
	int num;
	cin>> num;
	
	int ans = 0;
	while(num/10 != 0){
		int tmp = num;
		int k=0;
		while(tmp!=0){
			tmp /= 10;
			k++;
		}
		int res = -1;
		for(int i=0;i<k-1;i++){
			int n = num;
			int a = n / pow(10,i+1);
			int b = n % pow(10,i+1);
			res = max(res, a*b);
		}
		num = res;
		ans++;
	}
	
	cout<< ans<< endl;
	
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	
	int n;
	cin>> n;
	for(int i=0;i<n;i++) solve();

	return 0;
}

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

int solve(int n) {
    int d, next_n;

    int count = 0;

    while(n >= 10) {
        ++count;
        d = 1000000;
        next_n = 0;

        while(d > 0) {
            next_n = max(next_n, (n / d) * (n % d));
            d /= 10;
        }

        n = next_n;
    }

    return count;
}

int main() {
    int Q, N;
    cin >> Q;
    for(int i = 0; i < Q; ++i) {
        cin >> N;
        cout << solve(N) << endl;
    }
    return 0;
}

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

using namespace std;

int q,r;
int n;
int nmax;
int b;

void calc(){
	if(n/10==0)return;
	r++;
	int keta=0;
	b=0;
	for (int i = n; i > 0; i/=10){
		keta++;
	}
	for(int i=0; i<keta; i++){
		int x,y;
		int k=10;
		for (int j = 0; j < i; ++j){
			k*=10;
		}
		x=n/k;
		y=n%k;
		if(!b){
			nmax=x*y;
			b=1;
		}
		else{
			if(nmax<x*y){
				nmax=x*y;
			}
		}
	}
	n=nmax;
	//cout<<"n:"<<n<<endl;
	calc();
}

int main(){
	cin>>q;
	for (int i = 0; i < q; ++i){
		cin>>n;
		r=0;
		calc();
		cout<<r<<endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <cmath>
#include <algorithm>
#include <map>
#include <list>

using namespace std;

typedef pair<int, int> P;

/* 右からdigit桁と残りの積 */
/* 桁が大きい時は-1を返す */
int CutMul(int num, int digit) {
	int pow = 1;
	for(int i = 0; i < digit; i++) { pow *= 10; }
	if(pow > num) { return -1; }
	return (num / pow) * (num % pow);
}

int main()
{
	int q;
	cin >> q;
	while(q--) {
		bool inf = false;
		int n, a, count = 0;
		set<int> snum;
		cin >> n;
		a = n;
		snum.insert(n);
		while(1) {
			int max = 0;
			if(a / 10 == 0) break;
			for(int i = 1; ; ++i) {
				int m = CutMul(a, i);
				if(m == -1) break;
				max = (m > max ? m : max);
			}
			if(snum.find(max) != snum.end()) {
				inf = true;
				break;
			}
			++count;
			snum.insert(max);
			a = max;
		}
		cout << (inf ? n : count) << endl;
		snum.clear();
	}
	return 0;
}

C++: /*
 * 2424.cc: Kakezan
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef set<int> si;

/* global variables */

/* subroutines */

/* main */

int main() {
  int qn;
  cin >> qn;

  while (qn--) {
    int n;
    cin >> n;

    int tm = 0;
    si ns;

    while (n >= 10) {
      //printf("%d: %d\n", tm, n);
      
      if (ns.find(n) != ns.end()) {
	tm = -1;
	break;
      }
      ns.insert(n);
      
      int maxm = 0;
      for (int t = 10; t <= n; t *= 10) {
	int m = (n / t) * (n % t);
	if (maxm < m) maxm = m;
      }

      tm++;
      n = maxm;
    }

    printf("%d\n", tm);
  }
  return 0;
}

C++: #include <cstdio>
#include <cctype>
#include <utility>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int f(int n, int c) {
	if (n < 10)
		return c;
	int m = 0;
	for (int k = 10; n / k; k *= 10)
		m = max(m, (n / k) * (n % k));
	return f(m ,c + 1);
}

int main() {
	for (int Q = in(); Q; Q--)
		outl(f(in(), 0));
}