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>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

int change_to_i(string s){
    stringstream ss; int k;
    ss << s; ss >> k;
    return k;
}
string change_to_s(int k){
    stringstream ss; string s;
    ss << k; ss >> s;
    return s;
}

signed main(){
    int q;
    cin >> q;
    rep(x, 0, q){
        string s;
        cin >> s;
        for(int ans = 0;; ans++){
            if(s.size() == 1){
                cout << ans << endl;
                break;
            }
            if(ans > 1000000){
                cout << -1 << endl;
                break;
            }
            string t1, t2;
            int MAX = 0, n1, n2;
            rep(i, 1, s.size()){
                t1 = s.substr(0, i);
                t2 = s.substr(i, s.size() - i);
                n1 = change_to_i(t1);
                n2 = change_to_i(t2);
                int tmp = n1*n2;
                //cout << t1 << ' ' << t2 << endl;
                //cout << n1 << ' ' << n2 << ' ' << tmp << endl;
                MAX = max(MAX, tmp);
            }
            s = change_to_s(MAX);
            //cout << ' ' << MAX << ' ' << s << endl;
        }
    }
}

C++: #include<iostream>
#include<string.h>
#include<string>
#include<sstream>
#include<cstdio>
#include<stdlib.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> pii;

int main()
{
  int q;
  cin>>q;
  int i,j,k,num;
  rep(i,q){
    string s;
    cin>>s;
    rep(num,100000){
      if(s.size()==1){
	cout<<num<<endl;
	break;
      }
      ll ans=0LL;
      rep(j,s.size()-1){
	int n1=0,n2=0;
	int a=1;
	for(k=j;k>=0;k--){
	  n1+=a*(s[k]-'0');
	  a*=10;
	}
	a=1;
	for(k=s.size()-1;k>j;k--){
	  n2+=a*(s[k]-'0');
	  a*=10;
	}
	ans=max(ans,(ll)n1*n2);
      }//rep
      stringstream ss;
      ss<<ans;
      s=ss.str();
    }
    if(num>100000)cout<<"-1"<<endl;
  }
}

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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9

using namespace std;

int main(){
  int q;
  cin >> q;
  REP(i, q){
    int n;
    cin >> n;
    int res = 0;
    while(n >= 10){
      int divisor = 10;
      int maxim = 0;
      REP(j, 6){
        if(divisor >= n) break;
        maxim = max(maxim, (n / divisor) * (n % divisor));
        divisor *= 10;
      }
      n = maxim;
      res++;
      // cout << n << endl;
      if(res > 100) { res = -1; break; }
    }
    cout << res << endl;
  }
}

C++: #include<iostream>
#include<map>
using namespace std;

int main(){
  map<int,bool> h;
  int q,n,cnt;
  cin >> q;
  while(q--){
    cin >> n;
    cnt = 0;
    h.clear();
    h[n] = true;
    while(true){
      int m = -1, k = 10;
      cnt++;
      for(int i=0;i<5;i++){
	m = max(m,(n/k)*(n%k));
	k *= 10;
      }
      if(h[m]){
	cout << -1 << endl;
	break;
      }
      if(m<10){
	cout << cnt << endl;
	break;
      }
      n = m;
      h[m] = true;
    }
  }
}

C++: #include<iostream>
using namespace std;

int main(){
  int q,r,a;
  cin>>q;

  for(int i=0;i<q;i++){
    cin>>r;
    int j=10,count=1;
    a=r;

    while(1){
      a/=j;
      if(a==0)break;
      count++;
    }
    int count1=0;
    while(1){
      int max=0;
      j=10; 
      if(r/j==0)break;
      
      for(int k=1;k<count;k++){
	a=(r/j)*(r%j);
	if(max<a)max=a;
	j*=10;
      }

      r=max;
      count1++;
    }

    cout<<count1<<endl;
  }

  return 0;
}

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

int foo(int x, int n){
  if(x < 10) return 0;
  int ma = 0, temp;
  for(int i = 10;x/i; i*=10)
    ma = max((x/i)*(x%i),ma);//cout<<ma<<" "<<n<<" "<<x<<endl;
  temp = foo(ma, n+1)+1;
  if(temp == -1 || ma == x) return -1;
  else return temp;
}

int main(){
  int Q, N;
  cin>>Q;
  for(int i = 0; i < Q; i++){
    cin>>N;
    cout<<foo(N,0)<<endl;
  }
  
  return 0;
}

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

using namespace std;

template<typename T> inline void chmax(T& t, T f){if(t < f)t = f;}

int main(){
    int Q;
    cin >> Q;
    while(Q--){
        int N, R = 0;
        cin >> N;
        set<int> u{N};
        for(; 10 <= N; ++R){
            string s = to_string(N);
            N = 0;
            for(int i=1; i<(int)s.size(); ++i){
                chmax(N, stoi(s.substr(0, i)) * stoi(s.substr(i)));
            }
            if(!u.insert(N).second)N = -1;
        }
        cout << (N < 0? N: R) << '\n';
    }
    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000

int proc(int n){
  int res=0;
  for(int i=10; i<=1000000; i*=10){
    res = max(res, (n/i)*(n%i));
  }
  return res;
}

int main(){
  int q;
  cin>>q;
  rep(repeat, q){
    int n;
    scanf("%d", &n);

    int res=0;
    while(n>9){
      n = proc(n);
      res++;
    }
    cout<<res<<endl;
  }
  return 0;
}