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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll q;
  string s = "024";
  cin >> q;
  rep(i,q){
    bool f = true;
    ll n = 0;
    cin >> s;
    while(s.size() != 1){
      set<ll> st;
      ll ans = -1;
      REP(k,1,s.size()){
        string l = s,r = s;
        l.resize(k);
        r = r.substr(k);
        ll n2 = ston(l,1) * ston(r,1);
        ans = max(ans,n2);
        if(!st.insert(n2).se ){
          cout << -1 << endl;
          f = false;
          k = 1e9;
          break;
        }
      }
      s = to_string(ans);
      ++n;
    }
    if(f)
    cout << n << endl;
  }
  return 0;
}

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

int main()
{
	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++)
	{
		int N;
		cin >> N;
		int count = 0;
		set<int> intSet;
		while (N > 9 && intSet.find(N) == intSet.end())
		{
			intSet.insert(N);
			count++;
			string s;
			stringstream strStream;
			strStream << N;
			s = strStream.str();
			int maxV = 0;
			for (int i = 1; i < s.size(); i++)
			{
				string ss = s.substr(0, i);
				string sss = s.substr(i, s.size());
				cout << ss.data() << " : " << sss.data() << endl;
				int ii = atoi(ss.c_str());
				int iii = atoi(sss.c_str());
				maxV = max(maxV, ii * iii);
			}

			N = maxV;
		}
		if (intSet.find(N) != intSet.end())
		{
			cout << -1 << endl;
		}
		else
		{
			cout << count << 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<set>
#include<sstream>

using namespace std;

int str2int(string str) {
  stringstream ss;
  int ans;
  ss<<str;
  ss>>ans;
  return ans;
}

string int2str(int num) {
  stringstream ss;
  string str;
  ss<<num;
  ss>>str;
  return str;
}

int main() {
  int q;
  cin>>q;
  for(int i=0; i<q; i++) {
    string n;
    set<int> alreadyUsed;
    cin>>n;

    int ans = 0;
    while(true) {
      if(str2int(n)/10 == 0) { // 1桁なら終了
	break;
      }
      set<int>::iterator itr = alreadyUsed.find(str2int(n));
      if(itr != alreadyUsed.end()) { // 同じ値が2度出たら無限ループ
	ans = -1;
	break;
      }
      alreadyUsed.insert(str2int(n));
      int tmpMax = -1;
      /*
      for(int j=0; j<n.length(); j++) {
	string front, back;
	front += n[j];
	for(int k=j+1; k<n.length(); k++) {
	  back += n[k];
	}
	int tmp = str2int(front)*str2int(back);
	cout<<"tmpIs "<<tmp<<endl;
	if(tmp > tmpMax) {
	  tmpMax = tmp;
	}
      }
      */
      for(int j=1; j<n.length(); j++) {
	string front, back;
	for(int k=0; k<j; k++) {
	  front += n[k];
	}
	for(int k=j; k<n.length(); k++) {
	  back += n[k];
	}
	int tmp = str2int(front)*str2int(back);
	if(tmp > tmpMax) {
	  tmpMax = tmp;
	}
      }
      n = int2str(tmpMax);
      //cout<<"next is "<<n<<endl;
      ans++;
    }
    cout<<ans<<endl;
  }
}

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

using namespace std;

int main() {
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int value, source_value, count = 0;

		cin >> source_value;
		value = source_value;

		while (value >= 10) {
			count++;

			string str = to_string(value);
			int len = str.size(), max = 0;

			for (int j = 1; j < len; j++) {
				int temp1, temp2;

				temp1 = stoi(str.substr(0, j));
				temp2 = stoi(str.substr(j));

				if (max < temp1 * temp2) {
					max = temp1 * temp2;
				}
			}

			value = max;

			if (value == source_value) {
				cout << -1 << endl;
				goto TO;
			}
		}

		cout << count << endl;
	TO:;
	}

	return 0;
}