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<set>
#include<algorithm>
using namespace std;

unsigned int xor128(){
	static unsigned int x=123456789,y=362436069,z=521288629,w=88675123; 
	unsigned int t=(x^(x<<11));
	x=y;y=z;z=w;
	return w=(w^(w>>19))^(t^(t>>8));
}

template<class Key,class Val>
class Treap{
	struct Node{
		unsigned int priority;
		Key key;
		Val value;
		Node *left,*right;
		Node(const Key& k,const Val& v)
			:priority(xor128()),key(k),value(v),left(0),right(0){}
		
		Node *rotate_right(){
			Node *s=left;
			left=s->right;
			s->right=this;
			return s;
		}
		Node *rotate_left(){
			Node *s=right;
			right=s->left;
			s->left=this;
			return s;
		}
		~Node(){
			if(this){
				if(left)delete left;
				if(right)delete right;
			}
		}
		Node *insert(const Key& k,const Val& v){
			return insert(new Node(k,v));
		}
		Node *insert(Node *t){
			if(this==NULL)return t;
			if(t==NULL)return this;
			Node *s=this;
			if(t->key < key){
				left = left->insert(t);
				if(priority < left->priority)s=rotate_right();
			}else{
				right = right->insert(t);
				if(priority < right->priority)s=rotate_left();
			}
			return s;
		}
		Node *find(const Key& k){
			return this==NULL?NULL:k==key?
				this:k<key?left->find(k):right->find(k);
		}
		Node *erase(const Key& k){
			if(this==NULL)return NULL;
			if(k==key){
				if(left && (!right || left->priority > right->priority)){
					Node *s=rotate_right();
					right=right->erase(k);
					return s;
				}else if(right && (!left || left->priority < right->priority)){
					Node *s=rotate_left();
					left=left->erase(k);
					return s;
				}
				delete this;
				return NULL;
			}
			else if(k<key)left = left->erase(k);
			else right = right->erase(k);
			return this;
		}
		int getHeight(){
			if(this==NULL)return 0;
			return 1+max(left->getHeight(),right->getHeight());
		}
	} *root;
public:
	Treap():root(0){}
	~Treap(){if(root)delete root;}
	void insert(const Key& k,const Val& v){
		root=root->insert(k,v);
	}
	void insert(Treap<Key,Val> t){
		root=root->insert(t->root);
	}
	Val* find(const Key& k){
		Node *p=root->find(k);
		if(p)return &p->value;
		return NULL;
	}
	void erase(const Key& k){
		root=root->erase(k);
	}
};


struct A{};

int main(){
	int q;
	cin>>q;
	while(q--){
		int n;
		//set<int> s;
		Treap<int,A> s;
		cin>>n;
		int ans=0;
		while(10<=n){
			if(s.find(n)){
				ans=-1;
				break;
			}
			s.insert(n,A());
			int next=0;
			int b=10;
			while(b<=n){
				int t=(n%b)*(n/b);
				next=max(next,t);
				b*=10;
			}
			n=next;
			ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)

string ss;
int str_to_i(string ss_) {
    //cout<<ss_<<endl;
    int ret=0;
    istringstream is(ss_);
    is>>ret;
    return ret;
}
string i_to_str(int n_) {
    ostringstream os;
    os<<n_;
    return os.str();
}

void solve() {
    cin>>ss;
    int ans=0;
    while(ss.size()!=1) {
        int maxi=0;
        string tmp = ss;
        for(int i=1;i<ss.size();i++) {
            int t = str_to_i(ss.substr(0,i))*str_to_i(ss.substr(i));
            if(maxi<=t) {
                maxi=t;
                tmp = i_to_str(t);
            }
        }
        //cout<<"tmp: "<<tmp<<endl;
        ss = tmp;
        ans++;
    }

    cout<<ans<<endl;
}

int main() {
    int n;cin>>n;
    rep(i,n) solve();

    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<sstream>
#include<queue>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#define INF 2147483647
#define lli long long int

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

int main() {
	
	int q; cin >> q;

	for (int i = 0; i < q; i++){
		int ans = 0;
		string n; cin >> n;
		//cout << " n = " << n << endl;
		while(1){
			int max = 0;
			if (n.size() == 1){
				cout << ans << endl;
				break;
			}else{
				for (int i = 0; i < n.size() - 1; i++){
					string str1 = n.substr(0,i+1);
					string str2 = n.substr(i+1,n.size()-i);
					//cout << "str1 = "  << str1 << endl;
					//cout << "str2 = "  << str2 << endl;
					int right = stoi(str1);
					int left = stoi(str2);
					if (max < right * left){
						max = right * left;
					}
				}
				ans++;
			}
			n = to_string(max);
		}
	}
	return 0;
}

C++: #include "bits/stdc++.h"
#define pb push_back
#define mt make_tuple
#define all(a) (a).begin(),(a).end()
#define frep(i,a,n) for(int i=(a);i<(n);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define rrep(i, n) for(int i=n-1;i>=0;--i)
#define debug(x) cout << #x << " : " << x << " ------------ " << endl;
using namespace std;
int main()
{
    int q;
    cin >> q;
    while (q--) {
        int n, count = 0;
        cin >> n;
        map<int, bool> h;
        while (1) {
            if (floor(n/10) == 0) break;
            string s = to_string(n);
            vector<int> p;
            frep(i, 1, s.length()) {
                int tmp = stoi(s.substr(0, i)) * stoi(s.substr(i));
                if (tmp == 0) break;
                p.pb(tmp);
            }
            int m = *max_element(all(p));
            if (h[m]) {
                count = -1;
                break;
            }
            n = m;
            h[m] = true;
            ++count;
        }
        
        cout << count << endl;
    }
    return EXIT_SUCCESS;
}