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

int c;

int seisu_1(int n){
    if(0<=n && n<10) return c;
    if(n == (n/10)*(n%10)) return -1;
    else{    
    int nmax=(n/10)*(n%10), m;
    for(int j=10; j<=n; j*=10){
        m = (n/j)*(n%j);
        if(nmax<m)  nmax = m;
    }
    c++;
    return seisu_1(nmax);
    }
}


int main(void){
    int Q, n;
    cin >> Q;
    for(int i=1; i<=Q; i++){
        c = 0;
        cin >> n;
        cout << seisu_1(n) << endl;
    }
    
    return 0;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

bool contains(vector<int>&vs, int x) {
  for (int v : vs) {
    if (v == x) return true;
  }
  return false;
}

int main() {

  int n; cin >> n;
  while (n--) {
    int x; cin >> x;
    int cx = 0;
    vector<int> history;

    while (x > 9) {
      int nx = 0;
      for (int d = 10; ; d *= 10) {
        int z = x / d;
        int y = x % d;
        if (z == 0) break;
        nx = max(nx, z * y);
      }
      x = nx;
      trace(x);
      ++cx;
    }

    cout << cx << endl;

  }

  return 0;
}

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

int main ()
{
    int q;
    cin >> q;
    while (q--) {
        int n, res = 0;
        cin >> n;
        set<int> t;
        while (n / 10) {
            t.insert(n);
            res++;
            int MAX = 0;
            int j = 1, k = 0;
            while (n) {
                k += j * (n % 10);
                n /= 10;
                MAX = max(MAX, k * n);
                j *= 10;
            }
            n = MAX;
            if (t.find(n) != t.end()) {
                res = -1;
                break;
            }
        }
        cout << res << endl;
    }

    return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
  int Q, N, s, t, l, ans;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    cin >> N;
    s = N;
    ans = 0;
    while (s > 9) {
      ++ans;
      l = 10;
      t = 0;
      while (l < N) {
	t = max(t, (s%l)*(s/l));
	l *= 10;
      }
      s = t;
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <math.h>
#include <vector>

//FILE *in = freopen("2424.txt", "r", stdin);
//FILE * out = freopen("outputA.txt", "w", stdout);


int main()
{
	int n, count, cut;
	int num, front, back, max, now;
	std::vector<int> prev;

	//while (scanf("%d", &n) > 0){
		scanf("%d", &n);
		for(int i = 0; i < n; i++){
			scanf("%d", &num);
			max = 0;
			count = 0;
			if(num < 10)
			{
				printf("%d\n", count);
				continue;
			}
			while(num > 10){
				count++;
				back = 0;
				cut = 0;
				max = 0;
				while((front = num / 10) > 0){
					int a = 1;
					for(int i = 1; i < cut; i++)
						a *= 10;
						//back *= 10;
					back += (num%10)*a;
					now = back * front;
					if(max < now)
						max = now;
					num/=10;
				}
				num = max;
				if(prev.size() != 0){
					for(int i = 0; i < prev.size(); i++)
						if(num == prev.at(i))
						{
							count = -1;
							goto out;
						}
				}
				prev.push_back(num);

			}
			out:
			printf("%d\n", count);
			prev.clear();
		}
	//}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>

#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

/*---------------------------------------------------*/

int str_to_int(string s){
  int keta=1;
  int num=0;
  char c;
  while(s.size()){
    c=s[s.size()-1];
    s.pop_back();
    num+=keta*int(c-'0');
    keta*=10;
  }
  return num;
}

void solve(string s){
  int maxi=str_to_int(s);
  int cnt=0;
  for(cnt=0;;cnt++){
  	if(maxi<=10)break;
    if(cnt==100)break;
  	maxi=-INF;
  	  string ss;
  	  ss.pb(s[0]);
      s.erase(s.begin());
    while(s.size()){
      //cout<<str_to_int(s)<<" "<<str_to_int(ss)<<" ";
      maxi=max(maxi,str_to_int(ss)*str_to_int(s));
      //cout<<maxi<<endl;
      ss+=s[0];
      s.erase(s.begin());
    }
    //cout<<maxi<<endl<<endl;;
    if(cnt>=100)break;
    else s=to_string(maxi);
  }
  cout<<cnt<<endl;
}

int main(){
  int n;
  string s;

  cin>>n;
  rep(i,n){
    cin>>s;
    solve(s);
  }

  return 0;
}