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 <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
#define NUM 1000000
typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int dp[NUM+1];

int dfs(int n) {
    if (dp[n] != -1) return dp[n];
    if (n < 10) return 0;
    int ma = 0;
    int digit = 0, tmp = n;
    while (tmp) {
        tmp /= 10;
        digit++;
    }
    for (int i = 1; i < digit; i++) {
        int pow = 1;
        for (int j = 0; j < i; j++) pow *= 10;
        ma = max(ma, ((n%pow) * (n/pow)));
    }
    if (ma == n) return dp[n] = INF;
    else return dp[n] = dfs(ma) + 1;
}

int main(void) {
    for (int i = 0; i <= NUM; i++) dp[i] = -1;
    int N;
    cin >> N;
    while (N--) {
        int p;
        cin >> p;
        int ans = dfs(p);
        if (ans >= INF) cout << -1 << endl;
        else cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

int n;
string str;
set<int> data;

int solve(){
   for(int cnt=0;;cnt++){
      if(str.size() == 1) return cnt;
      int tmp = atoi(str.c_str());
      if(data.find(tmp) != data.end()) break;
      data.insert(atoi(str.c_str()));
      int valM = 0;
      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());
	 valM = max(valM, a * b);
      }
      str = "";
      if(valM == 0) str += '0';
      else{
	 while(valM){
	    str += (char)(valM % 10) + '0';
	    valM /= 10;
	 }
	 reverse(str.begin(), str.end());
      }
   }
   return -1;
}

main(){
   cin >> n;
   for(int i=0;i<n;i++){
      data.clear();
      cin >> str;
      cout << solve() << endl;
   }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  int n,m,s,max,cnt;
  string  str,str1;
  cin>>n;
  for(int i=0;i<n;i++){
     cin>>str;
     cnt=0;
     while(1){
       if(str.size()==1) break;
       str1=str[0],max=0;
     for(int j=0;j<str.size()-1;j++){
       if(j>0) str1+=str[j];
       m=stoi(str1),s=stoi(&str[j+1]);
       if(max<m*s) max=m*s;
     }
     str=to_string(max),cnt++;
     }
     cout<<cnt<<endl;    
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
string itos(int a){
  string s="";
  while(a){
    s=(char)(a%10+'0')+s;
    a/=10;
  }
  if(s=="")s="0";
  return s;
}
int main(){
  int n;
  cin>>n;
  while(n--){
    string s;
    cin>>s;
    int co=0;
    while(s.size()!=1){
      co++;
      int maxi=0;
      rep(i,s.size()-1){
	string a=s.substr(0,i+1);
	string b=s.substr(i+1);
	maxi=max(maxi,atoi(&a[0])*atoi(&b[0]));
      }
      s=itos(maxi);
    }
    cout<<co<<endl;
  }
}

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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

const double eps = 1e-10;
const int MOD = 1000000007;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, s.size()) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int digit(int n) {
  int cnt = 0;
  while(n > 0) {
    n /= 10;
    cnt++;
  }
  return cnt;
}

int pow(int a, int b) {
  int ans = 1;
  REP(i, b) {
    ans *= a;
  }
  return ans;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int q; cin >> q;
  REP(i, q) {
    int r; cin >> r;
    map<int, bool> sel;
    int next = r;
    int cnt = 0;
    while(1) {
      if(sel[next]) {
        cout << -1 << endl;
        break;
      }
      if(next / 10 == 0) {
        cout << cnt << endl;
        break;
      }
      sel[next] = true;
      int ma = 0;
      FOR(i, 1, digit(next)) {
        ma = max(ma, (next / pow(10, i)) * (next % pow(10, i)));
      }
      next = ma;
      cnt++;
    }
  }  
}

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

using namespace std;

int next(int n)
{
    ostringstream oss;
    oss << n;
    string str = oss.str();
    int mmax = 0;
    int lim = str.size();
    for(int i=1; i<lim; i++)
    {
        stringstream ss1(str.substr(0, i)), ss2(str.substr(i));
        int x, y;
        ss1 >> x;
        ss2 >> y;
        mmax = max(mmax, x*y);
    }
    return mmax;
}

int main()
{
    int n;
    cin >> n;
    while(n--)
    {
        int r;
        cin >> r;
        set<int> already;
        for(int t=0; ; t++)
        {
            if(r<10)
            {
                cout << t << endl;
                break;
            }
            if(already.find(r)!=already.end())
            {
                cout << -1 << endl;
                break;
            }
            already.insert(r);
            r = next(r);
        }
    }
}