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;

int Q;

int main(){
  cin >> Q;
  for(int i=0;i<Q;i++){
    set<int> F;
    string n; cin >> n;
    int cnt = 0;
    while( n.size() > 1 ){
      int mn = -1;      
      for(int i=1;i<n.size();i++){
        string a = n.substr(i), b = n.substr(0,i);
        int x = stoi(a);
        int y = stoi(b);
        mn = max( mn, x*y );
      }
      if( F.count( mn ) == 0 ) {
        cnt++;
        F.insert( mn );
        n = to_string( mn );
      } else {
        cnt = -1;
        break;
      }
    }
    cout << cnt << endl;
  }
}

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


void solve(string N){

	  int l = N.size();
	  int ans = 0;
	  while(l>1){
			int maxi = 0;
			for(int i=1; i<l; i++){
				  int pre = stoi( N.substr(0,i) );
				  int suf = stoi( N.substr(i,l-i) );
				  maxi = max(maxi,pre*suf);
			}
			N = to_string(maxi);
			l = N.size();
			ans++;
	  }
	  cout << ans << endl;

}


int main(){

	  int Q; cin >> Q;
	  for(int i=0; i<Q; i++){
			string N; cin >> N;
			solve(N);
	  }

}

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

int main() {

  long long int n, input;

  cin >> n;

  for ( long long int i = 0; i < n; i++ ) {

    cin >> input;

    if ( input < 10 ) {
      cout << 0 << endl;
      continue;
    }

    long long int ans = 1;

    while( true ) {

      long long int k = 0;

      for ( long long int j = 10; j <= input; j *= 10 ) {

	k = max( k, ( input / j ) * ( input % j ) );

      }

      input = k;

      if ( input < 10 ) break;

      ans++;

    }

    cout << ans << endl;

  }

  return 0;

}

C++: #include <bits/stdc++.h>
int e,n,c,k,i;
using namespace std;
int main() {
  cin>>e;
  while(e--){
    cin>>n;
    c=0;
    while(n>9){
      int m=0,b=1;
      for(c++,i=0;i<5;i++){
        b*=10;
        k=(n/b)*(n%b);
        if(k>m)m=k;
      }
      n=m;
    }
    cout<<c<<endl;
  }
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for(int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for(ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

int q;

int main() {
	std::cin >> q;
	rep(i, q) {
		int n;
		std::cin >> n;
		int cnt = 0;
		while (true) {
			int max = 0;
			std::string str = std::to_string(n);
			if (str.size() == 1)break;
			REP(i, 1, str.size()) {
				max = std::max(max, std::atoi(str.substr(0, i).c_str()) * std::atoi(str.substr(i, str.size() - i).c_str()));
			}
			n = max;
			cnt++;
		}
		std::cout << cnt << std::endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
int N;
int R[100];
int solve(int m){
	int res=0;
	int mul=1;
	for(int i=0;i<6;i++){
		res=max(res,(m/mul)*(m%mul));
		mul*=10;
	}
	return res;
}
int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		map<int,int>M;
		scanf("%d",&R[i]);
		if(R[i]<10){
			printf("0\n");
			goto aaa;
		}
		M[R[i]]++;
		while(true){
			R[i]=solve(R[i]);
			if(R[i]<10){
				break;
			}
			M[R[i]]++;
			if(M[R[i]]==2){
				printf("-1\n");
				goto aaa;	
			}
		}
		printf("%d\n",M.size());
		aaa:;
	}
}

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

#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m);i>=(int)(n);--i)
#define debug(x) cout << #x << "=" << (x) << endl;

template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end

void solve(){
  int q;
  cin >> q;
  while(q--){
    int num,ct=0;
    cin >> num;
    while(num>=10){
      int ma=0,digit=0,n=num;ct++;
      while(n!=0)
      {digit++;n/=10;}
      int p10=1;
      for(int i=1;i<digit;i++)
      {
        p10*=10;
        ma=max(ma,num%p10*(num/p10));
      }
      if(ma==num){cout << -1 << endl;break;}
      num=ma;
    }
    cout << ct << endl;
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}