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 <bits/stdc++.h>

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }

static inline int int_size(int n){ return (int)log10(n) + 1; }
static inline int split(int n, int s){ 
  int deli = (int)pow(10, s);
  return (n % deli) * (n / deli);
}

int main()
{
  rep(i, in()){
    int n = in();

    int count = 0;
    bool ok = true;
    set<int> vis;
    while (n > 9){
      int maxi = 0;
      count++;
      rep(j, int_size(n) - 1){
        maxi = max(maxi, split(n, j + 1));
      }
      if (vis.find(maxi) != vis.end()){
        ok = false;
        break;
      }
      else {
        vis.insert(maxi);
      }
      n = maxi;
    }
    if (ok){
      printf("%d\n", count);
    }
    else {
      printf("-1\n");
    }
  }
  return 0;
}

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

using namespace std;

int main()
{
  int q;
  cin >> q;
  while(1){
	if (q <= 0) break;
	int n ;
	cin >> n;
	int count = 0;
	string hoge;
	hoge = to_string(n);
	while(1){
	  int max = 0;
	  int l = hoge.length();
	  if(l <= 1) break;
	  int i;
	  
	  for (i = 1; i < l; i++) {
		string a,b;
		int c,d;
		a = hoge.substr(0,i);
		b = hoge.substr(i);
		// cout << a << endl;
		// cout << b << endl;
		c = stoi(a);
		d = stoi(b);
		if(max < c * d) max  = c * d;
		// cout << max << endl;	
	  }
	  
	  count++;
	  if(max >= 10) hoge = to_string(max);
	  else break;
	}
	cout << count << endl;
	q--;
  }  
  return 0;
}

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

int main(){
  int q,n,c;
  cin >> q;
  while(q--){
    cin >> n; c=0;
    for(;;){
      int m = -1,k = 10;
      if(n<10){
	cout << c << endl;
	break;
      }
      for(int i=0;i<5;i++){
	m=max(m,(n/k)*(n%k));
	k*=10;
      }
      n = m; c++;
    }
  }
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  int Q;
  cin >> Q;
  REP(i,Q) {
    int n;
    cin >> n;
    int ans = 0;
    while(n>9) {
      int p = 10;
      int next = 0;
      while(1) {
        if (n/p==0) break;
        int t = (n / p) * (n % p);
        next = max(next, t);
        p *= 10;
      }
      n = next;
      ++ans;
    }
    cout << ans << endl;
  }
}

C++: #include<iostream>
#define dump(a) cout << (#a) << "=" << a << endl
using namespace std;

int main() {
	int N;
	string num;

	cin >> N;

	for(int t=0;t<N;t++) {
		cin >> num;

		int cnt=0;
		int back_size=0;
		bool is_infre=false;
		while(true) {
			if (num.size() == 1) {
				is_infre=false;
				break;
			}
			else {
				if (num.size() == back_size) { //?????????????????´???????????¨???
					if (cnt > 1000000) { 
						//??±??????
						is_infre=true;
						break; 
					}
				}

				int max_num=0;
				for(int i=1;i<num.size();i++) {
					string left = num.substr(0,i);
					string right = num.substr(i,num.size()-i);
					max_num = max(max_num, stoi(left)*stoi(right));
				}
				num = to_string(max_num);
			}
			cnt++;
			back_size = num.size();
		}

		cout <<  (is_infre ? "-1" : to_string(cnt)) << endl;
	}
	
	return EXIT_SUCCESS;
}

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

template<class T, class U> T lexical_cast(const U &from) {
    stringstream ss;
    ss << from;
    T to;
    ss >> to;
    return to;
}

int main() {
    int Q; cin >> Q;
    while(Q--) {
        int N; cin >> N;
        int ans = 0;
        set<int> histo;
        while(N >= 10) {
            histo.insert(N);
            string s = lexical_cast<string>(N);
            vector<int> list;
            for(int i = 1; i < (int)s.length(); i++) {
                int left = lexical_cast<int>(s.substr(0, i));
                int right = lexical_cast<int>(s.substr(i));
                list.push_back(left * right);
            }
            N = *max_element(list.begin(), list.end());
            if(histo.count(N)) {
                ans = -1;
                break;
            }
            ans++;
        }
        cout << ans << endl;
    }
}