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 int Digits[7];

int q;
int n;
set<int> used;

int Convert(int t, int *ds) {
  int cnt = 0;
  while (t > 0) {
    ds[cnt++] = t%10;
    t /= 10;
  }
  return cnt;
}

int Restore(int *ds, int n) {
  int ret = 0;
  for (int i=n-1; i>=0; i--) {
    ret = ret*10 + ds[i];
  }
  return ret;
}

int main() {
  scanf("%d", &q);
  for (int i=0; i<q; i++) {
    Digits ds;

    used.clear();
    scanf("%d", &n);

    int ans = 0;
    while (1) {
      used.insert(n);
      int k = Convert(n, ds);
      if (k <= 1) break;

      int maxi = 0;
      for (int i=1; i<k; i++) {
        maxi = max(maxi, Restore(ds, i) * Restore(ds+i, k-i));
      }
  
      if (used.count(maxi)) {
        ans = -1;
        break;
      }

      n = maxi;
      ans++;
    }

    printf("%d\n", ans);
  }
}

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

const int N_MAX = 1000000;
int c[N_MAX+1];

int next(int n0) {
    int n1 = 0;
    for (int i = 10; i < n0; i *= 10) {
        int a = n0 / i;
        int b = n0 % i;
        n1 = max(n1, a * b);
    }
    return n1;
}

int main() {
    for (int i = 0; i < N_MAX; i++) {
        c[i] = next(i);
    }
    int q;
    while (cin >> q) {
        for (int i = 0; i < q; i++) {
            int n;
            cin >> n;
            set<int> s;
            s.insert(n);
            int ans = 0;
            while (n >= 10) {
                int n1 = c[n];
                if (s.find(n1) != s.end()) {
                    ans = -1;
                    break;
                }
                ans++;
                n = n1;
            }
            cout << ans << endl;
        }
    }
}

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

using namespace std;

#define INF 999999999

int main(){
	int i, j, q, n;
	int ans;
	
	cin >> q; 
	for(i=0;i<q;i++){
		ans = 0;
		cin >> n;
		while(n>=10){
			ans++;
			int mo=0;
			//cout << n << endl;
			for(j=1;n/pow(10,j)>0;j++){
				if(mo<(n/(int)pow(10,j))*(n%(int)(pow(10,j)))){
					mo = (n/(int)pow(10,j))*(n%(int)(pow(10,j)));
				}
			}
			n = mo;
		}
		cout << ans << endl;
	}
	return 0;
}

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

void solve() {
    int N;
    cin >> N;
    map<int, bool> is_visited;
    int ans = 0;
    while (true) {
        if (is_visited[N]) {
            cout << -1 << endl;
            return;
        }
        is_visited[N] = true;
        if (N < 10) break;
        int max_n = -1;
        int div = 10;
        for (int i = 0; i < 6; i++) {
            int d1 = N / div;
            int d2 = N % div;
            max_n = max(max_n, d1 * d2);
            div *= 10;
        }
        N = max_n;
        ans++;
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        solve();
    }
    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }
inline long long tonum(string s) {long long v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string tostr(T x) {ostringstream sout;sout<<x;return sout.str();}

int CASE;

string conv(string str) {
    long long num = 0;
    for (int i = 1; i < str.size(); ++i) {
        long long a = tonum(str.substr(0, i));
        long long b = tonum(str.substr(i));
        //COUT(a); COUT(b);
        long long tmp = a * b;
        chmax(num, tmp);
    }
    return tostr(num);
}

int main() {
    //freopen( "/Users/macuser/Dropbox/Contest/input.in", "r", stdin );
    cin >> CASE;
    for (int AAA = 0; AAA < CASE; ++AAA) {
        string str; cin >> str;
        int res = 0;
        while (true) {
            if (str.size() == 1) break;
            str = conv(str);
            ++res;
            
            //COUT(str);
        }
        cout << res << endl;
    }
    return 0;
}