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

immutable int steps = 10;

int solve (string s, int team)
{
	int [2] goals;
	foreach (step; 0..steps)
	{
		auto cur = (s[step] == '0') ? 0 :
		    (s[step] == '1') ? 1 : (step % 2 == team);
		goals[step % 2] += cur;
		if (goals[0] + (steps - 1 - step + 0) / 2 < goals[1] ||
		    goals[1] + (steps - 1 - step + 1) / 2 < goals[0])
		{
			return step + 1;
		}
	}
	return steps;
}

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