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 REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

//-----------------------------------------------------------------------
int calc(int a){
    int res=0,k=10;
    REP(i,6){
        res=max(res,(a/k)*(a%k));
        k*=10;
    }
    return res;
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin>>n;
    REP(i,n){
        int a; cin>>a;
        int cnt=0;
        while(10<=a){
            a=calc(a);
            cnt++;
        }
        cout<<cnt<<endl;
    }
}

C++: #include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int main(){
	int q;
	cin >> q;
	while(q--){
		int n, cnt = 0;
		cin >> n;
		while(n > 9){
			char buf[20];
			sprintf(buf, "%d", n);
			string s = buf;
			n = -1;
			rep(i, s.size() - 1){
				n = max(n, atoi(s.substr(0, i + 1).c_str()) * atoi(s.substr(i + 1).c_str()));
			}
			cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

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

std::string next(std::string n) {
  std::string str1;
  std::string str2;
  long max = -1;
  for(int i = 1; i < n.size(); ++i) {
    str1 = str2 = "";
    for(int j = 0; j < i; ++j) {
      str1 += n[j];
    }
    for(int j = i; j < n.size(); ++j) {
      str2 += n[j];
    }
    max = std::max(max, stol(str1) * stol(str2));
  }
  return std::to_string(max);
}                   

int main() {
  int Q;
  std::cin >> Q;
  for(int i = 0; i < Q; ++i) {
    std::string N;
    std::cin >> N;
    int count = 0;
    for(;;) {
      if( N.size() == 1 ) {
        std::cout << count << std::endl;
        break;
      }
      std::string t = next(N);
      N = t;
      count += 1;
    }
  }
  return 0;
}

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

typedef long long ll;
int flag[10000000];

ll next(ll x){
  ll y=x%10;
  ll ret=0;
  ll cnt=10;
  x/=10;
  while(x!=0){
    if(ret<x*y)ret=x*y;
    y=(x%10)*cnt+y;
    x/=10;
    cnt*=10;
  }
  return ret;
}

int main(){
  int Q;
  cin>>Q;
  for(int i=0; i<Q; i++){
    memset(flag, 0, sizeof(flag));
    int N;
    cin>>N;
    ll cnt=0;
    while(true){
      flag[N]=1;
      if(N<10){cout<<cnt<<endl; break;}
      N=next(N);
      if(flag[N]==1){cout<<"-1"<<endl; break;}
      cnt++;
    }
  }
  return 0;
}

C++: 
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
using LL = long long;

int dp[1234567];

int main(){
    for(int i=10;i<=1000000;++i){
        int d=0;
        int val=i;
        while(val>0){
            val/=10;
            d++;
        }
        int ten=1;
        int maxval=0;
        for(int e=0;e<d-1;++e){
            ten*=10;
            int lo=i%ten;
            int hi=(i-lo)/ten;
            //dp[i]=max(dp[i],dp[lo*hi]+1);
            maxval=max(maxval,lo*hi);
            //assert(lo*hi<i);
            //cout<<dp[i]<<endl;
        }
        dp[i]=dp[maxval]+1;
    }
    int Q;
    cin>>Q;
    for(int i=0;i<Q;++i){
        int r;
        cin>>r;
        cout<<dp[r]<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main() {
  int q;
  cin>>q;
  REP(i,q){
    string str;
    cin>>str;
    int n=0;
    while(1){
      if(str.size() == 1) break;
      int mx = 0;
      REP(j,str.size()-1){
        int fwd=stoi(str.substr(0,j+1));
        int bwd=stoi(str.substr(j+1));
        mx = max(mx, fwd*bwd);
      }
      str = to_string(mx);
      ++n;
    }
    cout<<n<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define INF 1000000000

int main() {
	int Q;
	string N[101];
	cin >> Q;
	REP(i, 0, Q) cin >> N[i];

	REP(i, 0, Q) {
		int cnt = 0;
		string val = N[i];
		while (1) {
			if (val.size() == 1) {
				cout << cnt << endl;
				break;
			}
			if (cnt > 10000) {
				cout << -1 << endl;
				break;
			}

			int maxi = 0;
			REP(j, 1, val.size()) {
				int l = stoi(val.substr(0, j));
				int r = stoi(val.substr(j));
				maxi = max(maxi, l*r);
			}
			val = to_string(maxi);
			cnt++;
		}
	}

	return 0;
}