import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

int solve (string s)
{
	s = s.strip ('1');
	if (s.empty)
	{
		return 0;
	}
	if (s.all !(q{a == '0'}))
	{
		return 1;
	}
	return 2;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		readln.strip.solve.writeln;
	}
}
