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<algorithm>
using namespace std;

const int MAX=1000000;

int func_num(int n){
  
  int count=0;

  while(1){
    int x=0;
    if(0<=n&&n<=9) break;
    for(int i=10;i<=MAX;i*=10){
      if(n/i==0) break;
      x=max(x,(n/i)*(n%i));
    }
    n=x;
    count++;
  }
  return count;
}

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

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
using namespace std;
int n;
main()
{
	cin>>n;
	for(;n--;)
	{
		int a;cin>>a;
		int cnt=0;
		while(a>=10)
		{
			int nexta=0;
			for(int i=10;i<=a;i*=10)
			{
				int now=a%i*(a/i);
				nexta=max(nexta,now);
			}
			a=nexta;
			cnt++;
		}
		cout<<cnt<<endl;
	}
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<queue>	

using namespace std;

namespace MyLib {
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long
}
using namespace MyLib;

int ten[10];
int main() {
	int q;
	int r;
	int count;
	ten[0] = 1;
	REP(i, 8)
		ten[i + 1] = ten[i] * 10;
	cin >> q;
	REP(i, q) {
		cin >> r;
		if (r == 1000000) {
			cout << 1 << endl;
			break;
		}
		for (count = 0;; count++) {
			if (r < 10)
				break;
			int ma = 0;
			REP(j, 6) {
				int k = r / ten[j];
				int s = r - (r / ten[j])*ten[j];
				ma = max(ma, k*s);

			}
			r = ma;

		}
		cout << count << endl;



	}



	return 0;
}

C++: #include <stdio.h>
#include <math.h>
#include <vector>

//FILE *in = freopen("2424.txt", "r", stdin);
//FILE * out = freopen("outputA.txt", "w", stdout);


int main()
{
	int n, count, cut;
	int num, front, back, max, now;
	std::vector<int> prev;

	while (scanf("%d", &n) > 0){
		for(int i = 0; i < n; i++){
			scanf("%d", &num);
			max = 0;
			count = 0;
			if(num < 10)
			{
				printf("%d\n", count);
				continue;
			}
			while(num > 10){
				count++;
				back = 0;
				cut = 0;
				max = 0;
				while((front = num / 10) > 0){
					for(int i = 1; i <= cut; i++)
						back *= 10;
					back += (num%10);
					now = back * front;
					if(max < now)
						max = now;
					num/=10;
				}
				num = max;
				if(prev.size() != 0){
					for(int i = 0; i < prev.size(); i++)
						if(num == prev.at(i))
						{
							count = -1;
							goto out;
						}
				}
				prev.push_back(num);

			}
			out:
			printf("%d\n", count);
			prev.clear();
		}
	}
	return 0;
}

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

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

using namespace std;

int max_multi(int x)
{
	int maximum = 0;
	int y = 1;
	rep(i, 5){
		int a, b;
		y *= 10;
		a = x / y;
		b = x - a * y;
		maximum = max(maximum, a * b);
	}
	return maximum;
}

int main(void)
{
	int Q;
	cin >> Q;
	rep(i, Q){
		int N, cnt = 0;
		cin >> N;
		//Nが一桁になるまで繰り返す
		while(N >= 10){
			N = max_multi(N);
			cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <sstream>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;

bool T[1000001];

string kakezan(string s)
{
  int m = -1;
  for(int i = 1; i < s.size(); i++){
    m = max(m, atoi(s.substr(0,i).c_str()) * atoi(s.substr(i).c_str()));
  }
  ostringstream ostr;
  ostr << m;
  return ostr.str();
}

int main()
{
  int Q;
  cin >> Q;
  REP(i,Q){
    fill(T, T+1000001, false);
    string N;
    cin >> N;
    if(N.size() == 1){
      cout << "0" << endl;
      continue;
    }
    int ans = 0;
    string s = N;
    while(s.size() != 1){
      s = kakezan(s);
      if(T[atoi(s.c_str())]){
        cout << "-1" << endl;
        break;
      }
      T[atoi(s.c_str())] = true;
      ans++;
    }
    cout << ans << endl;
  }
}

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

using namespace std;

int search(int n) {
    int right = 0;
    int ord = 1;
    int ans = 0;
    while(n > 0) {
        right += ord * (n % 10);
        ord *= 10;
        n /= 10;
        ans = max(ans, n*right);
    }
    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int Q;
    cin >> Q;
    while(Q--) {
        int N;
        cin >> N;
        int cnt = 0;
        while(N >= 10) {
            N = search(N);
            ++cnt;
        }
        cout << cnt << endl;
    }
    return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  int Q; cin >> Q;
  while(Q--) {
    string s; cin >> s;
    int ans = 0;
    int j = 0;
    while(s.length() > 1) {
      int l = 0;
      int r = stoi(s);
      int cnt = l * r;
      FOR(i,0,(int)s.length()-1) {
        l *= 10;
        l += s[i] - '0';
        r %= (int)pow(10, s.length()-i-1);
        cnt = max(cnt, l * r);
      }
      s = to_string(cnt);
      j++;
      ans++;
      if(j == 100000) {
        cout << -1 << '\n';
        break;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}