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 <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <sstream>
using namespace std;

string toString(int n){
  ostringstream os;
  os << n;
  return os.str();
}

int main(){
  int Q;
  string N;

  cin >> Q;
  while(Q--){
    cin >> N;  
    int i;
    for(i = 0 ; N.size() != 1 ; i++){
      int ans = -1;
      for(int j = 1 ; j < N.size() ; j++){
	string a = N.substr(0, j);
	string b = N.substr(j);
	ans = max(ans, atoi(a.c_str()) * atoi(b.c_str()));
      }
      N = toString(ans);
    }
    cout << i << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#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 pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

string IntToString(ll int number){
  stringstream ss;
  ss << number;
  return ss.str();
}

string tmp;
string tmp2;

int main(){
	int q,cnt;
	cin >> q;
	REP(i,q){
		
		cin >> tmp;
		tmp2 = tmp;
		cnt = 0;
		while(tmp.size()!=1){
			int mmax = -1;
			FOR(i,1,tmp.size()){
				string st1,st2;
				FOR(j,0,i) st1 += tmp[j];
				FOR(j,i,tmp.size()) st2 += tmp[j];
				mmax = max(mmax,stoi(st1)*stoi(st2));
			}
			cnt++;
			tmp = IntToString(mmax);
			if(tmp==tmp2){
				cnt = -1;
				break;
			}
		}
		
	cout << cnt << endl;
	}
	return 0;
}

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

string its(int n){
    stringstream s;
    s << n;
    
    return s.str();
}

int main(){
    string str;
    int n;
    
    cin >> n;
    while(n--){
        int cnt = 0;
        cin >> str;
        int len = str.size();
        
        while(len > 1){
            cnt++;
            int MAX = 0;
            for(int i = 0 ; i < len-1; i++){
                int a = atoi(str.substr(0,i+1).c_str());
                int b = atoi(str.substr(i+1,len-1).c_str());
                MAX = max(MAX,a*b);
            }
            str = "";
            str += its(MAX);
            len = str.size();
        }
        cout << cnt << endl;
    }
    
    return 0;
}

C++: #include <bits/stdc++.h>

#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main()
{
    int q;
    cin >> q;
    loop(q,i) {
        int n;
        cin >> n;
        int org = n;
        int ans = 0;
        while (n > 10) {
            string s = to_string(n);
            int m = 0;
            loop(s.size()-1, j) {
                int f = stoi(s.substr(0,j+1));
                int l = stoi(s.substr(j+1));
                m = max(m, f*l);
            }
            n = m;
            if (n == org) {
                ans = -1;
                break;
            }
            ans++;
        }
        cout << ans << endl;
    }
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
string itos(int n){
  stringstream ss;
  ss<<n;
  return ss.str();
}
int stoi(string s){
  return atoi(s.c_str());
}
int solve(int n){
  int ans = 0;
  while(true){
    string s = itos(n);
    if(s.size() <= 1) break;
    ans ++;
    int next = 0;
    for(int i = 1; i < s.size(); i++){
      string b = s.substr(0, i), e = s.substr(i);
      next = max(next, stoi(b) * stoi(e));
    }
    n = next;
  }
  return ans;
}

int main(){
  int N;
  while(cin>>N){
    while(N--){
      int n; cin>>n;
      cout<<solve(n)<<endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
using namespace std;

typedef ostringstream oss;
typedef istringstream iss;
typedef stringstream ioss;

int main(void) {
	int Q;
	cin >> Q;
	for (; Q; Q--) {
		long n;
		cin >> n;

		int cnt = 0;
		vector<long> his;
		
		while (n / 10) {
			if (find(his.begin(), his.end(), n) != his.end()) {
				cnt = -1;
				break;
			}
			
			int m = 0;
			ioss is;
			is << n;
			string str = is.str();
			for (int i = 1; i < str.size(); i++) {
				int a = atoi(str.substr(0, i).c_str());
				int b = atoi(str.substr(i).c_str());
				m = max(m, a * b);
			}

			n = m;
			cnt++;
		}

		cout << cnt << endl;

	}

	return 0;
}