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>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define nrep(i,n) for(int i=1;i<=(n);i++)
#define FST first
#define SEC second
using namespace std;

int stoi(string str){
  int ret;
  stringstream ss;
  ss << str;
  ss >> ret;
  return ret;
}

string itos(int val){
  stringstream ss;
  ss << val;
  string str = ss.str();
  return str;
}

int main(){
  int Q;
  scanf("%d",&Q);
  while(Q-->0){
    string N;
    cin >> N;

    if(stoi(N)<10){
      puts("0");
      continue;
    }

    set <int> s;    
    int count=1;
    for(;;){
      int max=0;
      for(int i=1;i<N.size();i++){
	string N1 = N.substr(0,i);
	string N2 = N.substr(i,N.size());
	int mul=stoi(N1)*stoi(N2);
	if(mul>max)
	  max=mul;
	// cout << N1 << " " << N2 << endl;
      }
      // cout << "max is :" << max << endl;
      if(max<10)
	break;
      if(s.count(max)){
	count = -1;
	break;
      }
      s.insert(max);

      N=itos(max);
      count++;
    }
    printf("%d\n",count);

  }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

string IntToString(ll int number){
  stringstream ss;
  ss << number;
  return ss.str();
}

string tmp;
string tmp2;

int main(){
	int q,cnt;
	cin >> q;
	REP(i,q){
		
		cin >> tmp;
		tmp2 = tmp;
		cnt = 0;
		while(tmp.size()!=1){
			int mmax = -1;
			FOR(i,1,tmp.size()){
				string st1,st2;
				FOR(j,0,i) st1 += tmp[j];
				FOR(j,i,tmp.size()) st2 += tmp[j];
				mmax = max(mmax,stoi(st1)*stoi(st2));
			}
			cnt++;
			tmp = IntToString(mmax);
			if(tmp==tmp2){
				cnt = -1;
				break;
			}
		}
		
	cout << cnt << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;
string IntToString(int);
int StringToInt(string);
int cal(int n){
  int ans = n;
  int cnt = 0;
  while(ans >= 10){
    string tmp = IntToString(ans);
    vector<int> keep;
    for(int i = 1;i < tmp.size();i++){
      int f,l;
      f = StringToInt(tmp.substr(0,i));
      l = StringToInt(tmp.substr(i));
      keep.push_back(f*l);
    }
    sort(keep.begin(),keep.end());
    /*    cout << "=========" << endl;
    for(int j = 0;j< keep.size();j++){
      cout << keep[j] << endl;
    }
    cout << "=========" << endl;*/
    ans = keep[keep.size()-1];
    ///    cout << ans << endl;
    cnt++;
  }
  
  return cnt;
}
int main(){
  /*  string a = "12";
  cout << a.substr(0,1) << " " << a.substr(1) << endl;
  return 0;
  */
  int n;
  cin >> n;

  for(int i = 0;i < n;i++){
    int tmp;
    cin >> tmp;
    cout << cal(tmp) << endl;
  }

  return 0;
}
string IntToString(int number){
  stringstream ss;
  ss << number;
  return ss.str();
}
int StringToInt(string number){
  stringstream ss;
  ss << number;
  int numInt;
  ss >> numInt;
  return numInt;
  
}
/*#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

*/

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2424>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll check(ll N){
    ll ret = -1;
    ll base = 10;
    for(;;base*=10){
        if(N%base == N) break;
        ret = max(ret,(N/base)*(N%base));
    }
    return ret;
}
ll solve(){
    ll res = 0;
    ll N; cin >> N;
    map<ll,bool> mp;
    while(true){
        if(N%10 == N) break;
        if(mp[N]){ res = -1; break; }
        N = check(N);
        res++;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int Q; cin >> Q;
    while(Q--){
        cout << solve() << endl;
    }
    return 0;
}