import std.stdio, std.string, std.algorithm, std.array;

void main()
{
    int t;
    scanf("%d", &t);
    getchar();
    foreach(i; 0..t){
	auto str = readln.strip();
	string result;
	while (str.length > 0)
	{
		result ~= str[0];
		str = str.stripLeft(str[0]);
	}
	if (result.length > 3)
		writeln(2);
	else if (result == "0")
		writeln(1);
	else if (result == "1")
		writeln(0);
	else if (result == "01" || result == "10")
		writeln(1);
	else if (result == "101")
		writeln(1);
	else
		writeln(2);
    }
}
