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

typedef long long ll;

int calc(int n) {
    int cnt = 0;
    while(n >= 10) {
        ll next = -1, r = 10;
        while (r < n) {
            next = max(next, ((ll)n/r) * (n%r));
            r *= 10;
        }
        n = next;
        cnt++;
    }
    return cnt;
}

int main() {
    int q,n;
    cin>>q;
    for (int i=0; i<q; ++i) {
        cin>>n;
        cout<<calc(n)<<endl;
    }
}

C++: #include <bits/stdc++.h>

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 nexts[1000010];

int main(void){
	for(int i=10;i<=1000000;++i){
		nexts[i]=0;
		string in=to_string(i);
		int n=in.size();
		rep(j,n-1){
			int a=stoi(in.substr(0,j+1));
			int b=stoi(in.substr(j+1,n-j-1));
			nexts[i]=max(nexts[i],a*b);
		}
	}
	int q;
	cin >> q;
	rep(loop,q){
		int cur;
		cin >> cur;
		int ans=0;
		while(cur>=10){
			ans++;
			cur=nexts[cur];
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
  int q;
  cin >> q;
  while(q--) {
    string s;
    cin >> s;
    int size = s.size();
    int res, ans = 0;
    while(size > 1) {
      res = 0;
      for(int i=0; i<size-1; i++) {
	string a = s.substr(0, i+1);
	string b = s.substr(i+1);
	res = max(atoi(a.c_str())*atoi(b.c_str()), ans);
      }
      stringstream ss; ss << res; s = ss.str();
      size = s.size();
      ans ++;
    }
    cout << ans << endl;
  }
  
  return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int n;
        cin >> n;

        int count = 0;
        auto process = [](int n) {
            auto s = to_string(n);
            if (s.size() == 1) {
                return n;
            }
            int max_ = 0;
            for (int j = 0; j < s.size() - 1; ++j) {
                auto l = stoi(s.substr(0, j + 1));
                auto r = stoi(s.substr(j + 1));
                max_ = max(max_, l * r);
            }
            return max_;
        };
        while (true) {
            if (0 <= n && n <= 9) {
                break;
            }
            n = process(n);
            count += 1;
        }
        cout << count << endl;
    }
}

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

using namespace std;

typedef vector<int> VI;
typedef vector<bool> VB;

const int SIZE = 1000001;

VI memo( SIZE, -2 );
VB visited( SIZE, false );

int dfs ( int num )
{
	if ( memo[num] != -2 ) {
		return memo[num];
	}
	if ( memo[num] == -2 && visited[num] ) {
		return memo[num] = -1;
	}
	if ( num < 10 ) {
		return memo[num] = 0;
	}
	int m = 10,
		next = 0,
		res = -1;
	visited[num] = true;
	while ( num >= m ) {
		next = max( next, ( num / m ) * ( num % 10 ) );
		m *= 10;
	}
	res = dfs( next );
	res += res != -1;
	return memo[num] = res;
}

int main ( void )
{
	int q;
	while ( cin >> q ) {
		for ( int i = 0; i < q; ++i ) {
			int n;
			cin >> n;

			cout << dfs( n ) << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<set>
#include<sstream>

using namespace std;

int str2int(string str) {
  stringstream ss;
  int ans;
  ss<<str;
  ss>>ans;
  return ans;
}

string int2str(int num) {
  stringstream ss;
  string str;
  ss<<num;
  ss>>str;
  return str;
}

int main() {
  int q;
  cin>>q;
  for(int i=0; i<q; i++) {
    string n;
    set<int> alreadyUsed;
    cin>>n;

    int ans = 0;
    while(true) {
      if(str2int(n)/10 == 0) { // 1桁なら終了
	break;
      }
      set<int>::iterator itr = alreadyUsed.find(str2int(n));
      if(itr != alreadyUsed.end()) { // 同じ値が2度出たら無限ループ
	//ans = -1;
	break;
      }
      alreadyUsed.insert(str2int(n));
      int tmpMax = -1;
      for(int j=1; j<n.length(); j++) {
	string front, back;
	for(int k=0; k<j; k++) {
	  front += n[k];
	}
	for(int k=j; k<n.length(); k++) {
	  back += n[k];
	}
	int tmp = str2int(front)*str2int(back);
	if(tmp > tmpMax) {
	  tmpMax = tmp;
	}
      }
      n = int2str(tmpMax);
      //cout<<"next is "<<n<<endl;
      ans++;
    }
    cout<<ans<<endl;
  }
}