fun main(args: Array<String>?): Unit {
    println(
            solve(IntArray(readLine()!!.trim().toInt()){ readLine()!!.trim().toInt()}).joinToString("\n")
    )
}



fun solve(numbers: IntArray): List<Int> {
    val memo = HashMap<Long, Int>()
    fun solve(value: Long): Int {
        return if (value < 10) 0
        else if (memo.containsKey(value)) memo[value]!!
        else {
            memo[value] = -1
            val r = solve((0 .. Math.log10(value.toDouble()).toInt()).map{digit -> exp10(digit).let{d -> (value / d) * (value % d)}}.max()!!).takeIf{it >= 0}
            if (r != null) {
                memo.replace(value, r + 1)
                r + 1
            }else -1
        }
    }
    val r = numbers.map{solve(it.toLong())}
    return r
}
fun exp10(e: Int): Long {
    return when(e){
        0 -> 1L
        1 -> 10L
        else -> exp10(e / 2).let{it * it * exp10(e % 2)}
    }
}
