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 <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

char s[1024];

int Number(int l, int r)
{
	int n = 0;
	for (int i = l; i <= r; i++){
		n = n * 10 + s[i] - '0';
	}
	
	return (n);
}

int main()
{
	int N;
	scanf("%d", &N);
	
	for (int c = 0; c < N; c++){
		scanf("%s", s);
		
		int cnt = 0;
		while (s[1] != '\0'){
			int ma = 0;
			
			int len = strlen(s);
			for (int m = 0; m < len - 1; m++){
				ma = max(ma, Number(0, m) * Number(m + 1, len - 1));
			}
			
			sprintf(s, "%d", ma);
			
			cnt++;
		}
		
		printf("%d\n", cnt);
	}
	
	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    while(--q >= 0){
        int n;
        cin >> n;

        int ret = 0;
        while(n >= 10){
            ++ ret;

            int maxNum = -1;
            int tmp = 10;
            while(tmp < n){
                maxNum = max(maxNum, (n % tmp) * (n / tmp));
                tmp *= 10;
            }
            n = maxNum;
        }

        cout << ret << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
long long m[100000];
int main() {
	int n;
	cin >> n;
	for (int z = 0; z < n; z++) {
		long long a;
		cin >> a;
		int sum = 0;
		while (to_string(a).length() != 1) {
			string h = to_string(a), c, d;
			long long b = 0;
			for (int i = 0; i < h.length() - 1; i++) {
				c = h.substr(0, i+1);
				d = h.substr(i+1, h.length()-i-1);
				b = max((stoll(c)*stoll(d)), b);
			}
			a = b;
			int s = 0, e = sum - 1, t;
			while (e - s > 1) {
				t = (e + s) / 2;
				if (m[t] >= a) s = t;
				if (m[t] < a) e = t;
			}
			if ((m[s] == a || m[e] == a)&&s>=0&&e>=0) {
				sum = -1;
				break;
			}
			m[sum] = a;
			sort(m, m + sum);
			sum++;
		}
		cout << sum << endl;
	}
}

C++: //include
//------------------------------------------
#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 <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//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())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int Q; cin >> Q;
  REP(i,Q){
	int x, ans = 0;
	cin >> x;
	set<int> s;
	for(;;){
	  if(x / 10 == 0) break;
	  if(s.find(x) != s.end()){
		ans = -1; break;
	  }
	  s.insert(x);
	  int nxt = 0, t1 = x, t2 = 0;
	  for(int p=10;x/p!=0;p*=10){
		t1 = x / p;
		t2 = x % p;
		nxt = max(nxt, t1*t2);
	  }
	  x = nxt;
	  ++ans;
	}
	cout << ans << endl;
  }
  
  return 0;
}

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

using namespace std;

vector<string> V;

bool find(string s){
  for(int i = 0; i < V.size(); i++)
    if(V[i] == s) return true;

  return false;
}

int StoI(string s, int pos){

  string s1 = "", s2 = "";
  
  for(int i = 0; i < pos; i++)
    s1 += s[i];
  
  for(int i = pos; i < s.length(); i++)
    s2 += s[i];

  stringstream ss1(s1), ss2(s2);
  int n1,n2;
  ss1 >> n1;
  ss2 >> n2;
  return n1*n2;
}

string ItoS(int n){
  string out = "";
  if(n == 0) out = "0";

  while(n){
    out += n%10+'0';
    n /= 10;
  }
  reverse(out.begin(),out.end());
  return out;
}

string make(string n){
  int out = 0;

  for(int i = 1; i < n.length(); i++)
     out = max(out,StoI(n,i));

  return ItoS(out);
}

int solve(string n){
  
  int rev = 0;

  while(1){
    
    if(find(n)) return -1;
    else V.push_back(n);

    if(n.length() == 1) return rev;

    n = make(n);
    rev++;
  }
}

int main(){
  int n;
  cin >> n;
  while(n--){
    V.clear();
    string in;
    cin >> in;
    cout << solve(in) << endl;
  }
  return 0;
}