import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons,std.numeric,std.math;
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);}
void times(int n,void delegate() stmt){foreach(i;iota(n))stmt();}

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;iota(1,ns.length)){
		res ~= reduce!("a+b[0]*b[1]")(0,ns[0..i].zip(tens))
			*  reduce!("a+b[0]*b[1]")(0,ns[i..$].zip(tens)); 
	}
	return 1 + calc(reduce!(max)(0,res));
}
void main(){
	int n;read(n);
	n.times({
		int m;read(m);
		m.calc.writeln;
	});
}