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: #!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    while 1:
        n = II()
        ans = 0
        if n == 0:
            break
        i = 1
        while i < n / 2:
            tmp = 0
            l = i
            while tmp < n:
                tmp += l
                l += 1
            if tmp == n:
                ans += 1
            i += 1
        print(ans)  

    return

#B
def B():

    def f(x):
        tmp = 0
        for i in range(len(x)-1):
            x1 = int(x[:i+1])
            x2 = int(x[i+1:])
            tmp = max(tmp, x1 * x2)
        return tmp

    q = II()
    for i in range(q):
        ans = 0
        n = II()
        while n > 9:
            ans += 1
            n = f(str(n))

        print(ans)
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    R, C, K = LI()
    n = II()
    rc = LIR_(n)
    fldr = [0 for _ in range(R)]
    fldc = [0 for _ in range(C)]
    for r, c in rc:
        fldr[r] += 1
        fldc[c] += 1
    fldcs = fldc[::1]
    fldcs.sort()
    fldrs = fldr[::1]
    fldrs.sort()
    ans = 0
    dr = defaultdict(int)
    dc = defaultdict(int)
    for k in range(R):
        dr[fldr[k]] += 1
    for k in range(C):
        dc[fldc[k]] += 1
    for k in range(K+1):
        ans += dr[K - k] * dc[k]
    for r, c in rc:
        a = fldr[r] + fldc[c]
        if a == K:
            ans -= 1
        elif a == K + 1:
            ans += 1
    print(ans)
    return

#F
def F():
    n, m = LI()
    uvl = LIR_(m)
    dist = [[inf] * n for _ in range(n)]
    dist0 = defaultdict(int)
    full = []
    d = 0
    for u, v, l in uvl:
        if u == 0:
            dist0[v] = l + 1
            full.append(v)
            d += 1
        elif v == 0:
            dist0[u] = l + 1
            d += 1
            full.append(u)
        else:
            l += 1
            dist[u][v] = l
            dist[v][u] = l
    for i in range(n):
        dist[i][i] = 0
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    
    fulls = itertools.combinations(range(d), 2)
    ans = inf
    for a, b in fulls:
        a, b = full[a], full[b]
        tmp = dist0[a] + dist0[b] + dist[a][b]
        ans = min(ans, tmp)
    print(-1 if ans == inf else ans)
    return

#G
def G():
    s = S()
    s = s[::-1]
    M_count = s.count("M")
    M_lis = [0] * M_count
    M_count //= 2
    tmp = 0
    k = 0
    for i in range(len(s)):
        if s[i] == "+":
            tmp += 1
        elif s[i] == "-":
            tmp -= 1
        else:
            M_lis[k] = tmp
            k += 1
    M_lis.sort()
    print(-sum(M_lis[:M_count]) + sum(M_lis[M_count:]))


    return

#H
def H():
    def f(t):
        return a * t + b * math.sin(c * t * math.pi)
    a, b, c = LI()
    ok = 99 // a + 1
    ng = 0
    while 1:
        t = (ok + ng) / 2
        ft = f(t)
        if abs(ft - 100) <= 10 ** (-6):
            print(t)
            return
        if ft > 100:
            ok = t
        if ft < 100:
            ng = t
    return

#Solve
if __name__ == '__main__':
    B()

Python: q = int(input())
num = [int(input()) for _ in range(q)]
for n in num:
    cnt = 0
    mulnum = [n]
    while True:
        strn = str(n)
        if len(strn) == 1:
            break
        m = 0
        for i in range(len(strn) - 1):
            m = max(m, int(strn[:i+1]) * int(strn[i+1:]))
        if m in mulnum:
            cnt = -1
            break
        else:
            cnt += 1
            mulnum.append(m)
            n = m
    print(cnt)

Python: for _ in range(int(input())):
    n=int(input())
    a=0;b=[]
    while n//10:
        a+=1
        b+=[n]+b
        x=1;s=m=0
        while n:
            s+=x*(n%10)
            n//=10
            x*=10
            m=max(s*n,m)
        n=m
        if b[-1]==n:print(-1);break
    else:print(a)

Python: import math
for _ in range(int(input())):
    n=int(input())
    c=0
    while n>9:
        c+=1
        n=max((n//(10**x))*(n%(10**x)) for x in range(1,int(math.log10(n))+1))
    print(c)

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)