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 <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	int n;cin>>n;
	rep(i,n){
		string s;
		cin>>s;
		if(s.size()==1){
			cout<<0<<endl;
			continue;
		}
		int t;
		convert(s,t);
		vint v(4000000,0);
		v[t]=1;
		int ans=0;
		while(1){
			int M=0;
			if(s.size()==1){
				break;
			}
			reep(i,1,s.size()){
				int x,y;
				convert(s.substr(0,i),x);
				convert(s.substr(i),y);
				M=max(M,x*y);
			}
			if(v[M]){
				ans=-1;
				break;
			}
			v[M]=1;
			convert(M,s);
			ans++;
		}
		cout<<ans<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

C++: #include<iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int main() {
  int q;
  cin >> q;
  while (q--) {
    int n, res = 0;
    cin >> n;
    while (n >= 10) {
      int mx = 0;
      for (int b = 10; b < n; b *= 10) {
	if (mx < (n / b) * (n % b)) {
	  mx = (n / b) * (n % b);
	}
      }
      n = mx;
      ++res;
    }
    cout << res << endl;
  }
  return 0;
}

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

int size (int n) {
    int s = 0;
    for (int j = 0;; j++) {
        if (n == 0) {
            s = 1;
            break;
        }
        else if ((pow(10, j)) <= n and n < (pow(10, j + 1))) {
            s++;
            break;
        }
        else s++;
    }
    return s;
}

int main () {
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int n;
        cin >> n;
        int res = 0;
        while (size(n) != 1) {
            vector<int> v;
            for (int j = 1; j < size(n); j++) {
                int a, b;
                a = n % int(pow(10, j));
                b = n / int(pow(10, j));
                v.push_back(a * b);
            }
            n = *max_element(v.begin(), v.end());
            res++;
        }
        cout << res << endl;
    }
}

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

using namespace std;

int table[1050000];

int solve(int x){
    if(table[x] != -2)return table[x];
    if(x < 10)return 0;
    int &res = table[x];
    res = -1;
    int p = 0;
    for(int i = 1;i <= x;i *= 10){
	p = max(p, (x / i) * (x % i));
    }
    res = solve(p);
    if(res >= 0)res++;
    return res;
}

int main(){
    int q, n;
    fill(table, table + 1050000, -2);
    cin >> q;
    while(q--){
	cin >> n;
	cout << solve(n) << endl;
    }
    return 0;
}

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

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

        int cnt = 0;
        set<int> rec;
        while(N >= 10) {
            int next = 0;
            for(int j=1; ; ++j) {
                int mod10j = N % static_cast<int>(pow(10, j));
                if(mod10j == N) {
                    break;
                } else {
                    next = max(next, N / static_cast<int>(pow(10, j)) * mod10j);
                }
            }
            N = next;
            if(rec.count(N) == 1) {
                cnt = -1;
                break;
            } else {
                rec.insert(N);
                cnt += 1;
            }
        }
        cout << cnt << endl;
    }
}