#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        q = input()
        for i in range(q):
            n = input()
            tmp = n
            ans = 0
            while tmp >= 10:
                max_val = -1
                s = str(tmp)
                for j in range(len(s)-1):
                    left = int(s[:j+1])
                    right = int(s[j+1:])
                    max_val = max(max_val, left * right)
                tmp = max_val
                ans += 1
            print ans
                    
        
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()