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

Python: #times volume24 2424
Q=int(input())
for i in range(Q):
    N=str(input())
    c=0
    while len(N)>1 and c<15:
        M=0
        for j in range(1,len(N)):
  #          print(N[:j])
            l=int(N[:j])
            r=int(N[j:])
            l*=r
            if M<l:
                M=l
        #    print(M)
        N=str(M)
        c+=1
    if c>=15:
        d=[int(N)]
        while c>=0 and c<50:
            while len(N)>1 and c<50:
                M=0
                for j in range(1,len(N)):
  #          print(N[:j])
                    l=int(N[:j])
                    r=int(N[j:])
                    l*=r
                    if M<l:
                        M=l
        #    print(M)
                k=0
                while k<len(d) and M<d[k]:
                    k+=1
                if M==d[k]:
                    c=-1
                else:
                    d.insert(j,M)
                N=str(N)
    print(c)

Python: def solve(s):
    return max(int(s[:i]) * int(s[i:]) for i in range(1, len(s)))

for _ in range(int(input())):
    s = input()
    cnt = 0
    while len(s) > 1:
        cnt += 1
        s = str(solve(s))
    print(cnt)

Python: def split(x):
    assert(isinstance(x, int))
    sx = str(x)
    l = len(sx)
    candidates = []
    for idx in range(1, l):
        first = sx[idx:]
        candidates.append(int(sx[:idx]) * int(sx[idx:]))
    if len(candidates) == 0:
        return None
    else:
        return max(candidates)


def problem1():
    Q = input()
    answers = []
    for _ in range(int(Q)):
        N = int(input())
        x = N
        cnt = 0
        while True:
            next_x = split(x)
            if next_x is None:
                break
            elif x == next_x:
                cnt = -1
                break
            else:
                cnt += 1
            x = next_x
        answers.append(str(cnt))
    print('\n'.join(answers))


if __name__ == '__main__':
    problem1()

Python: Q = int(input())

def solve(x,ans):
    #X = str(x)
    print(x,ans)
    if len(x) == 1:
#        print(ans)
        return
    ret= 0
    for i in range(1,len(x)):
        n = int(x[i:]) * int(x[:i])
        ret = max(ret , n)
        
    #print(ret)
    return solve(str(ret),ans + 1)

for i in range(Q):
    solve(input(),0)

Python: def recur(n, count):
    if n < 10:
        print(count)
        return
    part = []
    i = 10
    while i < n:
        part.append((n%i) * (n/i))
        i *= 10
    recur(max(part), count+1)


q = int(raw_input())
for i in range(q):
    n = int(raw_input())
    lst = []
    recur(n, 0)

Python: Q = int(input())

def solve(x,ans):
    X = str(x)
    if len(X) == 1:
        print(ans)
        return
    ret= 0
    for i in range(1,len(X)):
        n = int(X[i:]) * int(X[:i])
        ret = max(ans,n)
        
    #print(ret)
    return solve(ret,ans + 1)

for i in range(Q):
    solve(int(input()),0)

Python: from math import log10

for i in range(int(input())):
    n = int(input())
    j = 0
    while n >= 10:
        n = max((n / (10**k)) * (n % (10**k))
                for k in range(1, int(log10(n)) + 1))
        j += 1
    print(j)

Python: def calc(n):
    if n>=10 and n<100:
        return (n//10)*(n%10)
    elif n>=100 and n<1000:
        r1=(n//10)*(n%10)
        r2=(n//100)*(n%100)
        return max(r1,r2)
    elif n>=1000 and n<10000:
        r1=(n//10)*(n%10)
        r2=(n//100)*(n%100)
        r3=(n//1000)*(n%1000)
        return max(r1,r2,r3)
    elif n>=10000 and n<100000:
        r1=(n//10)*(n%10)
        r2=(n//100)*(n%100)
        r3=(n//1000)*(n%1000)
        r4=(n//10000)*(n%10000)
        return max(r1,r2,r3,r4)
    elif n>=100000 and n<1000000:
        r1=(n//10)*(n%10)
        r2=(n//100)*(n%100)
        r3=(n//1000)*(n%1000)
        r4=(n//10000)*(n%10000)
        r5=(n//100000)*(n%100000)
        return max(r1,r2,r3,r4,r5)
    else:
        r1=(n//10)*(n%10)
        r2=(n//100)*(n%100)
        r3=(n//1000)*(n%1000)
        r4=(n//10000)*(n%10000)
        r5=(n//100000)*(n%100000)
        r6=(n//1000000)*(n%1000000)
        return max(r1,r2,r3,r4,r5,r6)
n=int(input())


for i in range(n):
    cnt=0
    a=int(input())
    while a>=10:
        a=calc(a)
        cnt+=1

    print(cnt)

Python: #!/usr/bin/env python
Q = input()

for loop in range(Q):
	n = str(input())
	cnt = 0
	while len(n) > 1:
		cnt += 1
		nmin = 0
		for i in range(len(n) - 1):
			n1 = int(n[:i + 1])
			n2 = int(n[i + 1:])
			nmin = max(nmin, n1 * n2)
		n = str(nmin)
	print(cnt)

Python: for i in range(int(input())):
    n = int(input())
    j = 0
    while n >= 10:
        m_max = 0
        for k in range(1, int(log10(n)) + 1):
            m = (n // (10**k)) * (n % (10**k))
            if m >= m_max:
                m_max = m
        n = m_max
        j += 1
    print(j)

Python: Q = int(input())
for i in range(Q):
    n = int(input())
    ans = 0
    while n >= 10:
        s = str(n)
        a = 0
        for i in range(len(s) - 1):
            a = max(a, int(s[:i + 1]) * int(s[i + 1:]))
        n = a
        ans += 1
    print(ans)