import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons,std.numeric,std.math,std.random,std.concurrency;
const dx = [1,0,-1,0], dy = [0,1,0,-1];
const readMixin = q{ auto line = readln().split();foreach(i,ref arg; args){ if (i >= line.length) return;arg = line[i].to!(typeof(arg));}};
void read(T...)  (auto ref T args){ mixin(readMixin);}
void readArray(T)(auto ref T args){ mixin(readMixin);}
int read(){int n;read(n);return n;}
void times(int n,void delegate() stmt){foreach(i;iota(n))stmt();}
auto infIota = (int i=0) => new std.concurrency.Generator!int({for(;;)yield(i++);});
auto dot(R1,R2)(R1 a,R2 b){ElementType!(R1) res=0;for(;!a.empty&&!b.empty;a.popFront(),b.popFront())res+=a.front*b.front;return res;}

int calc(int n){
	if (n < 10) return 0;
	int [] ns;
	while(n){ns ~= n % 10;n /= 10;}
	int [] res;
	auto tens = ()=> iota(ns.length).map!"10^^a";
	foreach(i;1 .. ns.length){
		res ~= ns[0..i].dot(tens()) * ns[i..$].dot(tens());
	}
	return 1 + calc(res.reduce!(max));
}
void main(){ 
	read().times({ read().calc.writeln; });
}