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++: /*
 * Kakezan
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2424
 */

#include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;

int main() {
  int n;
  cin >> n;
  REP(_, n){
    string m;
    cin >> m;
    int cnt = 0;
    while(m.length() > 1) {
      cnt ++;
      int ma = 0;
      FOR(i, 1, m.length()){
        int a = stoi(m.substr(0, i));
        int b = stoi(m.substr(i, m.length() - i));
        // LOG("%d %d, %d\n", a, b, a * b);
        ma = max(ma, a * b);
      }
      m = to_string(ma);
      // LOG("%d \n", ma);
    }
    cout << cnt << endl;
  }
}

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

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for(int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for(ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

int q;

int main() {
	std::cin >> q;
	rep(i, q) {
		int n;
		std::cin >> n;
		int cnt = 0;
		while (true) {
			int max = 0;
			std::string str = std::to_string(n);
			REP(i, 1, str.size() + 1) {
				max = std::max(max, std::atoi(str.substr(0, i).c_str()) * std::atoi(str.substr(i, str.size() - i).c_str()));
			}
			if (max != 0) {
				n = max;
				cnt++;
			}
			else break;
		}
		std::cout << cnt << std::endl;
	}

	return 0;
}

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

using namespace std;

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

        int count = 0;
        auto process = [](int n) {
            auto s = to_string(n);
            if (s.size() == 1) {
                return n;
            }
            int max_ = 0;
            for (int j = 0; j < s.size() - 1; ++j) {
                auto l = stoi(s.substr(0, j + 1));
                auto r = stoi(s.substr(j + 1));
                max_ = max(max_, l * r);
            }
            return max_;
        };
        while (true) {
            if (0 <= n && n <= 9) {
                break;
            }
            else if (n < 0) {
                count = -1;
                break;
            }
            n = process(n);
            count += 1;
        }
        cout << count << endl;
    }
}

C++: #include <string>
#include <cstdio>
#include <cstdlib>
char S[9];
int main(){
	int q,n,r,i;
	for(scanf("%d",&q);q--;printf("%d\n",r))
		for(r=0,scanf("%d",&n);n>9;r++){
			sprintf(S,"%d",n);n=0;
			std::string s=S;
			for(i=1;i<s.length();i++)n=std::max(n,atoi(s.substr(0,i).c_str())*atoi(s.substr(i).c_str()));
		}
}

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

int main(){
  int q;
  int n;
  int count;
  cin >> q;
  for(int i=0;i<q;i++){
    cin >> n;
    count=0;
    while(n/10>=10){
      count+=1;
      int max=0;
      for(int j=1;j<6;j++){
	int t=pow(10,j);
	int tmp=(n/t)*(n%t);
	if(max<tmp) max=tmp;
      }
      n=max;
    }
    cout<<count<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <map>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)

typedef long long ll;
typedef pair<int, int> pii;

int nl(int n) { return n==0?0:1+nl(n/10); }
int number_of_length(int n) { return n==0?1:nl(n); }
int ipow(int n, int r) { return r==0?1:n*ipow(n, r-1); }

void divide(int d, int t, int *l, int *r)
{
	*l = t/ipow(10, d);
	*r = t%ipow(10, d);
}

int calc(int t)
{
	int cnt = 0;

	vector<int> vs;
	for (;;) {
		sort(vs.begin(), vs.end());
		if (binary_search(vs.begin(), vs.end(), t)) {
			return -1;
		}
		vs.push_back(t);
		if (t < 10) return cnt;
		int ans = 0;
		REPI(d, 1, number_of_length(t)-1) {
			int l, r;
			divide(d, t, &l, &r);
			ans = max(ans, l*r);
		}
		cnt++;
		t = ans;
	}
}

int main(void)
{
	int n;

	cin >> n;
	rep(TTT, n) {
		int t;
		cin >> t;
		cout << calc(t) << endl;
	}
	return 0;
}