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<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<cassert>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<30
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;

int main(){
  int Q;
  string s;
  cin >> Q;
  while(Q-- > 0){
    cin >> s;
    int index = 0;
    int Mex = 0;
    
    while(true){
      if(s.length() == 1){
	cout << index << endl;
	break;
      }
      Mex = 0;
      rep(j,s.length()-1){
      int A,B;
      A = B = 0;
      int st = 0;
      if(s[st] == '0'){
	for(int i=0;s[i] == '0' && i<j;i++){
	  st++;
	}
      }
      assert(j-st+1 >= 0);
           if(st < s.length())A = (atoi)(s.substr(st,j-st+1).c_str());
	   //cout << "A = " << A << endl;
      st = j+1;
      if(s[st] == '0'){
	for(int i=j+1;s[i] == '0' && i<s.length()-1;i++){
	  st++;
	}
      }     
     
      assert(s.length()-st >= 0);
            if(st < s.length())B = (atoi)(s.substr(st,s.length()-st).c_str());
	    //cout << "B = " << B << endl; 
     Mex = max(Mex,A*B);

      }
      //cout << "mex = " << Mex << endl;
      stringstream ss;
      ss << Mex;
      ss >> s;
      //cout <<"new s = " << s << endl;

      index++; 
    }
  }
  return 0;
}

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

int main() {
  int Q; cin >> Q;
  while(Q--) {
    int N; cin >> N;
    int res = 0;
    set<int> s;
    while(N >= 10) {
      string n;
      {
        stringstream ss; ss << N;
        n = ss.str();
      }
      int maxi = -1;
      for(int i = 1; i < n.size(); ++i) {
        string a = n.substr(0, i);
        string b = n.substr(i);
        int x = atoi(a.c_str()) * atoi(b.c_str());
        maxi = max(maxi, x);
      }
      N = maxi;
      if(s.count(N)) {
        res = -1; break;
      }
      s.insert(N);
      ++res;
    }
    cout << res << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
double EPS=1e-10;
double EQ(double a,double b){
    return abs(a-b)<EPS;
}
void fast_stream(){
  std::ios_base::sync_with_stdio(0);
}
template<class T>
string IntToString(T num){
  string res;stringstream ss;ss<<num;
  return ss.str();
}
ll StringToInt(string &str){
  ll res=0;
  for(int i=0;i<(int)str.size();i++)
    res=(res*10+str[i]-'0');
  return res;
}

bool used[1000001];
int main(){
  int Q;
  ll N;
  cin>>Q;
  while(Q--){
    memset(used,0,sizeof(used));
    cin>>N;
    int ite=0;
    while(1){
      if(used[N]){
	cout<<-1<<endl;
	break;
      }
      if(N<10){
	cout<<ite<<endl;
	break;
      }
      used[N]=true;
      string s=IntToString(N);
      ll nxt=-1;
      for(int i=1;i<(int)s.size();i++){
	ll a=atoi(s.substr(0,i).c_str());
	ll b=atoi(s.substr(i).c_str());
	nxt=max(nxt,a*b);
      }
      N=nxt;
      ite++;
    }
  }

  return 0;
}

C++: #include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define _GLIBCXX_DEBUG

void printv(vector<int> v) {
  for (int i : v)
    cout << i << " ";
  cout << endl;
}

int main() {
  int q;
  cin >> q;
  rep(loop, q) {
    int n;
    cin >> n;
    int now = n;
    int ans = 0;
    while (now > 9) {
      string stNum = to_string(now);
			int numSize=stNum.size();
      int maxNum = 0;
      for (int i = 1; i < numSize; i++) {
        int num1 = stoi(stNum.substr(0, i));
        int num2 = stoi(stNum.substr(i, numSize - i));
        maxNum = max(maxNum, num1 * num2);
      }
      now = maxNum;
      ans++;
    }
    cout << ans << endl;
  }
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int solve(long long int num){
	long long int ret=0;
	for(long long int i=10;i<10000000;i*=10){
		ret=max(ret,(num/i)*(num%i));
	}
	return ret;
}

long long int q,n[105];
int main() {
	string s,t;
	cout << fixed << setprecision(18);
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>n[i];
	}
	for(int i=0;i<q;i++){
		long long int res=0;
		while(n[i]>=10){
			res++;
			n[i]=solve(n[i]);
		}
		cout<<res<<endl;
	}

}