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 <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <complex>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EPS 1.0e-9

int main(){
	int q,n;
	cin>>q;
	REP(i,q){
		cin>>n;
		int ret=0;
		while(1){
			int div=10;
			if(n<10)break;
			int tmp = 0;
			while(n/div){
				tmp = max(tmp, (n/div)*(n%div));
				div*=10;
			}
			n=tmp;
			ret++;
		}
		cout << ret<<endl;
	}
	return 0;
}

C++: #include<stdio.h>

int main(){

int n;

scanf("%d",&n);
int x;
for(int i=0;i<n;i++)
{scanf("%d",&x);
int c=0;int d=10;int w=0,y=0;int max=0;
while(x/10!=0){
for(int j=0;j<6;j++)
{
w=x/d;y=x%d;d*=10;
if(j==0)max=w*y;
else if(w*y>max)max=w*y;}
x=max;c++;d=10;}
printf("%d\n",c);
}
return 0;
}

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


int ketasuu(int n) {
  int ans = 0;
  while(n > 0){
    ans++;
	n = n / 10;
  }
  return ans;
}

int A[7] = {1,10,100,1000,10000,100000,1000000};
int solve_loop(int n) {
  int a1, a2;
  int ans = 0;
  int k = ketasuu(n);
  if(k == 1 || k == 0) return -1;
  for(int i = 1; i < k; i++) {
    a1 = n / A[i];
	a2 = n % A[i];
	ans = max(ans,a1*a2);
  }
  return ans;
}
int solve(int num) {
  int output = 0;
  while(solve_loop(num) != -1){
    output++;
	num = solve_loop(num);
  }
  return output;
}


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

C++: #include <cstdio>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int Q;
  scanf("%d", &Q);
  for (int i=0;i<Q;i++) {
    int N;
    scanf("%d", &N);
    bool loop = false;
    vector<int> n;
    n.push_back(N);
    while (N/10 > 0) {
      const string sN = to_string(N);
      N = 0;
      for (int j=1;j<sN.size();j++)
        N = max(N, stoi(sN.substr(0,j))*stoi(sN.substr(j)));
      if (find(n.begin(), n.end(), N) != n.end()) {
        loop = true;
        break;
      }
      n.push_back(N);
    }
    if (loop) puts("-1");
    else printf("%d\n", (int)n.size()-1);
  }
  return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1
#define pb push_back

using namespace std;

int main() {
  int Q, N, tmp1, tmp2, digit, x, max, count = 0;;
  cin >> Q;
  while (Q--) {
    cin >> N;
    count = 0;
    while (N/10) {
      max = -INF;
      x = 10;
      for (digit = 1; N/x; digit++) {
        x *= 10;
      }
      x /= 10;
      for (int i = 1; i < digit; i++, x /= 10) {
        tmp1 = N / x;
        tmp2 = N % x;
        if (max < tmp1*tmp2) {
          max = tmp1*tmp2;
        }
      }
      N = max;
      count++;
    }
    cout << count << el;
  }
}

C++: //46
#include<iostream>
#include<set>

using namespace std;

int main(){
  int q;
  cin>>q;
  while(q--){
    int n;
    cin>>n;
    int a;
    set<int> s;
    for(a=0;n>=10&&s.insert(n).second;a++){
      int m=0;
      for(int p=10;p<=n;p*=10){
	int h,l;
	h=n/p;
	l=n-h*p;
	if(m<h*l){
	  m=h*l;
	}
      }
      n=m;
    }
    cout<<((n<10)?a:-1)<<endl;
  }
  return 0;
}