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;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

template<typename T> inline void _tostr(const T t, string& s){ostringstream o;o<<t;s=o.str();}
template<typename T> inline string _tostr(const T t){ostringstream o;o<<t;return o.str();}
template<typename T> inline void _toint(const string s, T& n){istringstream i(s);i>>n;}
template<typename T> inline T _toint(const string s){istringstream i(s);T n;i>>n;return n;}

int Q, N;
string s;

int main()
{
  cin >> Q;

  while(Q--){
    cin >> N;
    int res = 0;
    while(N > 9){
      int mx = 0;
      res += 1;
      s = _tostr(N);
      rep(i, s.size()-1){
        string l = s.substr(0, i+1);
        string r = s.substr(i+1, s.size()-i-1);
        maxup(mx, _toint<int>(l) * _toint<int>(r));
      }
      N = mx;
    }
    cout << res << endl;
  }

  return 0;
}

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

using namespace std;

inline int nextInt() { int d; cin >> d; return d; }

bool isUsed[(int)1e6 + 1];

int getNext(int n) {
  int ret = -1;
  for (int d = 10; d < n; d *= 10) {
    int n1 = n % d;
    int n2 = (n - n1) / d;
    ret = max(ret, n1 * n2);
  }

  return ret;
}

int solve(int n) {
  int step = 0;
  memset(isUsed, false, (int)1e6 + 1);
  while (true) {
    if (n < 10) {
      return step;
    }
    if (isUsed[n]) {
      return -1;
    }
    isUsed[n] = true;
    n = getNext(n);
    step++;
  }
  return 0;
}

int main() {
  int Q = nextInt();

  for (int i = 0; i < Q; i++) {
    int R = nextInt();
    int ans = solve(R);
    cout << ans << endl;
  }

  return 0;
}

C++: #include <cstdio>
#include <cstring>
int q,n;
bool data[1000001];
int main(void){
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		scanf("%d",&n);
		memset(data,false,sizeof(data));
		int x=n,next,cnt=0;
		while(1){
			if(data[x]){
				printf("-1\n");
				break;
			}
			if(x<=9){
				printf("%d\n",cnt);
				break;
			}
			data[x]=true;
			next=-1;
			int a=x,b=0,c=1;
			while(a>0){
				b=b+(a%10)*c;
				a/=10;
				if(a*b>next)next=a*b;
				c*=10;
			}
			x=next;
			cnt++;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int conv(int a){
    int n = 0;
    int p = a;
    while (p){
        n++;
        p /= 10;
    }
    VI c(n);
    p = a;
    REP(i,n){
        c[n-i-1] = p % 10;
        p /= 10;
    }
    int ma = 0;
    FOR(i,1,n-1){
        int x = 0, y = 0;
        REP(j,i){
            x *= 10;
            x += c[j];
        }
        FOR(j,i,n-1){
            y *= 10;
            y += c[j];
        }
        ma = max(ma, x*y);
    }
    return ma;
}

int main() {
    int q;
    cin >> q;
    while (q--){
        int a;
        cin >> a;
        int i = 0;
        while (a > 9){
            a = conv(a);
            i++;
        }
        cout << i << endl;
    }

    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int q,n;
  cin >> q;
  int i,j,k,l;
  for(i=0;i<q;i++){
    cin >> n;
    int s=0;
    while(n>=10){
      int b = n;
      k=0;
      while(b>=10) {
	b/=10;
	k++;
      }
      b=n;
      n=0;
      for(j=0;j<k;j++){
	int d=10;
	for(l=0;l<j;l++) d*=10;
	if((b/d)*(b%d)>n) n= (b/d)*(b%d);
      }
      
      s++;
    }
    cout << s << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<fstream>
#include<string>

using namespace std;

int search(int num){
    if(num < 10)return 0;

    auto log = 10;
    auto v = 0;
    while(log < num)
    {
        auto tmp = (num % log) * (num / log);
        v = max(tmp, v);
        log *= 10;
    }

    return 1 + search(v);

}


int main(){
    //ifstream fin("in.txt");

    auto n = 0;
    cin >> n;

    for(auto i = 0; i < n; i++){
        auto num = 0;
        cin >> num;
        cout << search(num) << endl;
    }

    return 0;
}