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 <iostream>
using namespace std;

int main() {
	int i,N,m,d,s;
	d=10;
	cin >> N;
	for (int k=0; k<N; k++) {
		cin >> m;
		while (m>9) {
			i += 1;
			while (m % d != m) {
				int lower = m%d;
				int upper = (m-lower)/d;
				int mlp = lower * upper;
				if(s < mlp) s = mlp;
				d *= 10;
			}
			m = s;
			d=10;
			s=0;
		}
		cout << i << endl;
		i=0;
	}
}

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

using namespace std;

int cnt = 0;

void mulspl(int n) {
	int place = 0, tmp = n, i = 0;
	vector<int> sp(10);
	while (tmp > 0) {
		sp[i] = tmp % 10;
		tmp /= 10;
		place++, i++;
	}
	if (place > 1) {
		int maxi = 0;
		for (int i = 1; i < place; ++i) {
			int x = (n / (int)pow(10, i)) * (n % (int)pow(10, i));
			maxi = max(maxi, x);
		}
		cnt++;
		mulspl(maxi);
	}
}

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

	return 0;
}

C++: 
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2424

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

bool step1(string N){
	return N.length() == 1;
}

string step2(string N)
{
	int n = N.length();

	string num1,num2;
	int max_value=0;
	REP(i,1,n)
	{
		num1 = N.substr(0,i);
		num2 = N.substr(i);
		int tmp = stoi(num1) * stoi(num2);
		max_value = max(max_value, tmp);
	}

	return to_string(max_value);
}

int main()
{
	int Q;
	cin >> Q;

	string N;
	rep(nth,Q)
	{
		cin >> N;
		string tmp=N;
		int count=0;
		while(true)
		{
			if(step1(N)){ cout << count << endl; break; }
			N = step2(N);
			if(N == tmp){ cout << -1 << endl; break; }
			tmp = N;
			count++;
		}
	}

	return 0;
}

C++: #include <stdio.h>
#include <set>
#include <math.h>
#include <algorithm>
using namespace std;

int maxNum(int N){
  int maxInt=0,i=1,a,b;
  int lenN=(int)log10(N)+1;
  while (i<lenN){
    a=N/(int)pow(10.0,(double)lenN-i);
    b=N%(int)pow(10.0,(double)lenN-i);
    maxInt=max(maxInt,a*b);
    i++;
  }
  return maxInt;
}

int main(){
  int Q,cnt,N;
  scanf("%d",&Q);
  for (int i=0;i<Q;i++){
    set<int> S;
    scanf("%d",&N);
    cnt=0;
    while (true){
      set<int>::iterator iti=S.find(N);
      if (N<10){
        printf("%d\n",cnt);
        break;
      }else if (iti!=S.end()){
        printf("-1\n");
        break;
      }else{
        S.insert(N);
        N=maxNum(N);
        cnt++;
      }
    }
  }
  return 0;
}

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

using namespace std;

int main(){
	int q;
	cin >> q;
	for(int i = 0; i < q; i++){
		int n;
		int cnt = 0;
		cin >> n;
		while(n >= 10){
			int m = 0;
			int a = n;
			for(int j = 1; j < log10(n); j++){
				int k = pow(10,j);
				m = max(m,(n/k)*(n%k));
			}
			n = m;
			if(a == n){
				cnt = -1;
				break;
			}
			cnt++;
		}
		cout << cnt << endl; 
	}
	return 0;
}

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

int solve(int x)
{
	int num = x;
	int count = 0;

	while (num / 10 != 0) {
		int maxx = 0;
		for (int i = 1; num / i != 0; i *= 10) {
			int temp1 = num / i;
			int temp2 = num%i;

			maxx = max(maxx, temp1*temp2);
		}
		num = maxx;
		count++;
	}

	return count;
}

int main()
{
	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;

		cout << solve(x) << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,i,c,p,w,x,m,j,k,t;
  cin>>n;
  while(n--){
    cin>>a;c=0;
    while(1){
      for(m=0,t=b=a,i=-1;a;a/=10)i++;
      if(!i)break;
      for(a=b,j=1;j<=i;j++){
        w=0;a=b=t;
        for(k=0;k!=j;k++){
          int o=1;
          p=a%10;
          for(x=1;x<=k;x++)o*=10;
          w+=o*p;
          a/=10;
        }
        while(x--)b/=10;
        if(w)m=max(m,w*b);
        else m=b;
      }
      a=m;
      c++;
    }
    cout<<c<<endl;
  }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

string IntToString(ll int number){
  stringstream ss;
  ss << number;
  return ss.str();
}

string tmp;
string tmp2;

int main(){
	int q,cnt;
	cin >> q;
	REP(i,q){
		
		cin >> tmp;
		tmp2 = tmp;
		cnt = 0;
		while(tmp.size()!=1){
			int mmax = -1;
			FOR(i,1,tmp.size()){
				string st1,st2;
				FOR(j,0,i) st1 += tmp[j];
				FOR(j,i,tmp.size()) st2 += tmp[j];
				mmax = max(mmax,stoi(st1)*stoi(st2));
			}
			cnt++;
			tmp = IntToString(mmax);
			/*if(tmp==tmp2){
				cnt = -1;
				break;
			}*/
		}
		
	cout << cnt << endl;
	}
	return 0;
}