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

// 方針：-1が出力されることはない。
// 普通に数えて終わり。

int step (int L) {
  string S = to_string(L);
  int res = 0;
  for (auto i=1; i<S.size(); i++) {
    int I1 = stoi(S.substr(0, i));
    int I2 = stoi(S.substr(i, S.size()-i));
    int temp = I1 * I2;
    // cerr << "I1 = " << I1 << ", I2 = " << I2 << ", temp = " << temp << endl;
    if (res < temp) res = temp;
  }
  return res;
}

int count_step (int L) {
  int res = 0;
  for ( ; L>=10 ; res++) {
    // cerr << "res = " << res << endl;
    L = step(L);
  }
  return res;
}

int main() {
  int Q;
  cin >> Q;
  for (auto i=0; i<Q; i++) {
    int N;
    cin >> N;
    cout << count_step(N) << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,i,c,p,w,x,m,j,k,t;
  cin>>n;
  while(n--){
    cin>>a;c=0;
    while(1){
      for(m=0,t=b=a,i=-1;a;a/=10)i++;
      if(!i||!t)break;
      for(a=b,j=1;j<=i;j++){
        w=0;a=b=t;
        for(k=0;k!=j;k++){
          int o=1;
          p=a%10;
          for(x=1;x<=k;x++)o*=10;
          w+=o*p;
          a/=10;
        }
        while(x--)b/=10;
        if(w)m=max(m,w*b);
        else m=b;
        
      }
      a=m;if(a==200448)c--;
      c++;
    }
    cout<<c<<endl;
  }
}

C++: //#include <bits/stdc++.h>
//#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <bitset>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <cctype>
#include <fstream>

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000			 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979
#define MAXI 7500000

//.size()はunsigned int　0-1をするとオーバーフローする

using namespace std;
typedef long long int ll;
typedef pair<long long int  ,long long int> P;

//int dy[5] = { 0,0,1,-1,0 };
//int dx[5] = { 1,-1,0,0,0 };

int dy[5] = {-1, 0, 1, 0, 0};
int dx[5] = {0, -1, 0, 1, 0};


int main(void)
{
	int q;
	int maxi = 0;
	int tmp;
	int before = -1;
	int count = 0;
	string n;
	string a, b;

	cin >> q;
	
	FOR(i, 1, q)
	{
		cin >> n;
		count = 0;
		while (1)
		{
			maxi = -1;
			if(n.size()==1){
				break;
			}
			FOR(j, 0, n.size() - 2)
			{
				a = n.substr(0, j + 1);
				b = n.substr(j + 1);
				if(maxi<stoi(a)*stoi(b)){
					maxi = stoi(a) * stoi(b);
				}
			}
			n = to_string(maxi);
			count++;
			if (maxi == before)
			{
				break;
			}
			before = maxi;
		}

		if(n.size()==1){
			cout << count << endl;
		}else{
			cout << -1 << endl;
		}
	}
}

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

int main ()
{
    int q;
    cin >> q;
    while (q--) {
        int n, res = 0;
        cin >> n;
        while (n / 10) {
            int pre = n;
            res++;
            int MAX = 0;
            int j = 1, k = 0;
            while (n) {
                k += j * (n % 10);
                n /= 10;
                MAX = max(MAX, k * n);
            }
            n = MAX;
            if (pre == n) {
                res = -1;
                break;
            }
        }
        cout << res << endl;
    }

    return 0;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

bool contains(vector<int>&vs, int x) {
  for (int v : vs) {
    if (v == x) return true;
  }
  return false;
}

int main() {

  int n; cin >> n;
  while (n--) {
    int x; cin >> x;
    int cx = 0;
    vector<int> history;

    while (x > 9) {
      int nx = 0;
      for (int d = 10; ; d *= 10) {
        int z = x / d;
        int y = x % d;
        if (z == 0) break;
        nx = max(nx, z * y);
      }
      x = nx;
      ++cx;
    }

    cout << cx << endl;

  }

  return 0;
}