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 <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 
#include <sstream>
#include <algorithm>
#include <cstdlib>

using namespace std;

int func(string str, int cnt);

string InToString(int number);

int main()
{
	int Q, ans;
	string str;
	cin >> Q;
	for(int i = 0; i < Q; i++){
		cin >> str;
		ans = func(str, 0);
		cout << ans << endl;
		}
	return 0;
}

int func(string str, int cnt)
{
	int l = (int)str.size();
	if(l < 2) return cnt;
	else {
		string a, b;
		int c, d, e;
		int max = 0;
		for(int j = 1; j < l; j++){
			a = str.substr(0, j);
			b = str.substr(j, l-j);
			c = stoi(a);
			d = stoi(b);
			e = c * d;
			if(e > max) max = e;
		}
		cnt++;
		return func(InToString(max), cnt);
	}
}

string InToString(int number)
{
	stringstream ss;
	ss << number;
	return ss.str();
}

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

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        int a;
        set<int> s;
        bool f = false;
        cin >> a;

        int j;
        for(j=0;a>=10;j++){
            int cnt = 0;
            for(int k=10;k<=a;k*=10) cnt = max(cnt,(a/k)*(a%k));
            if(s.find(cnt) != s.end()){
                f = true;
                break;
            } else {
                a = cnt;
                s.insert(cnt);
            }
        }
        cout << (f ? -1 : j) << endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int const MOD = 1000000007;

int main() {
    int q; cin >> q;
    rep(i,0,q) {
        string s; cin >> s;
        int cnt = 0;
        while(1) {
            // cout << s << endl;
            if(s.length() == 1) break;
            else {
                int ma = 0;
                rep(i,1,s.length()) {
                    string s1 = s.substr(0,i);
                    string s2 = s.substr(i,s.length() - i);
                    ma = max(ma, atoi(s1.c_str()) * atoi(s2.c_str()));
                }
                s = to_string(ma);
                cnt++;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

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

int main(void) {

    int Q; cin >> Q;
    string N;
    for (int i = 0; i < Q; i++) {
        cin >> N;

        set<int> hist;
        hist.insert(stoi(N));

        int cnt = 0;
        while (N.size() > 1) {
            int next_N = -1;
            for (int j = 1; j < N.size(); j++) {
                int n1 = stoi(string(N.begin(), N.begin()+j));
                int n2 = stoi(string(N.begin()+j, N.end()));
                next_N = max(next_N, n1*n2);
            }

            auto r = hist.insert(next_N);
            if (!r.second) {
                cnt = -1;
                break;
            }

            N = to_string(next_N);
            cnt++;
        }

        cout << cnt << endl;
    }


    return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;



int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	int Q;
	cin>>Q;
	while(Q--){
		int N;
		cin>>N;
		rep(i,INF){
			sst st;
			st<<N;
			string s=st.str();
			if(sz(s)==1){
				cout<<i<<endl;
				break;
			}
			int next=0;
			rep(i,sz(s)-1){
				string t=s.substr(0,i+1);
				string u=s.substr(i+1);
				iss is1(t),is2(u);
				int T,U;
				is1>>T;
				is2>>U;
				next=max(next,T*U);
			}
			N=next;
		}
	}
}

C++: // 2424_Kakezan.cpp
// 途中
#include <bits/stdc++.h>
using namespace std;

int solve(int n, int cnt){
  if(n<10) return cnt;

  int m=-1;
  for(int i=10;n/i>0;i*=10)
    m=max(m, (n/i)*(n%i));

  cnt++;
  return solve(m,cnt);
}
int main() {
  int q,n;
  cin>>q;

  for(int i=0;i<q;++i) {
    cin>>n;
    cout<<solve(n,0)<<endl;
  }

  return 0;
}