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 <iostream>
#include <string>
#include <unordered_set>

using namespace std;

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

        int count = 0;
        unordered_set<int> occurred;
        auto process = [&occurred](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);
            }
            if (occurred.find(max_) != end(occurred)) {
                return -1;
            }
            return max_;
        };
        while (true) {
            if (0 <= n && n <= 9) {
                break;
            }
            else if (n < 0) {
                count = -1;
                break;
            }
            n = process(n);
            count += 1;
        }
        cout << count << endl;
    }
}

C++: #include<stdio.h>

int main(){

int n;

scanf("%d",&n);if(n==0)break;
int x;
for(int i=0;i<n;i++)
{scanf("%d",&x);
int c=0;int d=10;int w=0,y=0;int max=0;
while(x/10!=0){
for(int j=0;j<6;j++)
{
w=x/d;y=x%d;d*=10;
if(j==0)max=w*y;
else if(w*y>max)max=w*y;}
x=max;c++;d=10;}
printf("%d\n",c);
}
return 0;
}

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

using namespace std;

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


int main(int argc, char const *argv[])
{
	int q;
	int n;
	string s;
	int max;
	int cnt;

	cin>>q;

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

		cnt=0;
		while(1){
			if(n/10==0) break;

			s=toString<int>(n);

			max=0;
			for(int i2=1;i2<s.size();i2++){
				int temp=(toInt(s.substr(0,i2)))*(toInt(s.substr(i2,s.size()-i2)));
				if(max<temp) max=temp;
			}
			n=max;
			cnt++;
			if(cnt>1000000) break;
		}
		if(cnt>1000000) cout<<-1<<endl;
		else cout<<cnt<<endl;

	}
	return 0;
}

C++: ///
// File:  2424.cpp
// Author: ymiyamoto
//
// Created on Thu Nov 16 21:38:19 2017
//

#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

int32_t main()
{
  uint32_t Q;
  cin >> Q;

  for (uint32_t _ = 0; _ < Q; _++) {
    string n;
    cin >> n;

    if (n[0] == '0') break;

    uint32_t count = 0;
    while (n.size() > 1) {
      count++;
      int32_t maxval = 0;
      for (uint32_t i = 1; i < n.size(); i++) {
        string n1 = n.substr(0, i);
        string n2 = n.substr(i, n.size() - i);
        maxval = max(maxval, stoi(n1) * stoi(n2));
      }
      if (n == to_string(maxval)) {
        count = -1;
        break;
      } else {
        n = to_string(maxval);
      }
    }
    cout << count << endl;
  }
  return 0;
}

C++: 
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stdlib.h>

using namespace std;

unsigned long long int power(unsigned long long int x, unsigned long long int n) {
	if(n == 0) return 1;
	if(n == 1) return x;
	if(x == 0) return 0;
	if(n % 2 == 1) {
		unsigned long long int y;
		y = power(x, (n - 1) / 2);
		return x*y*y;
	} else {
		unsigned long long int y;
		y = power(x, n / 2) ;
		return y*y;
	}
	return -1;
}

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);

	int Q;
	cin >> Q;
	vector<int> N;
	vector<int> ans;
	for(int i = 0; i < Q; i++) {
		unsigned long long int n_i;
		unsigned long long int p;
		int ans = 0;
		cin >> n_i;
		p = n_i;

		while( p > 9 ) {

			stringstream ss;
			ss << p;
			int max = 0;

			for(int i = 1; i < ss.str().length() ; i++) {
				unsigned long long int tmp;
				unsigned long long int div1, div2;
				tmp = power(10, i);
				div1 = p / tmp;
				div2 = p % tmp;
				if(div1 * div2 >= max) {
					p = div1 * div2;
					max = p;
				}
			}
			ans ++;

			if( p > n_i ) {
				ans = -1;
				p = -1;
			}

		}
		cout << ans << endl;
	}


	
	//while(1){}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,i,c,p,w,x,m,j,k,t;
  cin>>n;
  while(n--){
    cin>>a;c=0;
    while(1){
      for(m=0,t=b=a,i=-1;a;a/=10)i++;
      if(!i||!t)break;
      for(a=b,j=1;j<=i;j++){
        w=0;a=b=t;
        for(k=0;k!=j;k++){
          int o=1;
          p=a%10;
          for(x=1;x<=k;x++)o*=10;
          w+=o*p;
          a/=10;
        }
        while(x--)b/=10;
        if(w)m=max(m,w*b);
        else m=b;
      }
      a=m;
      c++;
    }
    cout<<c<<endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

int main(void){
    int p;
    cin>>p;
    rep(lp,p){
        string n;cin>>n;
        int ans=0;
        while(n.length()!=1){
            int mx=-1;
            range(i,1,n.length()){
                string a=n.substr(0,i);
                string b=n.substr(i);
                mx=max(mx,stoi(a)*stoi(b));
            }
            n=to_string(mx);
            ans++;
        }
        cout<<ans<<endl;
    }
}