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;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int q;
	cin>>q;
	while(q--){
		int cnt=0;
		string s;
		cin>>s;
		while(s.size()!=1){
			ll mx=0;
			rep(i,s.size()-1){
				ll a=stoll(s.substr(0,i+1));
				ll b=stoll(s.substr(i+1));
				chmax(mx,a*b);
			}
			cnt++;
			s=to_string(mx);
		}
		cout<<cnt<<"\n";
	}
}

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

using namespace std;

int digit_check(int n){
  int digit = 0;
  while(n!= 0){
    n = n/10;
    ++digit;
  }
  return digit;
}

bool archive_check(vector< int >& archive, int n){
  for (int i = 0; i < archive.size(); ++i)
  {
    if (archive[i] == n)
    {
      return true;
    }
  }
  return false;
}

int solve(int n){
  vector<int> ans;
  vector<int> archive;
  int digit, mul, upper, low, max;
  int count ;
  count = 0;
  while (true){
    digit = digit_check(n);
    // cout << n << endl;
    if (archive_check(archive, n)){
      return -1;
    }
    if (digit == 1 || digit == 0){
      return count;
    }
    for (int i = 1; i < digit; ++i)
    {
      mul = 1;
      for (int j = 0; j < i; ++j)
      {
        mul = mul*10;
      }
      upper = n / mul;
      low = n - mul * upper;
      ans.push_back(upper * low);
    }
    max = ans[0];
    for (int i = 0; i < digit-1; ++i)
    {
      if (max < ans[i])
      {
        max = ans[i];
      }
    }
    n = max;
    ans.clear();
    count ++;
  }

}

int main(){
  int q, n;
  cin >> q;
  for (int i = 0; i < q; ++i)
  {
    cin >> n;
    cout << solve(n) << endl;
  }
}

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

int main()
{
	int Q;
	cin >> Q;
	for (int ite = 0; ite < Q; ite++) {
		long long int N,res = 0;
		cin >> N;
		while (N >= 10) {
			long long int max = 0;
			for (long long int i = 1; i <= N; i *= 10) {
				if (max < (N % i) * (N / i)) {
					max = (N % i) * (N / i);
				}
			}
			N = max;
			res++;
		}
		cout << res << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
void pkuassert(bool t){t=1/t;};

int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};

string i2s(ll a){
  stringstream ss;
  ss << a;
  return ss.str();
}

ll s2i(string a){
  ll t=0;
  FOR(it,a) t=t*10+*it-'0';
  return t;
}

ll next(ll a){
  string s=i2s(a);
  ll ret=0;
  rep(i,SZ(s)-1) ret=max(ret,s2i(s.substr(i+1))*s2i(s.substr(0,i+1)));
  return ret;
}

void solve(){
  ll n,cnt=0;
  cin >> n;
  while(n>=10){
    ++cnt;
    n=next(n);
  }
  cout << cnt << endl;
}

int main(int argc, char *argv[])
{
  int q;
  cin >> q;
  rep(i,q) solve();
  return 0;
}

C++: #include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  int q;
  cin >> q;
  REP(i,q){
    int n;
    cin >> n;
    int answer=0;
    while(n>=10){
      ++answer;
      int tmp=0;
      for(int d=10;d<n;d*=10)
	tmp=max(tmp,(n/d)*(n%d));
      n=tmp;
    }
    cout << answer << endl;
  }
  return 0;
}