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++: using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using CHY72;

namespace CHY72{
    
    public class PointXY{
        public int X , Y;
        public int SQLength() { return X * X + Y * Y; }
        public bool Flag = false;
        public PointXY(int _X,int _Y) {
            X = _X; Y = _Y;
        }
        public PointXY(PointXY P1, int _X = 0, int _Y = 0) {
            X = P1.X +  _X; Y =P1.Y + _Y;
        }
        public static bool operator ==(PointXY P1, PointXY P2) {
            return (P1.X== P2.X && P1.Y == P2.Y);
        }
        public static bool operator !=(PointXY P1, PointXY P2) {return !(P1 ==P2);}
        public override int GetHashCode() {return X.GetHashCode() ^ Y.GetHashCode();}
        public override bool Equals(object obj) {
            if (obj == null || this.GetType() != obj.GetType()) {return false;}
            return (this == (PointXY)obj);
        }

    }

    public class Lib72 {
        public static int NumFromChar(char CNUM) { return CNUM - 48; }

        public static int[] KETAArray(int Num) {return KETAArray(Num.ToString()); }
        public static int[] KETAArray(string Num) {
            char[] cKETA = Num.ToCharArray();
            int[] iKETA = new int[cKETA.Length];
            for (int i = 0; i < iKETA.Length; i++) {
                iKETA[i] = NumFromChar(cKETA[i]);
            }
            return iKETA;
        }
        public static int KETA(int Num) { return Num.ToString().ToCharArray().Length; }
        public static int FromKETAArray(int[] _ketaarray) {
            int result = 0;
            int[] R_ketaarray = _ketaarray.Reverse().ToArray(); 
            for (int i = 0,j=1; i < R_ketaarray.Length; i++,j *=10) {
                result += j * R_ketaarray[i];
            }
            return result;
        }
        public static bool isPrime(int p) {
            if (p != 2 && p % 2 == 0) return false;
            if (p == 1) return false;
            int SQp = (int)(Math.Sqrt(p));
            for (int i = 3; i <= SQp; i++) {
                if (p % i == 0) return false;
            }
            return true;
        } 
    }
}    

public class Program {
    static bool ReadLine_1(ref int num1, bool Fin0 = true) {
        string str = Console.ReadLine();
        num1 = int.Parse(str);
        return (Fin0 && num1 == 0);
    }
    static int  ReadLine_1() {
        return  int.Parse(Console.ReadLine());
    }
    static bool ReadLine_2(ref int num1, ref int num2, char Spliter = ' ', bool Fin0 = true,int FinNum =0) {
        string str = Console.ReadLine();
        num1 = int.Parse(str.Split(Spliter)[0]);
        num2 = int.Parse(str.Split(Spliter)[1]);
        return (Fin0 && num1 == FinNum && num2 == FinNum);
    }
    static int[] ReadLine72(char Spliter = ' ') {
        return Console.ReadLine().Split(Spliter).Select(s => int.Parse(s)).ToArray();
    }

    const int DefaultMax = 72727272;



    static void Main(string[] args) {
        int Q = ReadLine_1();
        for (int i = 0; i < Q; i++) {
            int N = ReadLine_1(); int R = 0;
            while (true){
                if (Lib72.KETA(N) == 1) break;
                string Nstr = "" + N;
                break;

                R++;
            }
            Console.WriteLine(R + " ");
        }
    }
}

C++: #include<iostream>
#include<algorithm>
#include<set>
using namespace std;
int main()
{
	int q; cin>>q;
	while(q--) 
	{
		int n; cin>>n;
		set<int> used;
		int ans=0;
		while(used.find(n)==used.end()&&9<n)
		{
			int next=0,r=0;
			used.insert(n);
			int mul=1;
			while(1)
			{
				r+=n%10*mul;
				n/=10;
				mul*=10;
				if(n==0) break;
				next=max(next,r*n);
			}
			n=next;
			ans++;
		}
		if(n<=9) cout<<ans<<endl;
		else cout<<-1<<endl;
	}
  return 0;
}

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

string d="";
int k(int a) {
	int b = 0;
	for (; a < d.length(); a++) {
		b = b * 10 + d[a] - 48;
	}
	return b;
}
int main() {
	int a;
	cin >> a;
	for (int b = 0; b < a; b++) {
		int c = 0;
		cin >> d;
		unordered_set<string>j;
		while (c++,1) {
			if (d.length() == 1) { cout << c-1 << endl; break; }
			int MAX = 0;
			int l =0,r=k(0);
			for (int f = 0; f < d.length(); f++) {
				MAX = max(MAX, l*r);
				l = l * 10 + d[f] - 48;
				r = k(f + 1);
			}
			d = to_string(MAX);
			if (j.find(d) != j.end()) { puts("-1"); return 0; }
			j.insert(d);
		}
	}
}

C++: //#include <bits/stdc++.h>
#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

int f(int n, int cnt) {
  if (n < 10) return cnt;
  int maxnum = -1;
  string s;
  s = to_string(n);
  rep(i, s.size()) {
    string t = s.substr(0, i + 1);
    string u = s.substr(i + 1);
    int forward = atoi(t.c_str());
    int backward = atoi(u.c_str());
    // cout << forward << endl;
    int tmp = forward * backward;
    cmax(maxnum, tmp);
  }
  return f(maxnum, cnt + 1);
}

signed main() {
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    cout << f(n, 0) << endl;
  }
  return 0;
}