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>
#include<cmath>

using namespace std;

long Q, N;

long multip(long n, long keta){
	long maxn = 0;
	long left ,right;
	for(long i=keta-1;i>=1;i--){
		left = n / pow(10,i);
		right = n - left*pow(10,i);
		long mul = left * right;
		if(mul > maxn) maxn = mul;
	}
	return maxn;
}
		
int getketa(int n){
	int i=0;
	int keta = 1;
	for(i=1;keta>0;i++){
		keta = n / pow(10,i);
	}
	return i-1;
}

int main(){
	cin >> Q;
	for(long i=0;i<Q;i++){
		cin >> N;
		long keta;
		long count = 0;
		while(keta = getketa(N),keta != 1 && count < 10000){
			N = multip(N, keta);
			//cout << N << endl;
			count ++;
		}
		cout << count << endl;
	}
	
	return 0;
}

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

map<int, int> mem;

int main()
{
  int Q, n;
  cin >> Q;
  for(int q = 0; q < Q; q++)
  {
    mem.clear();
    cin >> n;
    int m = 0;
    while(n >= 10)
    {
      m++;
      mem[n] = 1;
      int tmp = 0;
      for(int j = 10; ; j *= 10)
      {
        int a, b;
        a = n / j;
        b = n % j;
        if(!a)
          break;
        tmp = max(tmp, a * b);
      }
      n = tmp;
      if(mem.count(n))
      {
        cout << -1 << endl; 
        goto end;
      }
    }
    cout << m << endl;
end:;
  }
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int q;
bool vis[1111111];

int dfs(int n,int d){
	if(n<10)return d;
	if(vis[n])return -1;
	vis[n]=true;
	string s=to_string(n);
	int res=0;
	rep(i,s.length()-1){
		maxch(res,stoi(s.substr(0,i+1))*stoi(s.substr(i+1,s.length()-i-1)));
	}
	return dfs(res,d+1);
}

int main(){
	cin.sync_with_stdio(false);
	cin>>q;
	rep(i,q){
		int n;
		cin>>n;
		memset(vis,0,sizeof(vis));
		cout<<dfs(n,0)<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm> 
#define MAX(a,b) a>b?a:b
#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;

int main(){
    int Q;
    int N;
    scanf("%d",&Q);
    rep(i,Q){
        int count = 0;
        scanf("%d",&N);
        while(N>=10){
            int temp = N;
            int digit = 0;
            while(temp>0){
                digit++;
                temp/=10;
            }
            count++;
            temp = 10;
            int max = 0;
            rep(i,digit-1){
                max = MAX(max,(N/temp)*(N%temp));
                temp*=10;
            }
            N = max;
        }
        printf("%d\n",count);
    }
    return 0;
}

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

#include <iostream>
#include <string>
#include <climits>
using namespace std;

int check(string num, int cnt){
  if(stoi(num)<10) return cnt;
  int max = -1;
  for(int i=1;i<=num.size()-1;i++){
    string sub1, sub2;
    sub1 = num.substr(0,i);
    sub2 = num.substr(i, num.size()-i);
    int num1 = stoi(sub1, nullptr, 10);
    int num2 = stoi(sub2, nullptr, 10);
    if(max<num1*num2) max=num1*num2;
  }

  cnt = check(to_string(max), cnt+1);

  return cnt;
}

int main(){
  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    string num;
    cin >> num;
    int cnt=0;
    cnt = check(num, cnt);
    if(cnt==INT_MAX) cout << -1 << endl;
    else cout << cnt << endl;
  }

  return 0;
}

C++: #include <cstdio>
#include <cassert>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <array>

using namespace std;

#define all(c) begin(c), end(c)
#define dump(c) cerr << "> " << #c << " = " << (c) << endl
#define REP(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1001001001;
const double EPS = 1e-10;


template<typename T1,typename T2>
ostream& operator<<(ostream& os, const pair<T1,T2>& p){
  return os << '(' << p.first <<',' << p.second << ')';
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& a){
  os << '[';
  rep(i,a.size()) os << (i ? " " : "") << a[i];
  return os << ']';
}

int main() {
  int Q; cin >> Q;
  while(Q--) {
    int R; cin >> R;
    int ans = 0;
    set<int> memo;
    while(R >= 10) {
      string r = to_string(R);
      set<int> s;
      rep(i, r.size() - 1) {
        int a = stoi(r.substr(0, i + 1));
        int b = stoi(r.substr(i + 1));
        s.insert(a * b);
      }
      R = *s.rbegin();
      if(memo.count(R)) {
        ans = -1;
        break;
      }
      memo.insert(R);
      ans++;
    }

    cout << ans << endl;
  }
  
  
  return 0;
}

C++: // 2016-12-12
#include <iostream>
#include <cmath>
using namespace std;

int main() {
	int q, n;
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> n;
		int c = 0;
		while (n >= 10) {
			int m = 0;
			for (int j = 10; j <= n; j *= 10) {
				m = max(m, (n / j) * (n % j));
			}
			n = m;
			c++;
		}
		cout << c << endl;
	}
	return 0;
}