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++: ///
// 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;

    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 <ios>
#include <set>
#include <cstdlib>
#include <cstdio>
using namespace std;
int main(void) {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    for(int iter = 0; iter < n; iter++) {
        string t;
        cin >> t;

        int count = 0;
        set<string> visited;
        while(true) {
            visited.insert(t);
            const int L = t.length();
            if(L == 1) {
                break;
            }
            int m = 0;
            for(int i = 1; i < L; ++i) {
                int a = atoi(t.substr(0, i).c_str());
                int b = atoi(t.substr(i).c_str());
                m = max(m, a * b);
            }
            char buffer[1000];
            snprintf(buffer, 1000, "%d", m);
            t = string(buffer);
            if(visited.find(t) != visited.end()) {
                count = -1;
                break;
            }
            count += 1;
        }
        cout << count << endl;
    }
    return 0;
}

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;
}

C++: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

int change_to_i(string s){
    stringstream ss; int k;
    ss << s; ss >> k;
    return k;
}
string change_to_s(int k){
    stringstream ss; string s;
    ss << k; ss >> s;
    return s;
}

signed main(){
    int q;
    cin >> q;
    rep(x, 0, q){
        string s;
        cin >> s;
        for(int ans = 0;; ans++){
            if(s.size() == 1){
                cout << ans << endl;
                break;
            }
            /*if(ans > 1000000){
                cout << -1 << endl;
                break;
            }*/
            string t1, t2;
            int MAX = 0, n1, n2;
            rep(i, 1, s.size()){
                t1 = s.substr(0, i);
                t2 = s.substr(i, s.size() - i);
                n1 = change_to_i(t1);
                n2 = change_to_i(t2);
                int tmp = n1*n2;
                //cout << t1 << ' ' << t2 << endl;
                //cout << n1 << ' ' << n2 << ' ' << tmp << endl;
                MAX = max(MAX, tmp);
            }
            s = change_to_s(MAX);
            //cout << ' ' << MAX << ' ' << s << endl;
        }
    }
}

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

int solve(int x) {
	int count = 0;
	while (x >= 10) {
		int ma = 0;
		for (int s = 10; x / s > 0; s *= 10) {
			int d = x / s;
			int m = x % s;
			ma = max(ma, d * m);
		}
		x = ma;
		count++;
	}
	return count;
}

int main () {
	int n;
	for (cin >> n; n; n--) {
		int x;
		cin >> x;
		cout << solve(x) << endl;
	}
	return 0;
}