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 <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  int Q; cin >> Q;
  while(Q--) {
    string s; cin >> s;
    int ans = 0;
    int j = 0;
    while(s.length() > 1) {
      int l = 0;
      int r = stoi(s);
      int cnt = l * r;
      FOR(i,0,(int)s.length()-1) {
        l *= 10;
        l += s[i] - '0';
        r %= (int)pow(10, s.length()-i-1);
        cnt = max(cnt, l * r);
      }
      s = to_string(cnt);
      j++;
      ans++;
      if(j == 100000) {
        cout << -1 << '\n';
        break;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

const int INF = 1e9;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int r;
	cin >> r;
	while(r--){
		string n;
		cin >> n;
		int ct = 0;
		int max_;
		bool ismultipled;
		do{
			ismultipled = false;
			max_ = 0;
			if(n.size() == 1)break;
			for(int digit = n.size() - 1;digit > 0;digit--){
				if(n[digit] == '0' && digit > 1)continue;
				ismultipled = true;
				max_ = max(max_,stoi(n.substr(0,digit)) * stoi(n.substr(digit,n.size() - digit)));

			}
			n = to_string(max_);
			if(ct > INF){
				ct = -1;
				break;
			}
		}while(ismultipled && ++ct);
		cout << ct << endl;
	}
  return 0;
}

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

int main() {
  int Q;
  cin >> Q;
  
  while ( Q-- ) {
    int n;
    int cnt = 0;
    cin >> n;
    map<int, bool> used;
    while ( 1 ) {      
      if ( used[n] ) {
	cnt = -1;
	break;
      }
      used[n] = true;
      if ( n < 10 ) break;
      cnt++;
      int m = -1;
      for ( int i = 10; ; i *= 10 ) {
	if ( i > n ) break;
	m = max(m, (n/i)*(n%i));
      }      
      n = m;      
    }

    cout << cnt << endl;
  }
  
  return 0;
}

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

int main() {

  int Q;
  cin >> Q;
  while(Q--) {
    string s;
    cin >> s;
    int cnt = 0;
    while(s.size() > 1) {
      int maxi = 0;
      for(int i = 1; i < s.size(); i++) {
        string left = s.substr(0, i), right = s.substr(i, s.size() - i);
        //cout << left << " " << right << endl;
        maxi = max(maxi, atoi(left.c_str()) * atoi(right.c_str()));
      }
      s = to_string(maxi);
      cnt++;
    }
    cout << cnt << endl;
  }
}

C++: #include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#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 range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
    int q; cin >> q;
    while(q--){
        int n; cin >> n;
        
        int res = 0;
        map<int, bool> used;
        while(n / 10 != 0){
            if(used[n]){
                res = -1;
                break;
            }
            else{
                used[n] = true;
                res++;
            }
            
            int next = 0;
            rep(i, 6){
                int a = n / (int)pow(10., (double)i);
                int b = n % (int)pow(10., (double)i);

                if(a == 0 || b == 0) continue;

                next = max(next, a * b);
            }
            n = next;
        }

        cout << res << endl;
    }

	return 0;
}

C++: #include <cstring>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>
using namespace std;

int dp[1000000 + 100000];
int solve(int n){
  if(n < 10) return 0;
  if(dp[n] != -1) return dp[n];

  int now = 0;
  int nn = n;

  int next = 0;

  int tmp = 1;
  while(true){
    now += tmp * (nn % 10);
    nn /= 10;

    if(nn == 0) break;
    next = max(next, now * nn);
    tmp *= 10;
  }

  return dp[n] = solve(next) + 1;
}

int main(){
  const int q = getInt();
  memset(dp, -1, sizeof(dp));

  REP(i,q)
    printf("%d\n", solve(getInt()));

  return 0;
}