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 <vector>
#include <string>
#include <algorithm>
#include <sstream>
using namespace std;

int main(int argc, char *argv[])
{
    int q, cnt, tmp;
    string n;
    vector<int>::iterator itr;
    cin >> q;
    while (cin >> n, q--) {
        vector<int> cache;
        for (cnt = 0;; ++cnt) {
            if (n.length() == 1)
                break;
            int kmax = 0;
            for (int i = 1; i < n.length(); ++i) {
                tmp = atoi(n.substr(0, i).c_str()) * atoi(n.substr(i).c_str());
                kmax = max(tmp, kmax);
            }
            itr = find(cache.begin(), cache.end(), kmax);
            if (itr != cache.end()) {
                cnt = -1;
                break;
            }
            else
                cache.push_back(kmax);
            stringstream ss;
            ss << kmax;
            n = ss.str();
        }
        cout << cnt << endl;
    }
    return 0;
}
[taguchi@Ken

C++: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

void ComputeKakezan(const string& lhs,const string& rhs,string& result){
  ll a = strtol(lhs.c_str(),NULL,10);
  ll b = strtol(rhs.c_str(),NULL,10);

  char str[32];
  sprintf(str,"%ld",a*b);
  result = str;
}

int main(){
  int n;
  while(~scanf("%d",&n)){
    for(int i=0;i<n;i++){
      int count = 0;
      string seed;
      cin >> seed;
      
      map<string,bool> visited;
      visited[seed] = true;

      string current_max = seed;

      while(current_max.size() > 1){
	ll tmp_max = 0;
	for(int i=0;i<current_max.size()-1;i++){
	  string lhs = current_max.substr(0,i+1);
	  string rhs = current_max.substr(i+1,current_max.size()-(i+1));

	  string result;
	  ComputeKakezan(lhs,rhs,result);

	  ll result_ll = strtol(result.c_str(),NULL,10);
	  tmp_max = max(result_ll,tmp_max);
	  
	  // cout << lhs <<"\n";
	  // cout << rhs <<"\n";
	}
	
	char tmp[100];
	sprintf(tmp,"%ld",tmp_max);
	current_max = tmp;
	// cout << current_max << "\n";
	count++;
	if(visited.find(current_max) != visited.end()){
	  if(current_max.size() != 1) count = -1;
	  break;
	}
	visited[current_max] = true;
      }

      printf("%d\n",count);
    }
  }
}