Consider a simplified penalty phase at the end of a football match.

A penalty phase consists of at most $10$ kicks, the first team takes the first kick, the second team takes the second kick, then the first team takes the third kick, and so on. The team that scores more goals wins; if both teams score the same number of goals, the game results in a tie (note that it goes against the usual football rules). The penalty phase is stopped if one team has scored more goals than the other team could reach with all of its remaining kicks. For example, if after the $7$-th kick the first team has scored $1$ goal, and the second team has scored $3$ goals, the penalty phase ends — the first team cannot reach $3$ goals.

You know which player will be taking each kick, so you have your predictions for each of the $10$ kicks. These predictions are represented by a string $s$ consisting of $10$ characters. Each character can either be 1, 0, or ?. This string represents your predictions in the following way:

if $s_i$ is 1, then the $i$-th kick will definitely score a goal;

if $s_i$ is 0, then the $i$-th kick definitely won't score a goal;

if $s_i$ is ?, then the $i$-th kick could go either way.

Based on your predictions, you have to calculate the minimum possible number of kicks there can be in the penalty phase (that means, the earliest moment when the penalty phase is stopped, considering all possible ways it could go). Note that the referee doesn't take into account any predictions when deciding to stop the penalty phase — you may know that some kick will/won't be scored, but the referee doesn't.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases.

Each test case is represented by one line containing the string $s$, consisting of exactly $10$ characters. Each character is either 1, 0, or ?.


-----Output-----

For each test case, print one integer — the minimum possible number of kicks in the penalty phase.


-----Examples-----

Input
4
1?0???1001
1111111111
??????????
0100000000
Output
7
10
6
9


-----Note-----

Consider the example test:

In the first test case, consider the situation when the $1$-st, $5$-th and $7$-th kicks score goals, and kicks $2$, $3$, $4$ and $6$ are unsuccessful. Then the current number of goals for the first team is $3$, for the second team is $0$, and the referee sees that the second team can score at most $2$ goals in the remaining kicks. So the penalty phase can be stopped after the $7$-th kick.

In the second test case, the penalty phase won't be stopped until all $10$ kicks are finished.

In the third test case, if the first team doesn't score any of its three first kicks and the second team scores all of its three first kicks, then after the $6$-th kick, the first team has scored $0$ goals and the second team has scored $3$ goals, and the referee sees that the first team can score at most $2$ goals in the remaining kicks. So, the penalty phase can be stopped after the $6$-th kick.

In the fourth test case, even though you can predict the whole penalty phase, the referee understands that the phase should be ended only after the $9$-th kick.

Source: codeforces | Difficulty: EASY
Tags: Dynamic programming

Bit manipulation

Complete search

Greedy algorithms


Solutions:
for i in range(int(input())):
	s = list(input())
	(a, b) = (0, 0)
	ans = float('inf')
	for j in range(10):
		if s[j] == '1':
			if j % 2 == 0:
				a += 1
			else:
				b += 1
		elif s[j] == '?' and j % 2 == 0:
			a += 1
		if a > b:
			c = 0
			for cc in range(j + 1, 10):
				if cc % 2 != 0:
					c += 1
			if b + c < a:
				ans = min(ans, j + 1)
		elif a < b:
			c = 0
			for cc in range(j + 1, 10):
				if cc % 2 == 0:
					c += 1
			if a + c < b:
				ans = min(ans, j + 1)
	(a, b) = (0, 0)
	for j in range(10):
		if s[j] == '1':
			if j % 2 == 0:
				a += 1
			else:
				b += 1
		elif s[j] == '?' and j % 2 != 0:
			b += 1
		if a > b:
			c = 0
			for cc in range(j + 1, 10):
				if cc % 2 != 0:
					c += 1
			if b + c < a:
				ans = min(ans, j + 1)
		elif a < b:
			c = 0
			for cc in range(j + 1, 10):
				if cc % 2 == 0:
					c += 1
			if a + c < b:
				ans = min(ans, j + 1)
	print(min(ans, 10))


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
from typing import Counter
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():

	def solve(index, f, s, kick1, kick2, s1):
		if index == len(s1):
			return 0
		if f + kick1 < s:
			return 0
		if s + kick2 < f:
			return 0
		if s1[index] == '1':
			if index % 2 == 0:
				return 1 + solve(index + 1, f + 1, s, kick1 - 1, kick2, s1)
			else:
				return 1 + solve(index + 1, f, s + 1, kick1, kick2 - 1, s1)
		if s1[index] == '0':
			if index % 2 == 0:
				return 1 + solve(index + 1, f, s, kick1 - 1, kick2, s1)
			else:
				return 1 + solve(index + 1, f, s, kick1, kick2 - 1, s1)
		elif index % 2 == 0:
			return 1 + min(solve(index + 1, f + 1, s, kick1 - 1, kick2, s1), solve(index + 1, f, s, kick1 - 1, kick2, s1))
		else:
			return 1 + min(solve(index + 1, f, s + 1, kick1, kick2 - 1, s1), solve(index + 1, f, s, kick1, kick2 - 1, s1))
	t = int(input())
	while t:
		s = input()
		print(solve(0, 0, 0, 5, 5, s))
		t -= 1
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	s = input()
	arr = []
	for i in range(2 ** 10):
		x = bin(i).split('b')[1]
		x = '0' * (10 - len(x)) + x
		f = 0
		for j in range(10):
			if s[j] == '?':
				continue
			if s[j] == x[j]:
				pass
			else:
				f = 1
		if f == 0:
			arr.append(x)
	ans = 10
	for i in arr:
		(a, b) = (0, 0)
		for j in range(10):
			if j % 2 == 0:
				a += int(i[j])
			else:
				b += int(i[j])
			if j % 2 == 0:
				rem = 9 - j
				rem = (rem + 1) // 2
				if rem + b < a:
					ans = min(ans, j + 1)
					break
				rem = (9 - j) // 2
				if a + rem < b:
					ans = min(ans, j + 1)
			else:
				rem = 9 - j
				rem = rem // 2
				if rem + a < b:
					ans = min(ans, j + 1)
					break
				if b + rem < a:
					ans = min(ans, j + 1)
	print(ans)


t = int(input())

def can_stop(first_score, second_score, num_kicks):
	if second_score < first_score and num_kicks % 2 == 1:
		return abs(first_score - (second_score + 1)) > (10 - num_kicks) // 2
	return abs(first_score - second_score) > (10 - num_kicks) // 2
for i in range(t):
	s = input()
	first_score = 0
	second_score = 0
	first_case = 1
	while first_case < 10:
		if first_case % 2 == 1 and s[first_case - 1] != '0':
			first_score += 1
		elif first_case % 2 == 0 and s[first_case - 1] == '1':
			second_score += 1
		if can_stop(first_score, second_score, first_case):
			break
		first_case += 1
	first_score = 0
	second_score = 0
	second_case = 1
	while second_case < 10:
		if second_case % 2 == 1 and s[second_case - 1] == '1':
			first_score += 1
		elif second_case % 2 == 0 and s[second_case - 1] != '0':
			second_score += 1
		if can_stop(first_score, second_score, second_case):
			break
		second_case += 1
	print(min(first_case, second_case))


t = int(input())
for _ in range(t):
	s = input()
	q = s.count('?')
	mn = 9
	for i in range(2 ** q):
		temp = []
		for j in range(q):
			if 2 ** j & i != 0:
				temp += ['1']
			else:
				temp += ['0']
		x = list(map(lambda x: temp.pop(0) if x == '?' else x, s))
		team = [0, 0]
		for j in range(10):
			if x[j] == '1':
				team[j % 2] += 1
			if j % 2 == 0:
				if team[0] > team[1] + 5 - j // 2 or team[1] > team[0] + 5 - (j // 2 + 1):
					mn = min(mn, j)
					break
			elif team[1] > team[0] + 5 - (j // 2 + 1) or team[0] > team[1] + 5 - (j // 2 + 1):
				mn = min(mn, j)
				break
	print(mn + 1)


from sys import stdin, stdout

def main():
	for _ in range(int(input())):
		s = input()
		first = 0
		second = 0
		(f1, s1) = (5, 5)
		r = 0
		for (i, v) in enumerate(s):
			if i % 2 == 0:
				if v == '1' or v == '?':
					first += 1
				f1 -= 1
			else:
				if v == '1':
					second += 1
				s1 -= 1
			if first > second:
				if first - second > s1:
					r = i + 1
					break
			elif second - first > f1:
				r = i + 1
				break
		else:
			r = 10
		(f1, s1) = (5, 5)
		(first, second) = (0, 0)
		r1 = 0
		for (i, v) in enumerate(s):
			if i % 2 == 0:
				if v == '1':
					first += 1
				f1 -= 1
			else:
				if v == '1' or v == '?':
					second += 1
				s1 -= 1
			if first > second:
				if first - second > s1:
					r1 = i + 1
					break
			elif second - first > f1:
				r1 = i + 1
				break
		else:
			r1 = 10
		print(min([r, r1]))
main()


def fun(s):
	first = [0, 0]
	second = [0, 0]
	for i in range(1, 11):
		if s[i - 1] == '1' and i % 2 != 0:
			first[0] += 1
			second[0] += 1
		elif s[i - 1] == '1' and i % 2 == 0:
			first[1] += 1
			second[1] += 1
		elif s[i - 1] == '?' and i % 2 != 0:
			first[0] += 1
		elif s[i - 1] == '?' and i % 2 == 0:
			second[1] += 1
		if (10 - i + 1) // 2 + first[1] < first[0]:
			return i
		if (10 - i) // 2 + second[0] < second[1]:
			return i
	return 10
t = int(input())
for i in range(t):
	s = input()
	print(fun(s))


import sys
Input = sys.stdin.readlines()
Output = ''
tests = int(Input[0])
for t in range(tests):

	def f(s):
		(sa, sb, ca, cb) = (0, 0, 5, 5)
		for i in range(10):
			if i & 1:
				sa += s[i]
				ca -= 1
			else:
				sb += s[i]
				cb -= 1
			if sa + ca < sb or sb + cb < sa:
				return i + 1
		return 10
	s = Input[t + 1].strip()
	a = [1 if s[i] == '1' else 0 if s[i] == '0' else i & 1 for i in range(10)]
	b = [1 if s[i] == '1' else 0 if s[i] == '0' else 1 ^ i & 1 for i in range(10)]
	ans = min(f(a), f(b))
	Output += str(ans) + '\n'
print(Output)


for s in [*open(0)][1:]:
	p = q = i = 0
	j = 1
	while i < 10 and p < 13 - i >> 1 and (q < 12 - i >> 1):
		p += j * (s[i] in '1' + (i % 2 ^ 1) * '?')
		q -= j * (s[i] in '1' + i % 2 * '?')
		i += 1
		j = -j
	print(i)


for _ in range(int(input())):
	s = input()
	one_best = [0 for x in range(10)]
	common = [0 for x in range(10)]
	two_best = [0 for x in range(10)]
	(team1, team2, bo, bt) = (0, 0, 0, 0)
	(one_rem, two_rem) = (5, 5)
	for i in range(10):
		if i == 0 or i % 2 == 0:
			if s[i] == '1':
				one_best[i] += 1
				common[i] += 1
			elif s[i] == '?':
				one_best[i] += 1
		elif i == 1 or i % 2 != 0:
			if s[i] == '1':
				two_best[i] += 1
				common[i] += 1
			elif s[i] == '?':
				two_best[i] += 1
	for i in range(10):
		if i == 0 or i % 2 == 0:
			team1 += one_best[i]
			bo += common[i]
			one_rem -= 1
		elif i == 1 or i % 2 != 0:
			team2 += two_best[i]
			bt += common[i]
			two_rem -= 1
		if team1 - bt > two_rem or team2 - bo > one_rem:
			print(i + 1)
			break
	else:
		print(10)


def test():
	x = 10
	s = input()
	s = 'q' + s
	a = 0
	b = 0
	for i in range(1, 11):
		if i % 2 == 1:
			if s[i] == '1' or s[i] == '?':
				a += 1
			if (10 - i + 1) // 2 + b < a:
				x = min(x, i)
		else:
			if s[i] == '1':
				b += 1
			if (10 - i) // 2 + b < a:
				x = min(x, i)
	a = 0
	b = 0
	for i in range(1, 11):
		if i % 2 == 1:
			if s[i] == '1':
				a += 1
			if (10 - i) // 2 + a < b:
				x = min(x, i)
		else:
			if s[i] == '1' or s[i] == '?':
				b += 1
			if (10 - i) // 2 + a < b:
				x = min(x, i)
	print(x)
t = int(input())
while t:
	test()
	t -= 1


for i in range(int(input())):
	l = input()
	w1 = 5
	v1 = 0
	w2 = 5
	v2 = 0
	a = 10
	for j in range(len(l)):
		if v1 > w2 + v2 or v2 > w1 + v1:
			a = min(a, j)
		if l[j] == '1':
			if j % 2 == 0:
				w1 -= 1
				v1 += 1
			else:
				w2 -= 1
				v2 += 1
		elif l[j] == '0':
			if j % 2 == 0:
				w1 -= 1
			else:
				w2 -= 1
		elif j % 2 == 0:
			w1 -= 1
			v1 += 1
		else:
			w2 -= 1
	w1 = 5
	v1 = 0
	w2 = 5
	v2 = 0
	for j in range(len(l)):
		if v1 > w2 + v2 or v2 > w1 + v1:
			a = min(a, j)
		if l[j] == '1':
			if j % 2 == 0:
				w1 -= 1
				v1 += 1
			else:
				w2 -= 1
				v2 += 1
		elif l[j] == '0':
			if j % 2 == 0:
				w1 -= 1
			else:
				w2 -= 1
		elif j % 2 == 0:
			w1 -= 1
		else:
			w2 -= 1
			v2 += 1
	print(a)


import sys
import math
from math import *
import builtins
import collections
input = sys.stdin.readline

def print(x, end='\n'):
	sys.stdout.write(str(x) + end)

def get_int():
	return int(input())

def get_list_ints():
	return list(map(int, input().split()))

def get_char_list():
	s = input()
	return list(s[:len(s) - 1])

def get_tuple_ints():
	return tuple(map(int, input().split()))

def print_iterable(p):
	print(' '.join(map(str, p)))

def CountFrequency(arr):
	return collections.Counter(arr)

def binary_search(arr, x):
	low = 0
	high = len(arr) - 1
	mid = 0
	while low <= high:
		mid = (high + low) // 2
		if arr[mid] < x:
			low = mid + 1
		elif arr[mid] > x:
			high = mid - 1
		else:
			return mid
	return high

def pow(a, n):
	if n == 0:
		return 1
	elif n % 2 == 0:
		return pow(a, n // 2) % const * (pow(a, n // 2) % const) % const
	else:
		return pow(a, n // 2) % const * (pow(a, n // 2) % const) * (a % const) % const

def main():
	t = get_int()
	for i in range(t):
		s = get_char_list()
		matches = 0
		pointsp1 = 0
		pointsp2 = 0
		i = 0
		while pointsp1 - pointsp2 <= math.ceil((10 - matches) / 2) and i < len(s):
			if i % 2 == 0:
				if s[i] == '1' or s[i] == '?':
					pointsp1 += 1
			elif s[i] == '1':
				pointsp2 += 1
			i += 1
			matches += 1
		matches2 = 0
		poin1 = 0
		poin2 = 0
		i = 0
		while poin2 - poin1 <= math.floor((10 - matches2) / 2) and i < len(s):
			if i % 2 == 0:
				if s[i] == '1':
					poin1 += 1
			elif s[i] == '1' or s[i] == '?':
				poin2 += 1
			i += 1
			matches2 += 1
		print(min(matches, matches2))
	pass
main()


for case in range(int(input())):
	s = input()
	n = len(s)
	count_a = 0
	count_b = 0
	for i in range(n):
		if s[i] == '?' or (i % 2 == 0 and s[i] == '0') or (i % 2 == 1 and s[i] == '1'):
			count_a += 1
		if s[i] == '?' or (i % 2 == 0 and s[i] == '1') or (i % 2 == 1 and s[i] == '0'):
			count_b += 1
		if 2 * count_a > n or 2 * count_b > n:
			print(i + 1)
			break
	else:
		print(n)


import sys
from os import path
input = lambda : sys.stdin.readline().rstrip()
from functools import lru_cache
if path.exists('Input.txt'):
	sys.stdin = open('Input.txt', 'r')
	sys.stdout = open('Output.txt', 'w')

@lru_cache(5)
def score(a, b, p1, p2, s1, s2):
	if a > b:
		if 4 - p2 < a - b:
			return p1 + p2 + 2
	elif a < b:
		if 4 - p1 < b - a:
			return p1 + p2 + 2
	elif p2 == 4:
		return 10
	if p1 == p2:
		p1 += 1
		if s1[p1] == '?':
			return min(score(a + 1, b, p1, p2, s1, s2), score(a, b, p1, p2, s1, s2))
		else:
			return score(a + int(s1[p1]), b, p1, p2, s1, s2)
	else:
		p2 += 1
		if s2[p2] == '?':
			return min(score(a, b + 1, p1, p2, s1, s2), score(a, b, p1, p2, s1, s2))
		else:
			return score(a, b + int(s2[p2]), p1, p2, s1, s2)

def solve_tc():
	s = input()
	s1 = s[0::2]
	s2 = s[1::2]
	return score(0, 0, -1, -1, s1, s2)
t = int(input())
for _ in range(t):
	sys.stdout.write(str(solve_tc()))
	sys.stdout.write('\n')


import os, sys, math
from io import BytesIO, IOBase
from collections import defaultdict, deque, OrderedDict
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

def I():
	return int(input())

def In():
	return map(int, input().split())

def ln():
	return list(map(int, input().split()))

def Sn():
	return input().strip()
BUFSIZE = 8192

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return len(a)

def solve():
	global A
	A = list(Sn())
	temp = [''.join(A)]
	for i in range(10):
		if A[i] == '?':
			loc = []
			for x in temp:
				t = list(x)
				t[i] = '1'
				loc.append(''.join(t))
				t[i] = '0'
				loc.append(''.join(t))
			temp.clear()
			temp = loc.copy()
	ans = 10
	for x in temp:
		(a, b) = (0, 0)
		for i in range(10):
			if i % 2 == 0:
				if x[i] == '1':
					a += 1
				if a - b > 5 - (i + 1) // 2:
					ans = min(ans, i + 1)
				elif b - a > 5 - (i + 2) // 2:
					ans = min(ans, i + 1)
			elif i % 2 == 1:
				if x[i] == '1':
					b += 1
				if b - a > 5 - (i + 1) // 2:
					ans = min(ans, i + 1)
				elif a - b > 5 - (i + 1) // 2:
					ans = min(ans, i + 1)
	print(ans)
	pass

def main():
	T = I()
	for i in range(T):
		solve()
M = 998244353
P = 1000000007

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def solve():
	s = input()
	ans = []
	(a, b) = (0, 0)
	for ind in range(10):
		if s[ind] == '1':
			if ind % 2 == 0:
				a += 1
			else:
				b += 1
		if s[ind] == '?' and ind % 2 == 0:
			a += 1
		if a > b + (10 - ind) // 2 or b > a + (10 - ind - 1) // 2:
			ans.append(ind + 1)
			break
		if ind == 9:
			ans.append(10)
			break
	(a, b) = (0, 0)
	for ind in range(10):
		if s[ind] == '1':
			if ind % 2 == 0:
				a += 1
			else:
				b += 1
		if s[ind] == '?' and ind % 2 == 1:
			b += 1
		if a > b + (10 - ind) // 2 or b > a + (10 - ind - 1) // 2:
			ans.append(ind + 1)
			break
		if ind == 9:
			ans.append(10)
			break
	print(min(ans))
t = int(input())
while t:
	solve()
	t -= 1


t = int(input())

def solve():
	s = list(input())
	ans = 10
	s1 = s.copy()
	for i in range(10):
		if s1[i] == '?':
			if i % 2 == 0:
				s1[i] = '1'
			else:
				s1[i] = '0'
	team1 = 0
	team2 = 0
	rem = 5
	for i in range(10):
		if i % 2 == 0:
			team1 += int(s1[i])
		else:
			team2 += int(s1[i])
			rem -= 1
		maxTeam2 = rem + team2
		if team1 > maxTeam2:
			ans = i + 1
			break
	s2 = s.copy()
	for i in range(10):
		if s2[i] == '?':
			if i % 2 == 0:
				s2[i] = '0'
			else:
				s2[i] = '1'
	team1 = 0
	team2 = 0
	rem = 5
	for i in range(10):
		if i % 2 == 1:
			team1 += int(s2[i])
		else:
			team2 += int(s2[i])
			rem -= 1
		if team1 > rem + team2:
			ans = min(ans, i + 1)
			break
	print(ans)
for i in range(t):
	solve()


for s in [*open(0)][1:]:
	a = b = i = 0
	j = 1
	while (i < 10) * (a < 13 - i >> 1) * (b < 12 - i >> 1):
		a += j * (s[i] in '1' + '?' * j)
		j = -j
		b += j * (s[i] in '1' + '?' * j)
		i += 1
	print(i)


for _ in range(int(input())):
	s = input()
	p1 = 0
	p2 = 0
	r1 = 5
	r2 = 5
	d1 = 0
	d2 = 0
	flag = 0
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '1':
				p1 += 1
			elif s[i] == '?':
				d1 += 1
			r1 -= 1
			if p1 + d1 > p2 + r2 or p2 + d2 > p1 + r1:
				print(i + 1)
				flag = 1
				break
		else:
			if s[i] == '1':
				p2 += 1
			elif s[i] == '?':
				d2 += 1
			r2 -= 1
			if p1 + d1 > p2 + r2 or p2 + d2 > p1 + r1:
				print(i + 1)
				flag = 1
				break
	if not flag:
		print(10)


for _ in range(int(input())):
	s = input()
	a = 0
	b = 0
	ra = 5
	rb = 5
	ca = 0
	cb = 0
	ans = 10
	for i in range(10):
		if i % 2 == 0:
			ra = ra - 1
			if s[i] == '1':
				a = a + 1
			elif s[i] == '?':
				ca = ca + 1
		else:
			rb = rb - 1
			if s[i] == '1':
				b = b + 1
			elif s[i] == '?':
				cb = cb + 1
		if cb + b - a > ra or ca + a - b > rb:
			ans = i + 1
			break
	print(ans)


t = int(input())

def solve():
	s = input()
	case1 = 0
	res1 = 10
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '?':
				case1 += 1
			else:
				case1 += int(s[i])
		elif s[i] != '?':
			case1 -= int(s[i])
		if case1 > (10 - i) // 2:
			res1 = i + 1
			break
	case2 = 0
	res2 = 10
	for i in range(10):
		if i % 2 == 0:
			if s[i] != '?':
				case2 -= int(s[i])
		elif s[i] == '?':
			case2 += 1
		else:
			case2 += int(s[i])
		if case2 > (9 - i) // 2:
			res2 = i + 1
			break
	print(min(res1, res2))
for _ in range(t):
	solve()


import sys
import math
from collections import deque
from bisect import bisect_left, bisect_right
I = sys.stdin.readline
II = lambda : int(I())
IN = lambda x: map(int, x.split())
FN = lambda x: map(float, x.split())
L = lambda x: list(IN(x))
M = 1000000007
P = print
T = True
F = False

def how(ns):
	fs = 0
	ss = 0
	for i in range(5):
		if ns[i] == '1':
			if i & 1 == 1:
				ss += 1
			else:
				fs += 1
	for i in range(6, 11):
		if ns[i - 1] == '1':
			if i & 1 == 1:
				fs += 1
				t = fs - ss
				if i == 7 and t > 2 or (i == 9 and t > 1):
					return i
			else:
				ss += 1
				t = ss - fs
				if i == 6 and t > 2 or (i == 8 and t > 1):
					return i
		elif i & 1 == 1:
			t = ss - fs
			if i == 7 and t > 1 or (i == 9 and t > 0):
				return i
		else:
			t = fs - ss
			if i == 6 and t > 2 or (i == 8 and t > 1):
				return i
	return 10
for _ in range(II()):
	s = input()
	mx = 10
	t = ''
	for i in range(10):
		if s[i] == '?':
			if i & 1 == 1:
				t += '1'
			else:
				t += '0'
		else:
			t += s[i]
	h = how(t)
	if mx > h:
		mx = h
	t = ''
	for i in range(10):
		if s[i] == '?':
			if i & 1 == 0:
				t += '1'
			else:
				t += '0'
		else:
			t += s[i]
	h = how(t)
	if mx > h:
		mx = h
	P(mx)


from collections import deque
import heapq
from math import sqrt
import operator
from operator import itemgetter
import sys
import copy
inf_var = 0
if inf_var == 1:
	inf = open('input.txt', 'r')
else:
	inf = sys.stdin
input = inf.readline

def read_one_int():
	return int(input().rstrip('\n'))

def read_one_float():
	return float(input().rstrip('\n'))

def read_list_of_ints():
	res = [int(val) for val in input().rstrip('\n').split(' ')]
	return res

def read_str():
	return input().rstrip()

def to_left_diag(i, j):
	return i + j

def to_right_diag(i, j):
	return i - j

class Vertex:

	def __init__(self):
		self.next = {}
		self.terminal = False
		self.cnt = 1

def add_str(trie, cur_str):
	vertices_cnt = 0
	cur_node = trie
	for ch in cur_str:
		if ch in cur_node.next:
			cur_node = cur_node.next[ch]
			cur_node.cnt += 1
		else:
			cur_node.next[ch] = Vertex()
			vertices_cnt += 1
			cur_node = cur_node.next[ch]
	cur_node.terminal = True
	return vertices_cnt

def when_stops(answer):
	first = 0
	second = 0
	first_at = 5
	second_at = 5
	for i in range(len(answer)):
		if i % 2:
			second += answer[i]
			second_at -= 1
		else:
			first += answer[i]
			first_at -= 1
		if first > second + second_at:
			return i + 1
		if second > first + first_at:
			return i + 1
	return 10

def rec_bf(cur_str, pos, answer, res):
	if pos == len(cur_str):
		cur_res = when_stops(answer)
		res[0] = min(res[0], cur_res)
		return
	if cur_str[pos] != '?':
		answer[pos] = int(cur_str[pos])
		rec_bf(cur_str, pos + 1, answer, res)
		return
	for i in range(2):
		answer[pos] = i
		rec_bf(cur_str, pos + 1, answer, res)

def main():
	tests = read_one_int()
	for _ in range(tests):
		cur_str = read_str()
		answer = [-1] * len(cur_str)
		res = [10]
		rec_bf(cur_str, 0, answer, res)
		print(res[0])
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict
from math import ceil, floor, sqrt, log2, gcd, pi
from heapq import heappush, heappop
from fractions import Fraction
from bisect import bisect_left, bisect
import sys
abc = 'abcdefghijklmnopqrstuvwxyz'
ABC = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for _ in range(int(input())):
	a = input()
	(l, r) = (0, 0)
	reml = 5
	remr = 5
	dl = 0
	dr = 0
	flag = 0
	for i in range(10):
		if i % 2 == 0:
			reml -= 1
			if a[i] == '1':
				l += 1
			elif a[i] == '?':
				dl += 1
		else:
			remr -= 1
			if a[i] == '1':
				r += 1
			elif a[i] == '?':
				dr += 1
		if l + dl > r + remr or r + dr > l + reml:
			print(i + 1)
			flag = 1
			break
	if flag == 0:
		print(10)


from collections import Counter, defaultdict, OrderedDict, deque
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from typing import List
import itertools
import math
import heapq
import string
import random
(MIN, MAX, MOD) = (-1061109567, 1061109567, 1000000007)
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())
for _ in range(N()):
	s = input()
	t1 = t2 = s1 = 0
	for (i, si) in enumerate(s):
		si = si if si != '?' else '0' if i % 2 else '1'
		t1 += si == ('0' if i % 2 else '1')
		t2 += si == ('1' if i % 2 else '0')
		s1 += 1
		if 10 - (t1 + t2) < abs(t1 - t2):
			break
	t1 = t2 = s2 = 0
	for (i, si) in enumerate(s):
		si = si if si != '?' else '1' if i % 2 else '0'
		t1 += si == ('0' if i % 2 else '1')
		t2 += si == ('1' if i % 2 else '0')
		s2 += 1
		if 10 - (t1 + t2) < abs(t1 - t2):
			break
	print(min(s1, s2))


import time

def main():
	t = i_input()
	for tt in range(t):
		p = input()
		out = 10
		(s1, s2) = (0, 0)
		for (m, r) in enumerate(p, 1):
			if m % 2:
				r = int(r) if r != '?' else 1
				s1 += r
				if s1 > s2 + (10 - m + 1) // 2:
					out = min(out, m)
					break
			else:
				r = int(r) if r != '?' else 0
				s2 += r
				if s1 > s2 + (10 - m) // 2:
					out = min(out, m)
					break
		(s1, s2) = (0, 0)
		for (m, r) in enumerate(p, 1):
			if m % 2:
				r = int(r) if r != '?' else 0
				s1 += r
				if s1 + (10 - m) // 2 < s2:
					out = min(out, m)
					break
			else:
				r = int(r) if r != '?' else 1
				s2 += r
				if s1 + (10 - m) // 2 < s2:
					out = min(out, m)
					break
		print(out)

def i_input():
	return int(input())

def l_input():
	return input().split()

def li_input():
	return list(map(int, l_input()))

def il_input():
	return list(map(int, l_input()))
TT = time.time()
main()


def solve():
	ss = input()
	mxa = 0
	mna = 0
	mxb = 0
	mnb = 0
	for (i, s) in enumerate(ss):
		if i % 2 == 0:
			if s == '1':
				mna += 1
			if s != '0':
				mxa += 1
			if mxa - mnb > (10 - i) // 2 or mxb - mna > (8 - i) // 2:
				print(i + 1)
				return
		else:
			if s == '1':
				mnb += 1
			if s != '0':
				mxb += 1
			if mxb - mna > (9 - i) // 2 or mxa - mnb > (9 - i) // 2:
				print(i + 1)
				return
	print(10)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


from sys import stdin
for _ in range(int(stdin.readline())):
	s = stdin.readline().strip()
	max_arr = [0, 0]
	min_arr = [0, 0]
	res = 10
	remaining = [5, 5]
	for i in range(10):
		if s[i] != '0':
			max_arr[i % 2] += 1
			if s[i] == '1':
				min_arr[i % 2] += 1
		remaining[i % 2] -= 1
		if max_arr[0] - min_arr[1] > remaining[1] or max_arr[1] - min_arr[0] > remaining[0]:
			res = i + 1
			break
	print(res)


for _ in range(int(input())):
	m1 = 10
	m2 = 10
	pen = list(input())
	vin1 = []
	vin2 = []
	for i in range(10):
		if pen[i] == '?':
			vin1.append((i + 1) % 2)
			vin2.append(i % 2)
		else:
			vin1.append(int(pen[i]))
			vin2.append(int(pen[i]))
	goals = [0, 0]
	for i in range(10):
		goals[i % 2] += vin1[i]
		if goals[0] > (10 - i) // 2 + goals[1]:
			m1 = i + 1
			break
	goals = [0, 0]
	for i in range(10):
		goals[i % 2] += vin2[i]
		if goals[1] > (9 - i) // 2 + goals[0]:
			m2 = i + 1
			break
	print(min(m1, m2))


def check(res):
	team1 = 0
	team2 = 0
	for i in range(10):
		if i % 2 == 0:
			team1 += int(res[i])
			if team2 - team1 > (9 - i) // 2:
				return i + 1
			if team1 - team2 - 1 > (9 - i) // 2:
				return i + 1
		else:
			team2 += int(res[i])
			if team1 - team2 > (9 - i) // 2:
				return i + 1
			if team2 - team1 > (9 - i) // 2:
				return i + 1
	return 10
q = int(input())
s = []
for i in range(q):
	s.append(input())
for i in s:
	besta = ''
	worsta = ''
	for j in range(len(i)):
		if i[j] == '?':
			if j % 2 == 0:
				besta = besta + '0'
				worsta = worsta + '1'
			else:
				besta = besta + '1'
				worsta = worsta + '0'
		else:
			besta = besta + i[j]
			worsta = worsta + i[j]
	print(min(check(besta), check(worsta)))


import sys
read = sys.stdin.readline
t = int(read())

def check(s):
	(first, second) = (0, 0)
	for i in range(10):
		if i % 2 == 0 and s[i] == '1':
			first += 1
		if i % 2 == 1 and s[i] == '1':
			second += 1
		(rem_first, rem_second) = (0, 0)
		for j in range(i + 1, 10):
			if j % 2 == 0:
				rem_first += 1
			else:
				rem_second += 1
		if first + rem_first < second or second + rem_second < first:
			return i + 1
	return 10
for cs in range(t):
	s = list(read().strip())
	s1 = s[:]
	s2 = s[:]
	for i in range(10):
		if s[i] == '?':
			if i % 2 == 0:
				s1[i] = '1'
				s2[i] = '0'
			else:
				s1[i] = '0'
				s2[i] = '1'
	print(min(check(s1), check(s2)))


import sys
sys.setrecursionlimit(10000)
t = int(input())
for _ in range(t):
	s = input()
	g1 = 0
	g2 = 0
	r1 = 5
	r2 = 5
	e1 = 0
	e2 = 0
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '?':
				e1 += 1
			else:
				g1 += int(s[i])
			r1 -= 1
		else:
			if s[i] == '?':
				e2 += 1
			else:
				g2 += int(s[i])
			r2 -= 1
		if g1 + e1 > g2 + r2 or g2 + e2 > g1 + r1:
			break
	print(i + 1)


import sys
import os.path
from collections import *
import math
import bisect
import heapq as hq
from fractions import Fraction
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
t = int(input())
while t:
	t -= 1
	s = input()
	dp = [0 for i in range(len(s))]
	score1 = 0
	score2 = 0
	res = 10
	res1 = 10
	for i in range(len(s)):
		if s[i] == '1':
			if i % 2 == 0:
				score1 += 1
			else:
				score2 += 1
		elif s[i] == '?':
			if i % 2 == 0:
				score1 += 1
		if i % 2 == 0:
			if score1 > score2 + (10 - i) // 2:
				res = i + 1
				break
		if i % 2:
			if score1 > score2 + (10 - i - 1) // 2:
				res = i + 1
				break
	score1 = 0
	score2 = 0
	for i in range(len(s)):
		if s[i] == '1':
			if i % 2 == 0:
				score1 += 1
			else:
				score2 += 1
		elif s[i] == '?':
			if i % 2:
				score2 += 1
		if i % 2:
			if score2 > score1 + (10 - i - 1) // 2:
				res1 = i + 1
				break
		if i % 2 == 0:
			if score2 > score1 + (10 - i) // 2 - 1:
				res1 = i + 1
				break
	print(min(res, res1))


for _ in range(int(input())):
	st = input()
	ans = 9
	(cnt0, cnt1) = (0, 0)
	for i in range(10):
		if i % 2 == 0:
			cnt0 += st[i] != '0'
		else:
			cnt1 += st[i] == '1'
		if cnt0 > cnt1 + (10 - i) // 2:
			ans = min(ans, i)
		if cnt1 > cnt0 + (9 - i) // 2:
			ans = min(ans, i)
	(cnt0, cnt1) = (0, 0)
	for i in range(10):
		if i % 2 == 0:
			cnt0 += st[i] == '1'
		else:
			cnt1 += st[i] != '0'
		if cnt0 > cnt1 + (10 - i) // 2:
			ans = min(ans, i)
		if cnt1 > cnt0 + (9 - i) // 2:
			ans = min(ans, i)
	print(ans + 1)


import sys
import math
mod = 10 ** 9 + 7
LI = lambda : [int(k) for k in input().split()]
input = lambda : sys.stdin.readline().rstrip()
IN = lambda : int(input())
S = lambda : input()
r = range
for t in r(IN()):
	s = S()
	t1 = 0
	t2 = 0
	t1n = 0
	t1x = 0
	t2n = 0
	t2x = 0
	for i in range(1, 11):
		t1l = 5 - (i + 1) // 2
		t2l = 5 - i // 2
		if i % 2:
			if s[i - 1] == '1':
				t1n += 1
				t1x += 1
			elif s[i - 1] == '?':
				t1x += 1
		elif s[i - 1] == '1':
			t2n += 1
			t2x += 1
		elif s[i - 1] == '?':
			t2x += 1
		if t2x > t1n + t1l:
			print(i)
			break
		elif t1x > t2n + t2l:
			print(i)
			break
	else:
		print(10)


def min_penalty_balls(pred_res):
	team_a_certain = 0
	team_a_uncertain = 0
	team_b_certain = 0
	team_b_uncertain = 0
	for (i, r) in enumerate(pred_res):
		if i % 2 == 0:
			if r == '1':
				team_a_certain += 1
			elif r == '?':
				team_a_uncertain += 1
		elif r == '1':
			team_b_certain += 1
		elif r == '?':
			team_b_uncertain += 1
		max_a = team_a_certain + team_a_uncertain
		min_b = (10 - i) / 2 + team_b_certain
		if max_a > min_b:
			print(i + 1)
			break
		max_b = team_b_certain + team_b_uncertain
		min_a = (9 - i) / 2 + team_a_certain
		if max_b > min_a:
			print(i + 1)
			break
		if i == 9:
			print(10)
t = int(input())
for _ in range(t):
	min_penalty_balls(input())


from math import floor
for i in range(int(input())):
	my_str = str(input())
	team0_sum = 0
	team1_sum = 0
	team0_mb = 0
	team1_mb = 0
	ans = 10
	for ind in range(0, 10):
		if ind % 2 == 0:
			if my_str[ind] != '?':
				team0_sum += int(my_str[ind])
			else:
				team0_mb += 1
		elif my_str[ind] != '?':
			team1_sum += int(my_str[ind])
		else:
			team1_mb += 1
		if team0_mb + team0_sum > team1_sum + (10 - ind) // 2 or team1_mb + team1_sum > team0_sum + floor((10 - ind - 1) / 2):
			ans = ind + 1
			break
	print(ans)


def decide(p1, p2, q1, q2, k1, k2):
	return p1 + q1 > k2 + p2 or p2 + q2 > k1 + p1

def process(s):
	p1 = 0
	p2 = 0
	q1 = 0
	q2 = 0
	k1 = 2
	k2 = 2
	for i in range(6):
		if i % 2 == 0:
			if s[i] == '1':
				p1 += 1
			elif s[i] == '?':
				q1 += 1
		elif s[i] == '1':
			p2 += 1
		elif s[i] == '?':
			q2 += 1
	if decide(p1, p2, q1, q2, k1, k2):
		return 6
	for i in range(6, 10):
		if i % 2 == 0:
			k1 -= 1
			if s[i] == '1':
				p1 += 1
			elif s[i] == '?':
				q1 += 1
		else:
			k2 -= 1
			if s[i] == '1':
				p2 += 1
			elif s[i] == '?':
				q2 += 1
		if decide(p1, p2, q1, q2, k1, k2):
			return i + 1
	return 10
t = int(input())
for i in range(t):
	s = input()
	print(process(s))


for _ in range(int(input())):
	s = input()
	t1 = s[::2]
	t2 = s[1::2]
	c1 = 0
	c2 = 0
	r1 = 5
	r2 = 5
	a1 = -1
	for i in range(5):
		if t1[i] in '1?':
			c1 += 1
		r1 -= 1
		if c1 > c2 + r2:
			a1 = i * 2 + 1
			break
		if t2[i] == '1':
			c2 += 1
		r2 -= 1
		if c1 > c2 + r2:
			a1 = i * 2 + 2
			break
		if i == 4:
			a1 = 10
	c1 = 0
	c2 = 0
	r1 = 5
	r2 = 5
	a2 = -1
	for i in range(5):
		if t1[i] in '1':
			c1 += 1
		r1 -= 1
		if c2 > c1 + r1:
			a2 = i * 2 + 1
			break
		if t2[i] in '1?':
			c2 += 1
		r2 -= 1
		if c2 > c1 + r1:
			a2 = i * 2 + 2
			break
		if i == 4:
			a2 = 10
	print(min(a1, a2))


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections, string, bisect, re, random, queue, itertools, statistics, math
from collections import *
from bisect import *
from string import *
from itertools import *
from statistics import *
from math import *
from re import *
from queue import *

class Stack:

	def __init__(self):
		self.items = []

	def push(self, item):
		self.items.append(item)

	def pop(self):
		return self.items.pop()

	def empty(self):
		return self.items == []

	def size(self):
		return len(self.items)

	def at(self, idx):
		try:
			return self.items[idx]
		except:
			return -1

class priority_queue(object):

	def __init__(self):
		self.queue = []

	def __str__(self):
		return ' '.join([str(i) for i in self.queue])

	def empty(self):
		return len(self.queue) == 0

	def push(self, data):
		self.queue.append(data)

	def pop(self):
		try:
			max = 0
			for i in range(len(self.queue)):
				if self.queue[i] > self.queue[max]:
					max = i
			item = self.queue[max]
			del self.queue[max]
			return item
		except IndexError:
			print()
			exit()
mod = int(1000000000.0 + 7)
imax = float('inf')
imin = float('-inf')
true = True
false = False
N = int(100000.0)
none = None
inp = lambda : input()
I = lambda : int(inp())
M = lambda : map(int, inp().split())
MS = lambda : map(str, inp().split())
S = lambda : list(MS())
L = lambda : list(M())

def IO():
	try:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('uttar.txt', 'w')
	except:
		pass
IO()

def kabraji_ka_totka():
	s = inp()
	team1 = 0
	team2 = 0
	res = 9
	res = 10
	maxa = 0
	maxb = 0
	mina = 0
	minb = 0
	for i in range(10):
		if i & 1:
			if s[i] != '0':
				maxb += 1
			if s[i] == '1':
				minb += 1
		else:
			if s[i] != '0':
				maxa += 1
			if s[i] == '1':
				mina += 1
		if maxa - minb > (10 - i) // 2:
			res = i + 1
			break
		if maxb - mina > (9 - i) // 2:
			res = i + 1
			break
	print(res)
for i in range(I()):
	kabraji_ka_totka()


import sys
from collections import deque
t = int(sys.stdin.readline())
for _ in range(t):
	data = sys.stdin.readline().rstrip()
	temp = []
	cnt = 0
	ans = 10
	for item in data:
		if item == '?':
			cnt += 1
		temp.append(item)
	for i in range(2 ** cnt):
		team = [0, 0]
		q = bin(i)[2:]
		question_idx = 0
		pre = ''
		for j in range(len(q), cnt):
			pre += '0'
		q = pre + q
		for idx in range(len(data)):
			if data[idx] == '?':
				temp[idx] = q[question_idx]
				question_idx += 1
			team[idx % 2] += int(temp[idx])
			if team[0] > team[1] + (len(data) - idx) // 2:
				ans = min(ans, idx + 1)
			if team[0] + (len(data) - 1 - idx) // 2 < team[1]:
				ans = min(ans, idx + 1)
	print(ans)


from sys import stdin
input = stdin.readline

def f(s):
	t1 = 0
	t2 = 0
	ans = float('inf')
	for i in range(len(s)):
		if i % 2 == 0:
			if s[i] == '1':
				t1 += 1
			if s[i] == '?':
				t1 += 1
		elif s[i] == '1':
			t2 += 1
		if i % 2 == 0:
			odcnt = (9 - i) // 2 + 1
			evcnt = (9 - i) // 2
			if t2 + odcnt < t1:
				ans = i + 1
				break
			if t2 > t1 + evcnt:
				ans = i + 1
				break
		if i % 2 != 0:
			odcnt = (9 - i) // 2
			evcnt = (9 - i) // 2
			if t1 + evcnt < t2:
				ans = i + 1
				break
			if t1 > t2 + odcnt:
				ans = i + 1
				break
	ans2 = float('inf')
	t2 = 0
	t1 = 0
	for i in range(len(s)):
		if i % 2 == 0:
			if s[i] == '1':
				t1 += 1
		else:
			if s[i] == '1':
				t2 += 1
			if s[i] == '?':
				t2 += 1
		if i % 2 == 0:
			odcnt = (9 - i) // 2 + 1
			evcnt = (9 - i) // 2
			if t2 + odcnt < t1:
				ans2 = i + 1
				break
			if t2 > t1 + evcnt:
				ans2 = i + 1
				break
		if i % 2 != 0:
			odcnt = (9 - i) // 2
			evcnt = (9 - i) // 2
			if t1 + evcnt < t2:
				ans2 = i + 1
				break
			if t1 > t2 + odcnt:
				ans2 = i + 1
				break
	return min(10, ans2, ans)
for i in range(int(input())):
	s = input().strip()
	print(f(s))


for i in range(int(input())):
	s = input()
	a = b = c1 = c2 = 0
	for i in range(10):
		if s[i] == '1':
			if i % 2:
				b += 1
			else:
				a += 1
		elif s[i] == '?':
			if i % 2:
				c2 += 1
			else:
				c1 += 1
		if b + (9 - i) - (9 - i) // 2 < a + c1 or a + (9 - i) // 2 < b + c2:
			print(i + 1)
			break
	else:
		print(10)


def penalty(pen: str):
	len_pen = len(pen)
	(sum_first, q_first) = (0, 0)
	(sum_second, q_second) = (0, 0)
	for i in range(len_pen):
		if i % 2 == 0:
			if pen[i] != '?':
				sum_first += int(pen[i])
			else:
				q_first += 1
		elif pen[i] != '?':
			sum_second += int(pen[i])
		else:
			q_second += 1
		if sum_first + q_first > len_pen // 2 - (1 + i) // 2 + sum_second or sum_second + q_second > (len_pen - 1 - i) // 2 + sum_first:
			return i + 1
	return len_pen
n = int(input())
for i in range(n):
	print(penalty(input()))


t = int(input())
for _ in range(t):
	s = input()
	team1 = 0
	team2 = 0
	kl2 = 5
	flag = 0
	min_needed = []
	for i in range(10):
		if team1 > team2 + kl2:
			flag = 1
			break
		elif not i % 2:
			if s[i] == '1' or s[i] == '?':
				team1 += 1
		else:
			if s[i] == '1':
				team2 += 1
			kl2 -= 1
	if flag:
		min_needed.append(i)
	else:
		min_needed.append(i + 1)
	team1 = 0
	team2 = 0
	kl1 = 5
	flag = 0
	for i in range(10):
		if team2 > team1 + kl1:
			flag = 1
			break
		elif i % 2:
			if s[i] == '1' or s[i] == '?':
				team2 += 1
		else:
			if s[i] == '1':
				team1 += 1
			kl1 -= 1
	if flag:
		min_needed.append(i)
	else:
		min_needed.append(i + 1)
	print(min(min_needed))


def solve():
	s = input()
	odd = 0
	cnt = 0
	even = 0
	cnt1 = 0
	ok = 0
	i = 0
	for i in range(len(s)):
		if i % 2 == 0:
			if s[i] == '1':
				even += 1
			elif s[i] == '?':
				cnt += 1
		elif s[i] == '1':
			odd += 1
		elif s[i] == '?':
			cnt1 += 1
		if odd + cnt1 > even + (9 - i) / 2:
			return i + 1
			ok = 1
		if even + cnt > odd + (10 - i) / 2:
			return i + 1
			ok = 1
	if not ok:
		return i + 1
for i in range(int(input())):
	print(solve())


import sys
input = sys.stdin.readline

def main():
	S = input().strip()
	tot = 0
	fi = 5
	se = 5
	for (i, s) in enumerate(S, 1):
		if i % 2 == 1:
			fi -= 1
			if s != '0':
				tot += 1
		else:
			se -= 1
			if s == '1':
				tot -= 1
		if tot > se:
			break
	ans1 = i
	tot = 0
	fi = 5
	se = 5
	for (i, s) in enumerate(S, 1):
		if i % 2 == 1:
			fi -= 1
			if s == '1':
				tot -= 1
		else:
			se -= 1
			if s != '0':
				tot += 1
		if tot > fi:
			break
	print(min(ans1, i))
for _ in range(int(input())):
	main()


for u in range(int(input())):
	s = input()
	a = 0
	b = 0
	ans = 10
	for i in range(len(s)):
		if i % 2:
			if s[i] != '0':
				a += 1
		elif s[i] == '1':
			b += 1
		res = 9 - i
		if a - res // 2 > b:
			ans = min(ans, i + 1)
			break
	a = 0
	b = 0
	for i in range(len(s)):
		if i % 2 == 0:
			if s[i] != '0':
				b += 1
		elif s[i] == '1':
			a += 1
		res = 9 - i
		if b - (res + 1) // 2 > a:
			ans = min(ans, i + 1)
			break
	print(ans)


import sys
import math
from collections import deque, Counter
int1 = lambda x: int(x) - 1
inp = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
mi1 = lambda : map(int1, input().split())
li1 = lambda : list(mi1())
mis = lambda : map(str, input().split())
lis = lambda : list(mis())
pr = print
from collections import defaultdict
mod = 10 ** 9 + 7
Mod = 998244353
INF = 10 ** 18
ans = 0
q = inp()
x = [6, 5, 5, 4, 4, 3, 3, 2, 2, 0]
y = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1]
for _ in range(q):
	a = input()
	ans = 10
	c = 0
	d = 0
	for i in range(10):
		if a[i] == '1':
			if i % 2 == 0:
				c += 1
				d += 1
			else:
				c -= 1
				d -= 1
		if a[i] == '?':
			if i % 2 == 0:
				c += 1
			else:
				d -= 1
		if c >= x[i] or d <= -y[i]:
			ans = min(ans, i + 1)
	print(ans)


def getlist():
	return list(map(int, input().split()))

def main():
	t = int(input())
	for num in range(t):
		arr = input()
		res1 = 10
		res2 = 10
		i = 0
		k = 0
		m = 0
		z = 0
		escore = 0
		oscore = 0
		while i < 10:
			if i % 2 == 0:
				if arr[i] == '1':
					escore += 1
				elif arr[i] == '?':
					escore += 1
			else:
				if arr[i] == '1':
					oscore += 1
				m += 1
			rem = 5 - m
			if rem + oscore < escore:
				res1 = i
				break
			k = 1
			z = 0
			i += 1
		i = 0
		k = 1
		m = 0
		z = 0
		escore = 0
		oscore = 0
		while i < 10:
			if i % 2 != 0:
				if arr[i] == '1':
					oscore += 1
				elif arr[i] == '?':
					oscore += 1
			else:
				if arr[i] == '1':
					escore += 1
				k += 2
				m += 1
			rem = 5 - m
			if rem + escore < oscore:
				res2 = i
				break
			k = 0
			z = 0
			i += 1
		res = min(res1, res2)
		if res == 10:
			print(res)
		else:
			print(res + 1)
main()


def check(P):
	k = [5, 5]
	s = [0, 0]
	for i in range(10):
		k[i % 2] -= 1
		s[i % 2] += int(P[i])
		if s[i % 2] - s[(i + 1) % 2] > k[(i + 1) % 2] or s[(i + 1) % 2] - s[i % 2] > k[i % 2]:
			return i + 1
	return i + 1

def solve(P):
	if '?' in P:
		j = P.index('?')
		P[j] = '0'
		p0 = solve(P)
		P[j] = '1'
		p1 = solve(P)
		P[j] = '?'
		if p0 < p1:
			return p0
		else:
			return p1
	p = check(P)
	return p
t = int(input())
while t > 0:
	t -= 1
	S = list(input())
	p = solve(S)
	print(p)


for _ in range(int(input())):
	a = list(input())
	b = a[:]
	for i in range(10):
		if a[i] == '?':
			if i % 2 == 0:
				a[i] = '1'
			else:
				a[i] = '0'
	al = bl = 5
	acnt = bcnt = 0
	m = 353434
	for i in range(10):
		if i % 2 == 0:
			acnt += int(a[i])
			al -= 1
			if bcnt + bl < acnt or acnt + al < bcnt:
				m = i + 1
				break
		else:
			bcnt += int(a[i])
			bl -= 1
			if bcnt + bl < acnt or acnt + al < bcnt:
				m = i + 1
				break
	else:
		m = 10
	for i in range(10):
		if b[i] == '?':
			if i % 2 == 0:
				b[i] = '0'
			else:
				b[i] = '1'
	al = bl = 5
	acnt = bcnt = 0
	for i in range(10):
		if i % 2 == 0:
			acnt += int(b[i])
			al -= 1
			if bcnt + bl < acnt or acnt + al < bcnt:
				m = min(i + 1, m)
				break
		else:
			bcnt += int(b[i])
			bl -= 1
			if bcnt + bl < acnt or acnt + al < bcnt:
				m = min(i + 1, m)
				break
	else:
		m = min(m, 10)
	print(m)


t = int(input())

def retu(m, n, strr):
	Ga = 0
	Gb = 0
	A = 5
	B = 5
	strr = strr.copy()
	for i in range(10):
		if i % 2 == 0 and strr[i] == '?':
			strr[i] = m
		if i % 2 == 1 and strr[i] == '?':
			strr[i] = n
		if i % 2 == 0:
			Ga += int(strr[i])
			A -= 1
		if i % 2 == 1:
			Gb += int(strr[i])
			B -= 1
		if (Ga > Gb + B or Gb > Ga + A) and (Ga >= 1 or Gb >= 1):
			return i + 1
		if i == 9:
			return 10
for x in range(t):
	strr = list(input())
	a = retu(1, 0, strr)
	b = retu(0, 1, strr)
	print(min(a, b))


def pen(s):
	n = len(s)
	p1 = list(s[::2])
	p2 = list(s[1::2])
	m = len(p1)
	ans = 6
	g3 = ['1' if s[i] == '?' and i % 2 == 0 else s[i] for i in range(n)]
	g4 = ['1' if s[i] == '?' and i % 2 == 1 else s[i] for i in range(n)]
	return min(check(g3), check(g4))

def check(game):
	(score1, score2) = (0, 0)
	for i in range(len(game)):
		if i % 2 == 0 and game[i] == '1':
			score1 += 1
		elif i % 2 == 1 and game[i] == '1':
			score2 += 1
		if score1 > score2 + (len(game) - i) // 2 or score2 > score1 + (len(game) - i - 1) // 2:
			return i + 1
	return 10
cases = int(input())
res = []
for i in range(cases):
	s = input()
	res.append(pen(s))
for i in res:
	print(i)


for _ in range(int(input())):
	a = list(input())
	p = [a[0], a[2], a[4], a[6], a[8]]
	q = [a[1], a[3], a[5], a[7], a[9]]
	ct1 = 0
	ct2 = 0
	flag = 1
	for x in range(5):
		if p[x] == '?':
			p[x] = '1'
		if q[x] == '?':
			q[x] == '0'
	ind = 0
	sc1 = 0
	sc2 = 0
	rm1 = 5
	rm2 = 5
	for x in range(10):
		ct1 += 1
		if flag:
			if p[ind] == '1':
				sc1 += 1
			rm1 -= 1
			flag = 0
		else:
			if q[ind] == '1':
				sc2 += 1
			rm2 -= 1
			flag = 1
			ind += 1
		if sc1 > sc2 + rm2 or sc2 > sc1 + rm1:
			break
	p = [a[0], a[2], a[4], a[6], a[8]]
	q = [a[1], a[3], a[5], a[7], a[9]]
	flag = 1
	for x in range(5):
		if p[x] == '?':
			p[x] = '0'
		if q[x] == '?':
			q[x] = '1'
	ind = 0
	sc1 = 0
	sc2 = 0
	rm1 = 5
	rm2 = 5
	for x in range(10):
		ct2 += 1
		if flag:
			if p[ind] == '1':
				sc1 += 1
			rm1 -= 1
			flag = 0
		else:
			if q[ind] == '1':
				sc2 += 1
			rm2 -= 1
			flag = 1
			ind += 1
		if sc1 > sc2 + rm2 or sc2 > sc1 + rm1:
			break
	print(min(ct1, ct2))


def func(str, x, y):
	(a, b) = (0, 0)
	for i in range(1, 11):
		if i % 2 != 0:
			if str[i - 1] == '1':
				a += 1
			elif str[i - 1] == '?':
				a += x
			else:
				a += 0
		elif str[i - 1] == '1':
			b += 1
		elif str[i - 1] == '?':
			b += y
		else:
			b += 0
		if i >= 6 and i % 2 == 0:
			if abs(a - b) > 2 and i == 6:
				return i
			elif abs(b - a) > 1 and i == 8:
				return i
		elif i >= 6 and i % 2 != 0:
			if a - b > 2 and i == 7:
				return i
			elif b - a >= 2 and i == 7:
				return i
			elif a - b > 1 and i == 9:
				return i
			elif b - a >= 1 and i == 9:
				return i
	return 10
t = int(input())
for _ in range(t):
	s = input()
	c = func(s, 0, 1)
	d = func(s, 1, 0)
	print(min(c, d))


import sys
import math
from bisect import bisect_left
import heapq
from collections import deque

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()

def C(n, k, mod):
	return FACT(n, mod) * pow(FACT(k, mod) * FACT(n - k, mod) % mod, mod - 2, mod) % mod

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)
mod = 10 ** 9 + 7
for _ in range(II()):
	s = list(SI())
	pre = []
	suf = []
	(x, y, x1, y1) = (0, 0, 0, 0)
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '1':
				x += 1
			elif s[i] == '?':
				y += 1
			pre.append((x, y))
		else:
			if s[i] == '1':
				x1 += 1
			elif s[i] == '?':
				y1 += 1
			pre.append((x1, y1))
	boo = False
	for i in range(1, 10):
		(x, y) = pre[i]
		(x1, y1) = pre[i - 1]
		mi = (10 - i) // 2
		if x + y > x1 + mi or x1 + y1 > x + mi - (1 if i % 2 == 0 else 0):
			boo = True
			print(i + 1)
			break
	if not boo:
		print(10)


import math
mod = 1000000007
from sys import stdin, stdout
for abcd in range(int(input())):
	s = stdin.readline().strip('\n')
	x = y = a = b = 0
	li = []
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '1':
				x += 1
			elif s[i] == '?':
				a += 1
		elif s[i] == '1':
			y += 1
		elif s[i] == '?':
			b += 1
		p = [x, y, a, b]
		li.append(p)
	y = 0
	for i in range(5, 10):
		if i % 2 == 0:
			c = 1
			d = 0
		else:
			c = 0
			d = 1
		if li[i][0] + li[i][2] > li[i][1] + (9 - i + c) // 2:
			y = 1
			break
		if li[i][1] + li[i][-1] > li[i][0] + (9 - i + d) // 2:
			y = 1
			break
	if y == 0:
		print(10)
		continue
	print(i + 1)


t = int(input())
for _ in range(t):
	x = input().strip()
	s = 0
	ans = 10
	for i in range(5):
		if x[2 * i] == '1' or x[2 * i] == '?':
			if s + 1 > 5 - i:
				ans = 2 * i + 1
				break
		if x[2 * i] == '?' or x[2 * i] == '1':
			s += 1
		if x[2 * i + 1] == '1':
			s -= 1
		if s > 4 - i:
			ans = min(2 * i + 2, ans)
			break
	s = 0
	for i in range(5):
		if x[2 * i] == '0' or x[2 * i] == '?':
			if s < i - 4:
				ans = min(ans, 2 * i + 1)
				break
		if x[2 * i + 1] == '?' or x[2 * i + 1] == '1':
			s -= 1
		if x[2 * i] == '1':
			s += 1
		if s < i - 4:
			ans = min(2 * i + 2, ans)
			break
	print(ans)


from itertools import combinations_with_replacement
import sys
from sys import stdin
import math
import bisect

def BinarySearch(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def iinput():
	return int(input())

def minput():
	return map(int, input().split())

def linput():
	return list(map(int, input().split()))

def fiinput():
	return int(stdin.readline())

def fminput():
	return map(int, stdin.readline().strip().split())

def flinput():
	return list(map(int, stdin.readline().strip().split()))
for _ in range(iinput()):
	list1 = list(input())
	list2 = list1.copy()
	for i in range(10):
		if i % 2 == 0 and list1[i] == '?':
			list1[i] = '1'
		if i % 2 != 0 and list1[i] == '?':
			list1[i] = '0'
	for i in range(10):
		if i % 2 != 0 and list2[i] == '?':
			list2[i] = '1'
		if i % 2 == 0 and list2[i] == '?':
			list2[i] = '0'
	s1 = 0
	s2 = 0
	c1 = 0
	c2 = 0
	f = 0
	ll = []
	for i in range(10):
		if list1[i] == '1' and i % 2 == 0:
			s1 += 1
		if i % 2 == 0:
			c1 += 1
		if i % 2 != 0:
			c2 += 1
		if list1[i] == '1' and i % 2 != 0:
			s2 += 1
		if s1 - s2 > 5 - c2 or s2 - s1 > 5 - c1:
			ll.append(i + 1)
			f = 1
			break
	s1 = 0
	s2 = 0
	c1 = 0
	c2 = 0
	for i in range(10):
		if list2[i] == '1' and i % 2 == 0:
			s1 += 1
		if i % 2 == 0:
			c1 += 1
		if i % 2 != 0:
			c2 += 1
		if list2[i] == '1' and i % 2 != 0:
			s2 += 1
		if s1 - s2 > 5 - c2 or s2 - s1 > 5 - c1:
			ll.append(i + 1)
			f = 1
			break
	if f == 0:
		print(10)
	else:
		print(min(ll))


def goals_1(a):
	team_1 = 0
	team_2 = 0
	b = list(a)
	for i in range(0, 10):
		if b[i] == '?':
			if i % 2 == 0:
				b[i] = '1'
			else:
				b[i] = '0'
	for i in range(0, 10):
		if i % 2 == 0:
			team_1 += int(b[i])
		else:
			team_2 += int(b[i])
		if team_1 > team_2 + (10 - i) / 2:
			return i + 1
		elif team_2 > team_1 + (9 - i) / 2:
			return i + 1
	return 10

def goals_2(a):
	team_1 = 0
	team_2 = 0
	b = list(a)
	for i in range(0, 10):
		if b[i] == '?':
			if i % 2 == 0:
				b[i] = '0'
			else:
				b[i] = '1'
	for i in range(0, 10):
		if i % 2 == 0:
			team_1 += int(b[i])
		else:
			team_2 += int(b[i])
		if team_1 > team_2 + (10 - i) / 2:
			return i + 1
		elif team_2 > team_1 + (9 - i) / 2:
			return i + 1
	return 10

def main():
	n = int(input())
	for i in range(n):
		x = input()
		print(min(goals_1(x), goals_2(x)))
main()


def solve():
	s = list(input())
	first = second = 0
	even_question = 0
	odd_question = 0
	for i in range(len(s)):
		if s[i] == '1':
			if i % 2 == 0:
				first += 1
			else:
				second += 1
		if s[i] == '?':
			if i % 2 == 0:
				even_question += 1
			else:
				odd_question += 1
		opts = [(first + even_question, second), (first, second + odd_question)]
		left_total = len(s) - i - 1
		left_first = left_total // 2 + 0
		left_second = left_total // 2 + left_total % 2
		for (a, b) in opts:
			if a > b + left_second:
				return i + 1
			if b > a + left_first:
				return i + 1
	return 10
n = int(input())
for _ in range(n):
	ans = solve()
	print(ans)


t = int(input())
for i in range(t):
	s = input()
	fst_count = 0
	lst_count = 0
	c = 0
	a_fst = [0]
	b_lst = [0]
	x = 9
	res = 0
	for i in range(10):
		res += 1
		if i % 2 == 0:
			fst_count += 1
			if s[i] == '1':
				for i in range(len(a_fst)):
					a_fst[i] += 1
			elif s[i] == '?':
				p = max(a_fst)
				a_fst.append(p + 1)
		else:
			lst_count += 1
			if s[i] == '1':
				for i in range(len(b_lst)):
					b_lst[i] += 1
			elif s[i] == '?':
				p = max(b_lst)
				b_lst.append(p + 1)
		if min(a_fst) + (5 - fst_count) < max(b_lst):
			c = 1
			x = i
			break
		elif min(b_lst) + (5 - lst_count) < max(a_fst):
			x = i
			c = 1
			break
	print(res)


testn = input()
tests = []
for n in range(0, int(testn)):
	tests += [input()]

def check_done(s1, s2, k1, k2):
	return s1 > s2 + k2 or s2 > s1 + k1

def odd(n):
	return n % 2 != 0

def t1(test):
	s1 = 0
	s2 = 0
	k1 = 5
	k2 = 5
	n = 1
	for x in test:
		if odd(n):
			if x == '1' or x == '?':
				s1 += 1
				k1 += -1
			else:
				k1 += -1
		elif x == '1':
			s2 += 1
			k2 += -1
		else:
			k2 += -1
		if check_done(s1, s2, k1, k2) == True:
			return n
		n += 1
	return 10

def t2(test):
	s1 = 0
	s2 = 0
	k1 = 5
	k2 = 5
	n = 1
	for x in test:
		if odd(n):
			if x == '1':
				s1 += 1
				k1 += -1
			else:
				k1 += -1
		elif x == '1' or x == '?':
			s2 += 1
			k2 += -1
		else:
			k2 += -1
		if check_done(s1, s2, k1, k2) == True:
			return n
		n += 1
	return 10
for test in tests:
	print(min([t1(test), t2(test)]))


t = int(input())
for i in range(t):
	s = input()
	s1 = s
	s = list(s)
	s1 = list(s1)
	ans0 = 10
	ans1 = 10
	for j in range(10):
		if j % 2 == 0 and s[j] == '?':
			s[j] = '1'
		if j % 2 == 1 and s[j] == '?':
			s[j] = '0'
	for j in range(10):
		if j % 2 == 1 and s1[j] == '?':
			s1[j] = '1'
		if j % 2 == 0 and s1[j] == '?':
			s1[j] = '0'
	cnt1 = 0
	cnt2 = 0
	for j in range(10):
		if j % 2 == 0 and s[j] == '1':
			cnt1 += 1
		if j % 2 == 1 and s[j] == '1':
			cnt2 += 1
		if cnt1 > cnt2 + (10 - j) // 2:
			ans0 = j + 1
			break
	cnt1 = 0
	cnt2 = 0
	for j in range(10):
		if j % 2 == 1 and s1[j] == '1':
			cnt1 += 1
		if j % 2 == 0 and s1[j] == '1':
			cnt2 += 1
		if cnt1 > cnt2 + (10 - j - 1) // 2:
			ans1 = j + 1
			break
	ans0 = min(ans0, ans1)
	print(ans0)


def cal(k):
	p = 0
	q = 0
	pl = 0
	ql = 0
	for i in range(10):
		if k[i] == '1':
			if i % 2 == 0:
				p += 1
			else:
				q += 1
		if i % 2 == 0:
			pl += 1
		else:
			ql += 1
		if p > q:
			if 5 - ql < p - q:
				break
		elif 5 - pl < q - p:
			break
	return i + 1
for _ in range(int(input())):
	s = input()
	s1 = list(s)
	m = 0
	n = 0
	for i in range(10):
		if s1[i] == '?':
			if i % 2 == 0:
				s1[i] = '1'
			else:
				s1[i] = '0'
	m = cal(s1)
	s2 = list(s)
	for i in range(10):
		if s2[i] == '?':
			if i % 2 != 0:
				s2[i] = '1'
			else:
				s2[i] = '0'
	n = cal(s2)
	print(min(m, n))


import math, sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
mod1 = 1000000007
mod2 = 998244353
for _ in range(I()):
	s = list(S())
	a = 0
	b = 0
	ra = 5
	rb = 5
	even = 0
	odd = 0
	ans = 10
	flag = 1
	for i in range(10):
		if i % 2 == 0:
			ra -= 1
			if s[i] == '1':
				a += 1
			elif s[i] == '?':
				even += 1
		else:
			rb -= 1
			if s[i] == '1':
				b += 1
			elif s[i] == '?':
				odd += 1
		if a + even - b > rb or b + odd - a > ra:
			print(i + 1)
			flag = 0
			break
	if flag:
		print(ans)


import sys
import math
input = sys.stdin.readline
imp = 'IMPOSSIBLE'
t = int(input())
for test in range(t):
	r = input()
	j = 0
	d = 0
	jm = 0
	dm = 0
	je = 5
	de = 5
	res = 10
	for i in range(10):
		if i % 2 == 0:
			je -= 1
		else:
			de -= 1
		if r[i] == '1':
			if i % 2 == 0:
				j += 1
			else:
				d += 1
		elif r[i] == '?':
			if i % 2 == 0:
				jm += 1
			else:
				dm += 1
		if j + jm > d + de:
			res = i + 1
			break
		if d + dm > j + je:
			res = i + 1
			break
	print(res)


for _ in range(int(input())):
	s = input()
	nta = 5
	ntb = 5
	nga = 0
	ngb = 0
	count1 = 0
	i = 1
	while i < 11:
		if nga - ngb > ntb or ngb - nga > nta:
			break
		if s[i - 1] == '1':
			if i & 1 != 0:
				nga += 1
			else:
				ngb += 1
		elif s[i - 1] == '?':
			if i & 1 != 0:
				nga += 1
		count1 += 1
		if i & 1 == 1:
			nta -= 1
		else:
			ntb -= 1
		i += 1
	nta = 5
	ntb = 5
	nga = 0
	ngb = 0
	count2 = 0
	i = 1
	while i < 11:
		if nga - ngb > ntb or ngb - nga > nta:
			break
		if s[i - 1] == '1':
			if i & 1 != 0:
				nga += 1
			else:
				ngb += 1
		elif s[i - 1] == '?':
			if i & 1 == 0:
				ngb += 1
		count2 += 1
		if i & 1 == 1:
			nta -= 1
		else:
			ntb -= 1
		i += 1
	print(min(count1, count2))


def winner(game_state, winner_team):
	win = 0
	los = 0
	no_of_los = 0
	av_los = 5
	for j_win in range(len(game_state)):
		if j_win % 2 == winner_team - 1:
			if game_state[j_win] == '1' or game_state[j_win] == '?':
				win = win + 1
		else:
			if game_state[j_win] == '1':
				los = los + 1
			elif game_state[j_win] == '0' or game_state[j_win] == '?':
				no_of_los = no_of_los + 1
			av_los = 5 - (los + no_of_los)
		abc = win - los
		if abc > av_los:
			end_point = j_win + 1
			break
	else:
		end_point = j_win + 1
	return end_point

def main():
	n = int(input(''))
	lis = [''] * n
	lis_a = [0] * n
	for i in range(n):
		lis[i] = lis[i] + input('')
	for i in range(len(lis)):
		end_point1 = winner(lis[i], 1)
		end_point2 = winner(lis[i], 2)
		if end_point1 < end_point2:
			print(end_point1)
		else:
			print(end_point2)
main()


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	s = input().strip()
	one = s[::2]
	two = s[1::2]
	an = 10
	a = b = aq = bq = 0
	taq = one.count('?')
	tbq = two.count('?')
	for i in range(5):
		if one[i] == '1':
			a += 1
		elif one[i] == '?':
			aq += 1
		if a + aq > b + 5 - i:
			an = 2 * i + 1
			break
		if b + bq > a + 4 - i:
			an = 2 * i + 1
			break
		if two[i] == '1':
			b += 1
		elif two[i] == '?':
			bq += 1
		if a + aq > b + 4 - i:
			an = 2 * (i + 1)
			break
		if b + bq > a + 4 - i:
			an = 2 * (i + 1)
			break
	print(an)


from sys import *
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)

def solve(st):
	(f, s) = (0, 0)
	(fq, sq) = (0, 0)
	(x, y) = (5, 5)
	c = 0
	for i in range(len(st)):
		if i % 2 == 0:
			if st[i] == '?':
				fq += 1
			if st[i] == '1':
				f += 1
			x -= 1
		else:
			if st[i] == '?':
				sq += 1
			if st[i] == '1':
				s += 1
			y -= 1
		c += 1
		if f + fq > s + y:
			print(c)
			return
		if s + sq > f + x:
			print(c)
			return
	else:
		print(c)
for _ in range(int(input())):
	s = str(input())[:-1]
	solve(s)


for i in range(int(input())):
	s = input()
	n = 10
	a = 0
	b = 0
	p1 = 0
	p2 = 0
	z1 = 0
	z2 = 0
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '?':
				a += 1
			else:
				p1 += int(s[i])
		elif s[i] == '?':
			b += 1
		else:
			p2 += int(s[i])
		if i % 2 == 0:
			z1 = 1
			z2 = 0
		else:
			z1 = 0
			z2 = 1
		if a + p1 > p2 + (n - i - z2) // 2:
			print(i + 1)
			break
		elif b + p2 > p1 + (n - i - z1) // 2:
			print(i + 1)
			break
	else:
		print(10)


def solve(index, f, s, kick1, kick2, s1):
	if index == len(s1):
		return 0
	if f + kick1 < s:
		return 0
	if s + kick2 < f:
		return 0
	if s1[index] == '1':
		if index % 2 == 0:
			return 1 + solve(index + 1, f + 1, s, kick1 - 1, kick2, s1)
		else:
			return 1 + solve(index + 1, f, s + 1, kick1, kick2 - 1, s1)
	if s1[index] == '0':
		if index % 2 == 0:
			return 1 + solve(index + 1, f, s, kick1 - 1, kick2, s1)
		else:
			return 1 + solve(index + 1, f, s, kick1, kick2 - 1, s1)
	elif index % 2 == 0:
		return 1 + min(solve(index + 1, f + 1, s, kick1 - 1, kick2, s1), solve(index + 1, f, s, kick1 - 1, kick2, s1))
	else:
		return 1 + min(solve(index + 1, f, s + 1, kick1, kick2 - 1, s1), solve(index + 1, f, s, kick1, kick2 - 1, s1))
t = int(input())
while t:
	s = input()
	print(solve(0, 0, 0, 5, 5, s))
	t -= 1


t = int(input())
testes = []
for i in range(t):
	l = input()
	testes.append(l)
for i in range(t):
	ok = 0
	gol_team1 = 0
	gol_team2 = 0
	team1_joker = 0
	team2_joker = 0
	for j in range(0, 6, 2):
		if testes[i][j] == '1':
			gol_team1 += 1
		elif testes[i][j] == '?':
			team1_joker += 1
	for j in range(1, 6, 2):
		if testes[i][j] == '1':
			gol_team2 += 1
		elif testes[i][j] == '?':
			team2_joker += 1
	for j in range(6, 10):
		if gol_team2 + team2_joker - gol_team1 > (10 - j) // 2:
			print(j)
			ok = 1
			break
		if gol_team1 + team1_joker - gol_team2 > (11 - j) // 2:
			print(j)
			ok = 1
			break
		if j % 2 == 0:
			if testes[i][j] == '1':
				gol_team1 += 1
			elif testes[i][j] == '?':
				team1_joker += 1
		elif testes[i][j] == '1':
			gol_team2 += 1
		elif testes[i][j] == '?':
			team2_joker += 1
	if ok == 0:
		print(10)


for _ in range(int(input())):
	s = input()
	t1 = tb1 = tb2 = t2 = 0
	flag = 1
	for i in range(len(s)):
		if s[i] != '?':
			if i % 2 == 1:
				t2 += int(s[i])
			else:
				t1 += int(s[i])
		elif i % 2 == 1:
			tb2 += 1
		else:
			tb1 += 1
		kl1 = (9 - i) // 2
		kl2 = (10 - i) // 2
		if t1 + tb1 > t2 + kl2:
			print(i + 1)
			flag = 0
			break
		if t2 + tb2 > t1 + kl1:
			print(i + 1)
			flag = 0
			break
	if flag:
		print(i + 1)


import sys
import math
import random
import heapq
input = sys.stdin.readline

def pow(a, n, m):
	if n == 0:
		return 1
	x = pow(a, n // 2, m)
	if n % 2 == 0:
		return x * x % m
	else:
		return x * x * a % m

def gcd(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a

def bs(arr, le, ri):
	l = 0
	arr.sort()
	r = len(arr) - 1
	ans = 10000000
	while l <= r:
		m = (l + r) // 2
		if arr[m] >= le and arr[m] <= ri:
			ans = arr[m]
			r = m - 1
		elif arr[m] < le:
			l = m + 1
		else:
			r = m - 1
	return ans

def fun(s1, s2, r1, r2, c, s, ans):
	if c >= 10:
		return
	elif s1 > s2:
		if s1 - s2 > r2:
			ans[0] = min(ans[0], c)
			return
	elif s2 > s1:
		if s2 - s1 > r1:
			ans[0] = min(ans[0], c)
			return
	if c % 2 == 0:
		r1 -= 1
		if s[c] == '1':
			s1 += 1
			fun(s1, s2, r1, r2, c + 1, s, ans)
		elif s[c] == '0':
			fun(s1, s2, r1, r2, c + 1, s, ans)
		else:
			fun(s1, s2, r1, r2, c + 1, s, ans)
			s1 += 1
			fun(s1, s2, r1, r2, c + 1, s, ans)
	else:
		r2 -= 1
		if s[c] == '1':
			s2 += 1
			fun(s1, s2, r1, r2, c + 1, s, ans)
		elif s[c] == '0':
			fun(s1, s2, r1, r2, c + 1, s, ans)
		else:
			fun(s1, s2, r1, r2, c + 1, s, ans)
			s2 += 1
			fun(s1, s2, r1, r2, c + 1, s, ans)
t = int(input())
while t > 0:
	s = input().strip()
	ans = [10]
	fun(0, 0, 5, 5, 0, s, ans)
	print(ans[0])
	t -= 1


rint = lambda : int(input())
rli = lambda : list(map(int, input().split()))
rl = lambda : input().split()

def strm(m):
	s = ''
	for i in range(len(m)):
		for j in range(len(m[0])):
			s += str(m[i][j])
		s += '\n'
	return s

def solve():
	s = input()
	(p1, p2) = (0, 0)
	(t1, t2) = (5, 5)
	res = 10
	for (i, c) in enumerate(s):
		if i % 2 == 0:
			t1 -= 1
			if c != '0':
				p1 += 1
		else:
			t2 -= 1
			if c == '1':
				p2 += 1
		if p1 > p2 + t2:
			res = min(res, 10 - t1 - t2)
		if p2 > p1 + t1:
			res = min(res, 10 - t1 - t2)
	(p1, p2) = (0, 0)
	(t1, t2) = (5, 5)
	for (i, c) in enumerate(s):
		if i % 2 == 0:
			t1 -= 1
			if c == '1':
				p1 += 1
		else:
			t2 -= 1
			if c != '0':
				p2 += 1
		if p1 - p2 > t2:
			res = min(res, 10 - t1 - t2)
		if p2 - p1 > t1:
			res = min(res, 10 - t1 - t2)
	return str(res)
res = ''
for test_number in range(1, rint() + 1):
	r = solve()
	print(r)
	res += r + '\n'


z = int(input())
for i in range(z):
	odd = [0, 0, 0]
	even = [0, 0, 0]
	y = input()
	ans = 0
	for ll in range(len(y)):
		ans += 1
		if ll & 1 == 0:
			if y[ll] == '?':
				even[1] += 1
			elif y[ll] == '1':
				even[0] += 1
		elif y[ll] == '?':
			odd[1] += 1
		elif y[ll] == '1':
			odd[0] += 1
		if odd[0] + odd[1] - even[0] >= 3 and ll >= 5:
			break
		elif even[0] + even[1] - odd[0] >= 3 and ll >= 5:
			break
		if odd[0] + odd[1] - even[0] >= 2 and ll >= 6:
			break
		elif even[0] + even[1] - odd[0] >= 2 and ll >= 7:
			break
	if ans == 10:
		if y[-1] == '1':
			odd[0] -= 1
		elif y[-1] == '?':
			odd[1] -= 1
		if odd[0] + odd[1] - even[0] > 0:
			print(9)
		else:
			print(10)
	else:
		print(ans)


t = int(input())
for x in range(t):
	s = input()
	t1 = 0
	t2 = 0
	for a in range(len(s)):
		if s[a] == '1':
			if a % 2 == 0:
				t1 += 1
				t2 -= 1
			else:
				t1 -= 1
				t2 += 1
		elif s[a] == '?':
			if a % 2 == 0:
				t1 += 1
			else:
				t2 += 1
		if int((10 - a) / 2) < t1:
			print(a + 1)
			break
		elif int((10 - a - 1) / 2) < t2:
			print(a + 1)
			break
		elif a == 9:
			print(10)


import sys, os, time, collections
for T in range(int(input())):
	S = sys.stdin.readline().strip()
	N = len(S)
	dp1 = [[0, 0]] * N
	dp2 = [[0, 0]] * N
	p1c = 5
	p2c = 5
	for i in range(N):
		if i > 0:
			dp1[i] = dp1[i - 1]
			dp2[i] = dp2[i - 1]
		if i & 1:
			p2c -= 1
			if S[i] == '1':
				dp2[i][0] += 1
				dp2[i][1] += 1
			elif S[i] == '?':
				dp2[i][1] += 1
		else:
			p1c -= 1
			if S[i] == '1':
				dp1[i][0] += 1
				dp1[i][1] += 1
			elif S[i] == '?':
				dp1[i][1] += 1
		if dp2[i][1] - dp1[i][0] > p1c or dp1[i][1] - dp2[i][0] > p2c:
			ans = i + 1
			break
		if i == N - 1:
			ans = i + 1
			break
	print(ans)


from sys import stdin, stdout
nmbr = lambda : int(input())
lst = lambda : list(map(int, input().split()))

def fn(s):
	s0 = s1 = 0
	for i in range(n):
		if i & 1 == 0:
			s0 += int(s[i] == '1')
		else:
			s1 += int(s[i] == '1')
		if s0 > s1:
			extra = 0
			for j in range(i + 1, n):
				if j & 1:
					extra += 1
			if s0 > s1 + extra:
				return i + 1
		elif s1 > s0:
			extra = 0
			for j in range(i + 1, n):
				if j & 1 == 0:
					extra += 1
			if s1 > s0 + extra:
				return i + 1
	return n
for _ in range(nmbr()):
	s = list(input())
	n = len(s)
	s1 = s.copy()
	ans = n
	for i in range(n):
		if s[i] == '?':
			if i & 1 == 0:
				s1[i] = '1'
			else:
				s1[i] = '0'
	ans = fn(s1)
	s1 = s.copy()
	for i in range(n):
		if s[i] == '?':
			if i & 1:
				s1[i] = '1'
			else:
				s1[i] = '0'
	ans = min(ans, fn(s1))
	print(ans)


for _ in range(int(input())):
	s = input()
	s1 = []
	s2 = []
	n = len(s)
	for i in range(n):
		if i % 2 == 0:
			if s[i] == '?':
				s1.append(1)
				s2.append(0)
			else:
				s1.append(int(s[i]))
				s2.append(int(s[i]))
		elif s[i] == '?':
			s2.append(1)
			s1.append(0)
		else:
			s1.append(int(s[i]))
			s2.append(int(s[i]))
	ans1 = 0
	(t1, t2) = (0, 0)
	(l1, l2) = (5, 5)
	for i in range(n):
		if i % 2 == 0:
			t1 = t1 + s1[i]
			l1 = l1 - 1
		else:
			t2 = t2 + s1[i]
			l2 = l2 - 1
		ans1 = ans1 + 1
		if t1 > t2 + l2:
			break
	ans2 = 0
	(t1, t2) = (0, 0)
	(l1, l2) = (5, 5)
	for i in range(n):
		if i % 2 == 0:
			t1 = t1 + s2[i]
			l1 = l1 - 1
		else:
			t2 = t2 + s2[i]
			l2 = l2 - 1
		ans2 = ans2 + 1
		if t2 > t1 + l1:
			break
	print(min(ans1, ans2))


from sys import stdin as sin

def aint():
	return int(input())

def amap():
	return map(int, sin.readline().split())

def alist():
	return list(map(int, sin.readline().split()))

def astr():
	return input()
for _ in range(aint()):
	s = input()
	n = 10
	x = 0
	y = 0
	q1 = 0
	q2 = 0
	ans = -1
	for i in range(n):
		if s[i] == '1':
			if i % 2 == 0:
				x += 1
			else:
				y += 1
		elif s[i] == '?':
			if i % 2 == 0:
				q1 += 1
			else:
				q2 += 1
		if i % 2 == 0:
			if y + (n - i) // 2 < x + q1 or x + (n - i - 1) // 2 < y + q2:
				ans = i + 1
				break
		elif y + (n - i - 1) // 2 < x + q1 or x + (n - i) // 2 < y + q2:
			ans = i + 1
			break
	if ans == -1:
		ans = 10
	print(ans)


r = int(input().strip())
for _ in range(r):
	var = ([0, 0, 5], [0, 0, 5])
	s = input()
	for (i, c) in enumerate(s):
		if c != '0':
			var[i % 2][0] += 1
		if c == '1':
			var[i % 2][1] += 1
		var[i % 2][2] -= 1
		if var[0][0] - var[1][1] > var[1][2] or var[1][0] - var[0][1] > var[0][2]:
			print(i + 1)
			break
	else:
		print(10)


t = int(input())
for _ in range(t):
	s = input()
	pierwsza = [s[0], s[2], s[4], s[6], s[8]]
	druga = [s[1], s[3], s[5], s[7], s[9]]
	pierwsza2 = []
	druga2 = []
	for x in range(5):
		if pierwsza[x] == '?':
			pierwsza[x] = '1'
			pierwsza2.append('0')
		else:
			pierwsza2.append(pierwsza[x])
		if druga[x] == '?':
			druga[x] = '0'
			druga2.append('1')
		else:
			druga2.append(druga[x])
	wynik = 0
	jeden = 0
	dwa = 0
	for x in range(5):
		if pierwsza[x] == '1':
			jeden += 1
		elif pierwsza[x] == '0' and dwa - jeden > 5 - (x + 1):
			wynik = 2 * x + 1
			break
		if jeden - dwa > 5 - x:
			wynik = 2 * x + 1
			break
		if druga[x] == '1':
			dwa += 1
		elif druga[x] == '0' and jeden - dwa > 5 - (x + 1):
			wynik = 2 * x + 2
			break
		if dwa - jeden > 5 - (x + 1):
			wynik = 2 * x + 2
			break
		if x == 4:
			wynik = 10
	wynik2 = 0
	jeden = 0
	dwa = 0
	for x in range(5):
		if pierwsza2[x] == '1':
			jeden += 1
		elif pierwsza2[x] == '0' and dwa - jeden > 5 - (x + 1):
			wynik2 = 2 * x + 1
			break
		if jeden - dwa > 5 - x:
			wynik2 = 2 * x + 1
			break
		if druga2[x] == '1':
			dwa += 1
		elif druga2[x] == '0' and jeden - dwa > 5 - (x + 1):
			wynik2 = 2 * x + 2
			break
		if dwa - jeden > 5 - (x + 1):
			wynik2 = 2 * x + 2
			break
		if x == 4:
			wynik2 = 10
	print(min(wynik, wynik2))


import sys
import math
import collections
import heapq
import decimal

def cal(s, s1):
	(c1, c2) = (0, 0)
	(c3, c4) = (0, 0)
	k = -1
	le = 0
	l1 = []
	for i in range(10):
		l1.append(s[i])
	for i in range(10):
		if l1[i] == '?':
			l1[i] = s1[le]
			le += 1
	for i in range(10):
		if i % 2 == 0:
			c3 += 1
		else:
			c4 += 1
		if l1[i] == '1':
			if i % 2 == 0:
				c1 += 1
			else:
				c2 += 1
		if 5 - c3 + c1 < c2:
			k = i + 1
			break
		elif 5 - c4 + c2 < c1:
			k = i + 1
			break
	if k == -1:
		return 10
	else:
		return k
t = int(input())
for w in range(t):
	s = list(input())
	n = len(s)
	(c1, c2) = (0, 0)
	(c3, c4) = (0, 0)
	k1 = s.count('?')
	l = []
	p = pow(2, k1)
	for i in range(p + 1):
		s1 = bin(i)[2:]
		if len(s1) < k1:
			s1 = '0' * (k1 - len(s1)) + s1
		l.append(s1)
	if k1 == 0:
		k = -1
		for i in range(n):
			if i % 2 == 0:
				c3 += 1
			else:
				c4 += 1
			if s[i] == '1':
				if i % 2 == 0:
					c1 += 1
				else:
					c2 += 1
			if 5 - c3 + c1 < c2:
				k = i + 1
				break
			elif 5 - c4 + c2 < c1:
				k = i + 1
				break
		if k == -1:
			print(10)
		else:
			print(k)
	else:
		mi = 10
		for i in l:
			mi = min(mi, cal(s, i))
		print(mi)


for _ in range(int(input())):
	a = input()
	l1 = [a[x] for x in range(0, 10, 2)]
	l2 = [a[x] for x in range(1, 10, 2)]
	if l1[0:3].count('1') + l1[0:3].count('?') == 3 and l2[0:3].count('0') + l2[0:3].count('?') == 3 or (l2[0:3].count('1') + l2[0:3].count('?') == 3 and l1[0:3].count('0') + l1[0:3].count('?') == 3):
		print(6)
	elif l1[0:4].count('1') + l1[0:4].count('?') > l2[0:3].count('1') + 2 or l2[0:3].count('1') + l2[0:3].count('?') > l1[0:4].count('1') + 1:
		print(7)
	elif l1[0:4].count('1') + l1[0:4].count('?') > l2[0:4].count('1') + 1 or l2[0:4].count('1') + l2[0:4].count('?') > l1[0:4].count('1') + 1:
		print(8)
	elif l1.count('1') + l1.count('?') > l2[0:4].count('1') + 1 or l2[0:4].count('1') + l2[0:4].count('?') > l1.count('1'):
		print(9)
	else:
		print(10)


for _ in range(int(input())):
	c = list(input())
	t = 1
	a = b = 0
	ac = bc = 5
	ma = mb = 0
	ans = 0
	for x in range(10):
		if c[x] == '1':
			if t == 1:
				a += 1
				ac -= 1
				ma += 1
			if t == 2:
				b += 1
				bc -= 1
				mb += 1
		if c[x] == '0':
			if t == 1:
				ac -= 1
			if t == 2:
				bc -= 1
		if c[x] == '?':
			if t == 1:
				ac -= 1
				ma += 1
			if t == 2:
				bc -= 1
				mb += 1
		if ma == 5 and bc + mb != 5:
			if ans == 0:
				print(x + 1)
				ans = 1
		if mb == 5 and ac + ma != 5:
			if ans == 0:
				print(x + 1)
				ans = 1
		if ma > bc + b:
			if ans == 0:
				print(x + 1)
				ans = 1
		if mb > ac + a:
			if ans == 0:
				print(x + 1)
				ans = 1
		if t == 1:
			t = 2
		elif t == 2:
			t = 1
	if ans == 0:
		print(10)


t = int(input())
for j in range(t):
	ch = input()
	(a, b, ai, bi, ap, bp) = (0, 0, 0, 0, 5, 5)
	for i in range(10):
		w = i
		if i % 2 == 0:
			ap -= 1
		else:
			bp -= 1
		if ch[i] == '1':
			if i % 2 == 0:
				a += 1
			else:
				b += 1
		elif ch[i] == '?':
			if i % 2 == 0:
				ai += 1
			else:
				bi += 1
		if a + ai - b > bp:
			break
		if b + bi - a > ap:
			break
	print(w + 1)


def main():
	for _ in range(int(input())):
		s = input()
		(a, b) = (''.join([s[i] for i in range(0, 10, 2)]), ''.join([s[i] for i in range(1, 10, 2)]))
		(g1, b1) = (a.replace('?', '1', a.count('?')), a.replace('?', '0', a.count('?')))
		(g2, b2) = (b.replace('?', '1', b.count('?')), b.replace('?', '0', b.count('?')))
		(c1, c2) = (0, 0)
		ans = [10]
		for i in range(10):
			if i % 2 == 0:
				c1 += 1 if g1[i // 2] == '1' else 0
				if c1 > c2 + (5 - i // 2):
					ans.append(i + 1)
					break
			else:
				c2 += 1 if b2[i // 2] == '1' else 0
				if c1 > c2 + (4 - i // 2):
					ans.append(i + 1)
					break
		(c1, c2) = (0, 0)
		for i in range(10):
			if i % 2 == 0:
				c1 += 1 if b1[i // 2] == '1' else 0
				if c2 > c1 + (4 - i // 2):
					ans.append(i + 1)
					break
			else:
				c2 += 1 if g2[i // 2] == '1' else 0
				if c2 > c1 + (4 - i // 2):
					ans.append(i + 1)
					break
		print(min(ans))
main()


for tc in range(int(input())):
	s = input()
	(p1, p2) = (20, 20)
	(p1win, p2win) = (0, 0)
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '1' or s[i] == '?':
				p1win += 1
		elif s[i] == '1':
			p2win += 1
		if p1win > p2win + (10 - i) // 2:
			p1 = i + 1
			break
	(p1win, p2win) = (0, 0)
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '1':
				p1win += 1
		elif s[i] == '1' or s[i] == '?':
			p2win += 1
		p1pos = p1win + (10 - i) // 2 - (i % 2 == 0)
		if p2win > p1pos:
			p2 = i + 1
			break
	if p1 == p2 and p1 == 20:
		print(10)
	else:
		print(min(p1, p2))


t = int(input())
for _ in range(t):
	s = input()
	a = 0
	b = 0
	a1 = 0
	b1 = 0
	rema = 5
	remb = 5
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '1':
				a += 1
			if s[i] == '?':
				a1 += 1
			rema -= 1
		if i % 2 == 1:
			if s[i] == '1':
				b += 1
			if s[i] == '?':
				b1 += 1
			remb -= 1
		if a + a1 > remb + b or b + b1 > rema + a:
			print(i + 1)
			break
		if i == 9:
			print(i + 1)


import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq

def input():
	return sys.stdin.readline()[:-1]
INF = 10 ** 10

def solve(S):
	game1 = 10
	(n1, n2) = (0, 0)
	D1 = {'1': 1, '0': 0, '?': 1}
	D2 = {'1': 1, '0': 0, '?': 0}
	for i in range(5):
		n1 += D1[S[i * 2]]
		if n1 + (4 - i) < n2 or n2 + (5 - i) < n1:
			game1 = i * 2 + 1
			break
		n2 += D2[S[i * 2 + 1]]
		if n1 + (4 - i) < n2 or n2 + (4 - i) < n1:
			game1 = i * 2 + 2
			break
	game2 = 10
	(n1, n2) = (0, 0)
	D1 = {'1': 1, '0': 0, '?': 0}
	D2 = {'1': 1, '0': 0, '?': 1}
	for i in range(5):
		n1 += D1[S[i * 2]]
		if n1 + (4 - i) < n2 or n2 + (5 - i) < n1:
			game2 = i * 2 + 1
			break
		n2 += D2[S[i * 2 + 1]]
		if n1 + (4 - i) < n2 or n2 + (4 - i) < n1:
			game2 = i * 2 + 2
			break
	return min(game1, game2)
T0 = int(input())
for _ in range(T0):
	S = input()
	print(solve(S))


for _ in range(int(input())):
	st1 = input()
	temp = []
	temp2 = []
	ans = 10
	for i in range(10):
		if i % 2 == 0 and st1[i] == '?':
			temp.append('1')
			temp2.append('0')
		elif st1[i] == '?':
			temp.append('0')
			temp2.append('1')
		else:
			temp.append(st1[i])
			temp2.append(st1[i])
	a_s = b_s = 5
	a = b = 0
	for j in range(10):
		if j % 2 == 0:
			a += int(temp[j])
			a_s -= 1
		else:
			b += int(temp[j])
			b_s -= 1
		if a < b and abs(a - b) > a_s:
			ans = j + 1
			break
		elif b < a and abs(a - b) > b_s:
			ans = j + 1
			break
	a = b = 0
	a_s = b_s = 5
	for j in range(10):
		if j % 2 == 0:
			a += int(temp2[j])
			a_s -= 1
		else:
			b += int(temp2[j])
			b_s -= 1
		if a < b and abs(a - b) > a_s:
			ans = min(ans, j + 1)
			break
		elif b < a and abs(a - b) > b_s:
			ans = min(ans, j + 1)
			break
	print(ans)


def recur(s, i, teamA, teamB):
	global mini
	attempts = int((10 - i) / 2) + int(10 - i) % 2
	if teamA > teamB and attempts < teamA - teamB:
		if i < mini:
			mini = i
		return 0
	attempts = int((10 - i) / 2)
	if teamB > teamA and attempts < teamB - teamA:
		if i < mini:
			mini = i
		return 0
	if i == len(s):
		if 10 < mini:
			mini = 10
		return 0
	if s[i] == '0':
		recur(s, i + 1, teamA, teamB)
	if s[i] == '1':
		if i % 2 == 0:
			recur(s, i + 1, teamA + 1, teamB)
		if i % 2 != 0:
			recur(s, i + 1, teamA, teamB + 1)
	if s[i] == '?':
		if i % 2 == 0:
			recur(s, i + 1, teamA, teamB)
			recur(s, i + 1, teamA + 1, teamB)
		if i % 2 != 0:
			recur(s, i + 1, teamA, teamB + 1)
			recur(s, i + 1, teamA, teamB)
mini = 100000
tests = int(input())
mod = 10 ** 9 + 7
while tests:
	tests -= 1
	s = input()
	mini = 100000
	recur(s, 0, 0, 0)
	print(mini)


import sys
from bisect import bisect_left as lb
from collections import deque
from queue import PriorityQueue as pq
from math import *
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
mod = 10 ** 9 + 7
for _ in range(ii()):
	s = list(ip())
	ans = 10
	for i in range(0, 1025):
		x = list(bin(i)[2:])
		x = ['0' for j in range(10 - len(x))] + x
		fl = 0
		for j in range(10):
			if s[j] == '?':
				continue
			if s[j] != x[j]:
				fl = 1
				break
		if fl:
			continue
		t1 = 0
		t2 = 0
		t3 = 0
		t4 = 0
		for j in range(10):
			t3 = 0
			t4 = 0
			if j % 2 == 0 and x[j] == '1':
				t1 += 1
			if j % 2 == 1 and x[j] == '1':
				t2 += 1
			for k in range(j + 1, 10):
				if k % 2 == 0:
					t3 += 1
				else:
					t4 += 1
			if t1 > t2 + t4 or t2 > t1 + t3:
				ans = min(ans, j + 1)
				break
	print(ans)


import sys
from collections import defaultdict
from collections import deque

def solve(shots):
	best = 10
	(f_max, s_min) = (0, 0)
	for i in range(5):
		if f_max - s_min > 5 - i:
			best = i * 2
			break
		if shots[i * 2] != '0':
			f_max += 1
		if f_max - s_min > 5 - i:
			best = i * 2 + 1
			break
		if shots[i * 2 + 1] == '1':
			s_min += 1
	(s_max, f_min) = (0, 0)
	for i in range(5):
		if shots[2 * i] == '1':
			f_min += 1
		if s_max - f_min > 4 - i:
			best = min(best, i * 2 + 1)
			break
		if shots[2 * i + 1] != '0':
			s_max += 1
		if s_max - f_min > 4 - i:
			best = min(best, i * 2 + 2)
			break
	return best
n = int(input())
for _ in range(n):
	shots = input()
	print(solve(shots))


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
import math
from bisect import *
from heapq import *
from collections import defaultdict as dd
from collections import OrderedDict as odict
from collections import Counter as cc
from collections import deque
from itertools import groupby
sys.setrecursionlimit(20 * 20 * 20 * 20 + 10)

def help(s):
	n = len(s) // 2
	aw = 0
	al = n
	bw = 0
	bl = n
	count = 0
	for i in range(0, 2 * n):
		count += 1
		if count == 2 * n:
			break
		if i % 2 == 0:
			if s[i] == '1':
				aw += 1
			else:
				al -= 1
			if aw > bl:
				return count
				break
			if al < bw:
				return count
				break
		else:
			if s[i] == '1':
				bw += 1
			else:
				bl -= 1
			if bw > al:
				return count
				break
			if bl < aw:
				return count
				break
	if count == 2 * n:
		return count

def solve():
	string = list(map(str, input().strip()))
	n = len(string)
	c = string.copy()
	for i in range(0, n, 2):
		if string[i] == '?':
			string[i] = '1'
	first = help(string)
	string = c.copy()
	for i in range(1, n, 2):
		if string[i] == '?':
			string[i] = '1'
	second = help(string)
	print(min(first, second))

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = takein()
	for tt in range(1, t + 1):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def takein():
	return int(sys.stdin.readline().rstrip('\r\n'))

def takesr():
	return sys.stdin.readline().rstrip('\r\n')

def takeiar():
	return list(map(int, sys.stdin.readline().rstrip('\r\n').split()))

def takesar():
	return list(map(str, sys.stdin.readline().rstrip('\r\n').split()))

def takeivr():
	return map(int, sys.stdin.readline().rstrip('\r\n').split())

def takesvr():
	return map(str, sys.stdin.readline().rstrip('\r\n').split())

def ispalindrome(s):
	return s == s[::-1]

def invert(bit_s):
	temp = int(bit_s, 2)
	inverse_s = temp ^ 2 ** (len(bit_s) + 1) - 1
	rslt = bin(inverse_s)[3:]
	return str(rslt)

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def power_two(x):
	return x and (not x & x - 1)

def ceil(a, b):
	return -(-a // b)

def seive(n):
	a = [1]
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	return a

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def binary_search(li, val):
	ans = -1
	lb = 0
	ub = len(li) - 1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


T = int(input())
while T > 0:
	T -= 1
	s = input()
	kick = 9
	t1 = t2 = 0
	for i in range(10):
		if i % 2 == 0:
			t1 += s[i] == '1'
		else:
			t2 += s[i] != '0'
		if t1 > t2 + (10 - i) // 2 or t2 > t1 + (9 - i) // 2:
			kick = min(kick, i)
	t1 = t2 = 0
	for i in range(10):
		if i % 2 == 0:
			t1 += s[i] != '0'
		else:
			t2 += s[i] == '1'
		if t1 > t2 + (10 - i) // 2 or t2 > t1 + (9 - i) // 2:
			kick = min(kick, i)
	print(kick + 1)


for _ in range(int(input())):
	s = input()
	c = [[0] * 2 for _ in range(12)]
	for (j, i) in enumerate(s):
		if i == '1':
			c[j][0] = c[j - 2][0] + 1
			c[j][1] = c[j - 2][1]
		elif i == '?':
			c[j][1] = 1 + c[j - 2][1]
			c[j][0] = c[j - 2][0]
		else:
			(c[j][0], c[j][1]) = (c[j - 2][0], c[j - 2][1])
	flag = 10
	(t1, t2) = (5, 5)
	for i in range(len(c)):
		if i & 1:
			t1 -= 1
		else:
			t2 -= 1
		if c[i][1] + c[i][0] > c[i - 1][0] + t1 or c[i - 1][0] + c[i - 1][1] > c[i][0] + t2:
			flag = i
			break
	print(min(10, flag + 1))


def solve(s1):
	(m, o) = (0, 0)
	ans = 10
	for (i, it) in enumerate(s1):
		if i % 2:
			if s1[i] == '1':
				o += 1
		elif s1[i] != '0':
			m += 1
		left = 10 - i - 1
		(m1, o1) = (left // 2, (left + 1) // 2)
		if m > o + o1:
			ans = min(ans, i + 1)
			break
	(m, o) = (0, 0)
	for (i, it) in enumerate(s1):
		if i % 2:
			if s1[i] != '0':
				o += 1
		elif s1[i] == '1':
			m += 1
		left = 10 - i - 1
		(m1, o1) = (left // 2, (left + 1) // 2)
		if m + m1 < o:
			ans = min(ans, i + 1)
			break
	return ans
for case in range(int(input())):
	s1 = input()
	ans = solve(s1)
	print(ans)


from collections import defaultdict, Counter, deque
from math import sqrt, log10, log, floor, factorial
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations
import sys, io, os
input = sys.stdin.readline
inf = float('inf')
mod = 10 ** 9 + 7

def get_list():
	return [int(i) for i in input().split()]

def yn(a):
	print('YES' if a else 'NO')
ceil = lambda a, b: (a + b - 1) // b
t = int(input())
for i in range(t):
	s = [0] + list(input().strip())
	n = len(s) - 1
	maxright1 = [0 for i in range(n + 2)]
	maxright2 = [0 for i in range(n + 2)]
	for i in range(n, 0, -1):
		if i % 2 == 1:
			maxright1[i] = maxright1[i + 1] + 1
			maxright2[i] = maxright2[i + 1]
		else:
			maxright1[i] = maxright1[i + 1]
			maxright2[i] = maxright2[i + 1] + 1
	maxleft1 = [0 for i in range(n + 2)]
	maxleft2 = [0 for i in range(n + 2)]
	minleft1 = [0 for i in range(n + 2)]
	minleft2 = [0 for i in range(n + 2)]
	for i in range(1, n + 1):
		if s[i] == '1':
			if i % 2 == 1:
				minleft1[i] = minleft1[i - 1] + 1
				minleft2[i] = minleft2[i - 1]
			else:
				minleft1[i] = minleft1[i - 1]
				minleft2[i] = minleft2[i - 1] + 1
		else:
			minleft1[i] = minleft1[i - 1]
			minleft2[i] = minleft2[i - 1]
		if s[i] != '0':
			if i % 2 == 1:
				maxleft1[i] = maxleft1[i - 1] + 1
				maxleft2[i] = maxleft2[i - 1]
			else:
				maxleft1[i] = maxleft1[i - 1]
				maxleft2[i] = maxleft2[i - 1] + 1
		else:
			maxleft1[i] = maxleft1[i - 1]
			maxleft2[i] = maxleft2[i - 1]
	ans = n
	for i in range(1, n + 1):
		if maxleft1[i] - minleft2[i] > maxright2[i + 1]:
			ans = i
			break
		elif maxleft2[i] - minleft1[i] > maxright1[i + 1]:
			ans = i
			break
	print(ans)


def solve(arr, flag):
	(s1, s2) = (0, 0)
	(r1, r2) = (5, 5)
	for i in range(10):
		if arr[i] == '1':
			if i % 2 == 0:
				s1 += 1
			else:
				s2 += 1
		if arr[i] == '?':
			if flag and i % 2 == 0:
				s1 += 1
			elif not flag and i % 2 == 1:
				s2 += 1
		if i % 2 == 0:
			r1 -= 1
		else:
			r2 -= 1
		if s1 > s2 + r2 or s2 > s1 + r1:
			return i + 1
	return 10
for _ in range(int(input())):
	s = list(input())
	ans1 = solve(s, True)
	ans2 = solve(s, False)
	print(min(ans1, ans2))


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	s = st()
	f = 0
	ss = 0
	res = float('inf')
	for i in range(10):
		if i % 2 == 0 and (s[i] == '?' or s[i] == '1'):
			f += 1
		elif i % 2 and s[i] == '1':
			ss += 1
		if f > ss + (10 - i) // 2:
			res = min(res, i + 1)
			break
	(f, ss) = (0, 0)
	for i in range(10):
		if i % 2 == 0 and s[i] == '1':
			f += 1
		elif i % 2 and s[i] in ['?', '1']:
			ss += 1
		if ss > f + (10 - i - 1) // 2:
			res = min(res, i + 1)
			break
	print(min(res, 10))


def naiveSolve():
	return

def main():
	t = int(input())
	allans = []
	for _ in range(t):
		s = input()
		minTurns = 10
		p1RemTurns = p2RemTurns = 5
		p1Score = p2Score = 0
		p1Next = True
		turns = 1
		while turns < 10:
			x = s[turns - 1]
			if p1Next:
				if x == '?' or x == '1':
					p1Score += 1
				p1RemTurns -= 1
			else:
				if x == '1':
					p2Score += 1
				p2RemTurns -= 1
			if p1Score - p2Score > p2RemTurns:
				break
			turns += 1
			p1Next = not p1Next
		minTurns = turns
		p1RemTurns = p2RemTurns = 5
		p1Score = p2Score = 0
		p1Next = True
		turns = 1
		while turns < 10:
			x = s[turns - 1]
			if p1Next:
				if x == '1':
					p1Score += 1
				p1RemTurns -= 1
			else:
				if x == '1' or x == '?':
					p2Score += 1
				p2RemTurns -= 1
			if p2Score - p1Score > p1RemTurns:
				break
			turns += 1
			p1Next = not p1Next
		minTurns = min(turns, minTurns)
		allans.append(minTurns)
	multiLineArrayPrint(allans)
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(l, r):
	print('? {} {}'.format(l, r))
	sys.stdout.flush()
	return int(input())

def answerInteractive(x):
	print('! {}'.format(x))
	sys.stdout.flush()
inf = float('inf')
MOD = 998244353
from math import gcd, floor, ceil
for _abc in range(1):
	main()


testcase = int(input())
for i in range(testcase):
	s = input()
	first_ct = 0
	last_ct = 0
	c = 0
	a_fst = [0]
	b_lst = [0]
	x = 9
	res = 0
	for i in range(10):
		res += 1
		if i % 2 == 0:
			first_ct += 1
			if s[i] == '1':
				for i in range(len(a_fst)):
					a_fst[i] += 1
			elif s[i] == '?':
				p = max(a_fst)
				a_fst.append(p + 1)
		else:
			last_ct += 1
			if s[i] == '1':
				for i in range(len(b_lst)):
					b_lst[i] += 1
			elif s[i] == '?':
				p = max(b_lst)
				b_lst.append(p + 1)
		if min(a_fst) + (5 - first_ct) < max(b_lst):
			c = 1
			x = i
			break
		elif min(b_lst) + (5 - last_ct) < max(a_fst):
			x = i
			c = 1
			break
	print(res)


t = int(input())
while t != 0:
	mini = [10]
	s = input()

	def calc(s, i, a, b):
		if i + 1 >= mini[0]:
			return ()
		if s[i] == '1':
			if i % 2 == 0:
				if a + 1 - b > 10 - (i + 1) - (10 - (i + 1)) // 2:
					if i + 1 < mini[0]:
						mini[0] = i + 1
					return ()
				calc(s, i + 1, a + 1, b)
			else:
				if b + 1 - a > 10 - (i + 1) - (10 - (i + 1)) // 2:
					if i + 1 < mini[0]:
						mini[0] = i + 1
					return ()
				calc(s, i + 1, a, b + 1)
		elif s[i] == '0':
			if i % 2 == 0:
				if b - a > 10 - (i + 1) - ((10 - (i + 1)) // 2 + 1):
					if i + 1 < mini[0]:
						mini[0] = i + 1
					return ()
				calc(s, i + 1, a, b)
			else:
				if a - b > 10 - (i + 1) - (10 - (i + 1)) // 2:
					if i + 1 < mini[0]:
						mini[0] = i + 1
					return ()
				calc(s, i + 1, a, b)
		else:
			if i % 2 == 0:
				if a + 1 - b > 10 - (i + 1) - (10 - (i + 1)) // 2:
					if i + 1 < mini[0]:
						mini[0] = i + 1
					return ()
				calc(s, i + 1, a + 1, b)
			else:
				if b + 1 - a > 10 - (i + 1) - (10 - (i + 1)) // 2:
					if i + 1 < mini[0]:
						mini[0] = i + 1
					return ()
				calc(s, i + 1, a, b + 1)
			if i % 2 == 0:
				if b - a > 10 - (i + 1) - ((10 - (i + 1)) // 2 + 1):
					if i + 1 < mini[0]:
						mini[0] = i + 1
					return ()
				calc(s, i + 1, a, b)
			else:
				if a - b > 10 - (i + 1) - (10 - (i + 1)) // 2:
					if i + 1 < mini[0]:
						mini[0] = i + 1
					return ()
				calc(s, i + 1, a, b)
	a = 0
	b = 0
	calc(s, 0, a, b)
	print(mini[0])
	t -= 1


t = int(input())
for i in range(t):
	s = input()
	dp = [[[] for i in range(2)] for i in range(10)]
	if s[0] == '1':
		dp[0][0] = [1]
		dp[0][1] = [-1]
	elif s[0] == '0':
		dp[0][0] = [0]
		dp[0][1] = [0]
	else:
		dp[0][0] = [1, 0]
		dp[0][1] = [-1, 0]
	flag = False
	for k in range(1, 10):
		if s[k] == '1':
			for pro in range(len(dp[k - 1][k % 2])):
				dp[k][k % 2].append(dp[k - 1][k % 2][pro] + 1)
			for tro in range(len(dp[k - 1][1 - k % 2])):
				if dp[k - 1][1 - k % 2][tro]:
					dp[k][1 - k % 2].append(dp[k - 1][1 - k % 2][tro] - 1)
				else:
					dp[k][1 - k % 2].append(dp[k - 1][1 - k % 2][tro] - 1)
					dp[k][k % 2].append(1)
		elif s[k] == '?':
			for pro in range(len(dp[k - 1][k % 2])):
				dp[k][k % 2].append(dp[k - 1][k % 2][pro] + 1)
				dp[k][k % 2].append(dp[k - 1][k % 2][pro])
			for tro in range(len(dp[k - 1][1 - k % 2])):
				if dp[k - 1][1 - k % 2][tro]:
					dp[k][1 - k % 2].append(dp[k - 1][1 - k % 2][tro] - 1)
					dp[k][1 - k % 2].append(dp[k - 1][1 - k % 2][tro])
				else:
					dp[k][1 - k % 2].append(dp[k - 1][1 - k % 2][tro] - 1)
					dp[k][1 - k % 2].append(dp[k - 1][1 - k % 2][tro])
					dp[k][k % 2].append(1)
		else:
			dp[k][k % 2] = dp[k - 1][k % 2]
			dp[k][1 - k % 2] = dp[k - 1][1 - k % 2]
		if k % 2:
			if max(dp[k][k % 2]) > (9 - k) // 2 or max(dp[k][1 - k % 2]) > (9 - k) // 2:
				print(k + 1)
				flag = True
				break
		elif max(dp[k][k % 2]) > (9 - k) // 2 + 1 or max(dp[k][1 - k % 2]) > (9 - k) // 2:
			print(k + 1)
			flag = True
			break
	if flag == False:
		print(10)


def f(n):
	if n == 1:
		return [4, 5]
	elif n == 2:
		return [4, 4]
	elif n == 3:
		return [3, 4]
	elif n == 4:
		return [3, 3]
	elif n == 5:
		return [2, 3]
	elif n == 6:
		return [2, 2]
	elif n == 7:
		return [1, 2]
	elif n == 8:
		return [1, 1]
	elif n == 9:
		return [0, 1]
	elif n == 10:
		return [0, 0]
n = int(input())
for i in range(n):
	s = str(input())
	arr1 = []
	arr2 = []
	for k in range(len(s)):
		arr1.append(s[k])
		arr2.append(s[k])
	for k in range(len(arr1)):
		if arr1[k] == '?':
			if k % 2 == 0:
				arr1[k] = '1'
				arr2[k] = '0'
			else:
				arr1[k] = '0'
				arr2[k] = '1'
	output1 = 0
	output2 = 0
	score1 = 0
	score2 = 0
	for j in range(len(arr1)):
		if j % 2 == 0:
			if arr1[j] == '1':
				score1 = score1 + 1
		elif arr1[j] == '1':
			score2 = score2 + 1
		if score1 > score2 and f(j + 1)[1] + score2 < score1:
			output1 = j + 1
			break
		elif score2 > score1 and f(j + 1)[0] + score1 < score2:
			output1 = j + 1
			break
		elif j == 9:
			output1 = j + 1
	score1 = 0
	score2 = 0
	for j in range(len(arr2)):
		if j % 2 == 0:
			if arr2[j] == '1':
				score1 = score1 + 1
		elif arr2[j] == '1':
			score2 = score2 + 1
		if score1 > score2 and f(j + 1)[1] + score2 < score1:
			output2 = j + 1
			break
		elif score2 > score1 and f(j + 1)[0] + score1 < score2:
			output2 = j + 1
			break
		elif j == 9:
			output2 = j + 1
	print(min(output1, output2))


t = int(input())
for _ in range(t):
	s = input()
	(t1, t2, w1, w2) = (0, 0, 0, 0)
	for i in range(len(s)):
		if i % 2:
			if s[i] == '1':
				t2 += 1
			elif s[i] == '?':
				w2 += 1
		elif s[i] == '1':
			t1 += 1
		elif s[i] == '?':
			w1 += 1
		if t2 + (10 - i) // 2 < t1 + w1 or t1 + (9 - i) // 2 < t2 + w2:
			print(i + 1)
			break
	else:
		print(10)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
from collections import defaultdict as dd
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
stdmap = lambda : map(int, stdstr().split())
stdarr = lambda : list(map(int, stdstr().split()))
mod = 1000000007
for _ in range(stdint()):
	s = input()
	mi = [0, 0]
	ma = [0, 0]
	res = -1
	for i in range(len(s)):
		if s[i] == '?':
			ma[i % 2] += 1
		elif s[i] == '1':
			ma[i % 2] += 1
			mi[i % 2] += 1
		oddRem = math.ceil((9 - i) / 2)
		evenRem = 9 - i - oddRem
		if ma[0] > mi[1] + oddRem:
			break
		elif ma[1] > mi[0] + evenRem:
			break
	print(i + 1)


for _ in range(int(input())):
	s = input()
	(a, a_, b, b_) = (0, 0, 0, 0)
	for i in range(10):
		if i % 2:
			if s[i] == '1':
				b += 1
				b_ += 1
			if s[i] == '?':
				b_ += 1
			if b_ - a > (9 - i) // 2 or a_ - b > (10 - i) // 2:
				print(i + 1)
				break
		if not i % 2:
			if s[i] == '1':
				a += 1
				a_ += 1
			if s[i] == '?':
				a_ += 1
			if a_ - b > (10 - i) // 2 or b_ - a > (9 - i) // 2:
				print(i + 1)
				break
		if i == 9:
			print(10)


from collections import deque as de
import math
import sys
from math import sqrt as sq
from math import floor as fl
from math import ceil as ce
from sys import getfilesystemencodeerrors, stdin, stdout
sys.setrecursionlimit(10 ** 7)
from collections import Counter as cnt
from functools import reduce
from itertools import groupby as gb
from bisect import bisect_left as bl, bisect_right as br
from typing import Coroutine
sys.setrecursionlimit(10 ** 6)

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def __iter__(self):
		return iter(self.data)

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

class graph:

	def __init__(self):
		self.graphdict = {}

	def add_edge(self, node, neighbor):
		if node not in self.graphdict:
			self.graphdict[node] = [neighbor]
		else:
			self.graphdict[node].append(neighbor)

	def show_edge(self):
		for node in self.graphdict:
			for neighbors in self.graphdict:
				print(node, neighbors)

	def show_graph(self):
		return self.graphdict
gr = graph()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binarytodecimal(n):
	return int(n, 2)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def getProduct(n):
	product = 1
	while n != 0:
		product = product * (n % 10)
		n = n // 10
	return product

def lcm(x, y):
	lcm = x * y // math.gcd(x, y)
	return lcm

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))

def checkisap(list):
	d = list[1] - list[0]
	for i in range(2, len(list)):
		temp = list[i] - list[i - 1]
		if temp != d:
			return False
	return True

def primes_method5(n):
	out = {}
	sieve = [True] * (n + 1)
	for p in range(2, n + 1):
		if sieve[p]:
			out[p] = 1
			for i in range(p, n + 1, p):
				sieve[i] = False
	return out

def getSum(n):
	strr = str(n)
	list_of_number = list(map(int, strr.strip()))
	return sum(list_of_number)

def checkperfectsquare(n):
	if ce(sq(n)) == fl(sq(n)):
		return True
	else:
		return False

def ceildiv(x, y):
	return (x + y - 1) // y

def di():
	return map(int, input().split())

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def si():
	return list(map(str, input()))

def indict():
	dic = {}
	for (index, value) in enumerate(input().split()):
		dic[int(index)] = int(value)
	return dic

def frqdict():
	dic = {}
	for (index, value) in enumerate(input()):
		if value not in dic:
			dic[value] = 1
		else:
			dic[value] += 1
	return dic
t = ii()
while t:
	t -= 1
	s = si()
	if '?' in s:
		temps = s.copy()
		for i in range(10):
			if s[i] == '?':
				if i % 2 == 0:
					temps[i] = '1'
					s[i] = '0'
				else:
					temps[i] = '0'
					s[i] = '1'
		scocre1 = 0
		chance1 = [1, 3, 5, 7, 9]
		scocre2 = 0
		chance2 = [2, 4, 6, 8, 10]
		for i in range(len(s)):
			if i % 2 == 0:
				if temps[i] == '1':
					scocre1 += 1
				chance1.remove(i + 1)
			else:
				if temps[i] == '1':
					scocre2 += 1
				chance2.remove(i + 1)
			if scocre1 > scocre2 and scocre2 + len(chance2) < scocre1:
				break
		scocre1 = 0
		chance1 = [1, 3, 5, 7, 9]
		scocre2 = 0
		chance2 = [2, 4, 6, 8, 10]
		for j in range(len(s)):
			if j % 2 == 0:
				if s[j] == '1':
					scocre1 += 1
				chance1.remove(j + 1)
			else:
				if s[j] == '1':
					scocre2 += 1
				chance2.remove(j + 1)
			if scocre1 < scocre2 and scocre1 + len(chance1) < scocre2:
				break
		print(min(i, j) + 1)
	else:
		scocre1 = 0
		chance1 = [1, 3, 5, 7, 9]
		scocre2 = 0
		chance2 = [2, 4, 6, 8, 10]
		for i in range(len(s)):
			if i % 2 == 0:
				if s[i] == '1':
					scocre1 += 1
				chance1.remove(i + 1)
			else:
				if s[i] == '1':
					scocre2 += 1
				chance2.remove(i + 1)
			if scocre1 > scocre2 and scocre2 + len(chance2) < scocre1:
				break
		scocre1 = 0
		chance1 = [1, 3, 5, 7, 9]
		scocre2 = 0
		chance2 = [2, 4, 6, 8, 10]
		for j in range(len(s)):
			if j % 2 == 0:
				if s[j] == '1':
					scocre1 += 1
				chance1.remove(j + 1)
			else:
				if s[j] == '1':
					scocre2 += 1
				chance2.remove(j + 1)
			if scocre1 < scocre2 and scocre1 + len(chance1) < scocre2:
				break
		print(min(i, j) + 1)


def penalty(array):
	array = list(array)
	a_1s = 0
	a_qs = 0
	a__s = 5
	b_1s = 0
	b_qs = 0
	b__s = 5
	for x in range(0, 10):
		if x % 2 == 0:
			if array[x] == '1':
				a_1s += 1
			elif array[x] == '?':
				a_qs += 1
			a__s -= 1
		else:
			if array[x] == '1':
				b_1s += 1
			elif array[x] == '?':
				b_qs += 1
			b__s -= 1
		if a_1s + a_qs > b_1s + b__s or b_1s + b_qs > a_1s + a__s:
			return x + 1
	return 10
t = int(input())
for _ in range(t):
	l = input()
	print(penalty(l))


for t in range(int(input())):
	s = input()
	(p, q) = (s[0::2], s[1::2])
	(c, d, u1, u2) = (0, 0, 0, 0)
	(r1, r2) = (5, 5)
	for i in range(len(s)):
		if s[i] == '1':
			if i % 2 == 0:
				c += 1
			else:
				d += 1
		elif s[i] == '?':
			if i % 2 == 0:
				u1 += 1
			else:
				u2 += 1
		if i % 2 == 0:
			r1 -= 1
		else:
			r2 -= 1
		if c + u1 > d + r2:
			print(i + 1)
			break
		elif d + u2 > c + r1:
			print(i + 1)
			break
	else:
		print(10)


for s in [*open(0)][1:]:
	a = b = i = 0
	j = 1
	while i < 10 and (11 - i) // 2 >= a and ((10 - i) // 2 >= b):
		a += j * (s[i] in '1' + (i % 2 ^ 1) * '?')
		b -= j * (s[i] in '1' + i % 2 * '?')
		i += 1
		j = -j
	print(i)


import sys
input = sys.stdin.readline

def I():
	return input().strip()

def II():
	return int(input().strip())

def LI():
	return [*map(int, input().strip().split())]
import copy, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter, OrderedDict
from itertools import permutations, combinations, groupby
from operator import itemgetter
for _ in range(II()):
	s = I()
	odd = 10
	(var1, var2) = (0, 0)
	for i in range(10):
		if s[i] == '?' and i % 2 == 0:
			var1 += 1
		if s[i] == '1' and i % 2 == 0:
			var1 += 1
		if s[i] == '1' and i % 2 == 1:
			var2 += 1
		if var1 - var2 > math.ceil((9 - i) / 2):
			odd = i + 1
			break
	even = 10
	(var1, var2) = (0, 0)
	for i in range(10):
		if s[i] == '?' and i % 2 == 1:
			var2 += 1
		if s[i] == '1' and i % 2 == 0:
			var1 += 1
		if s[i] == '1' and i % 2 == 1:
			var2 += 1
		if var2 - var1 > math.floor((9 - i) / 2):
			even = i + 1
			break
	print(min(odd, even))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import *
from collections import deque
from operator import itemgetter, attrgetter
from decimal import *
import bisect
import math
import heapq as hq
MOD = 10 ** 9 + 7

def is_prime(n):
	if n == 2 or n == 3:
		return True
	if n < 2 or n % 2 == 0:
		return False
	if n < 9:
		return True
	if n % 3 == 0:
		return False
	r = int(n ** 0.5)
	f = 5
	while f <= r:
		if n % f == 0:
			return False
		if n % (f + 2) == 0:
			return False
		f += 6
	return True

def pow(a, b, m):
	ans = 1
	while b:
		if b & 1:
			ans = ans * a % m
		b //= 2
		a = a * a % m
	return ans

def ispalindrome(s):
	if s[:] == s[::-1]:
		return 1
	return 0
dp = []
limit = []
v = []

def dpdfs(u, t=-1):
	dp[0][u] = 0
	dp[1][u] = 0
	for i in v[u]:
		if i == t:
			continue
		if dp[1][i] == -1:
			dpdfs(i, u)
		dp[0][u] += max(abs(limit[0][u] - limit[1][i]) + dp[1][i], abs(limit[0][u] - limit[0][i]) + dp[0][i])
		dp[1][u] += max(abs(limit[1][u] - limit[1][i]) + dp[1][i], abs(limit[1][u] - limit[0][i]) + dp[0][i])
vis = []
f = 0

def dfs(i):
	vis[i] = 1
	act[i] = 1
	for j in v[i]:
		if act[j]:
			f = 1
			return -1
		if vis[j] == 0:
			if dfs(j) == -1:
				return -1
	act[i] = 0
	ans.append(i)
	return 0
from queue import PriorityQueue

def z_algorithm(s):
	res = [0] * len(s)
	res[0] = len(s)
	(i, j) = (1, 0)
	while i < len(s):
		while i + j < len(s) and s[j] == s[i + j]:
			j += 1
		res[i] = j
		if j == 0:
			i += 1
			continue
		k = 1
		while i + k < len(s) and k + res[k] < j:
			res[i + k] = res[k]
			k += 1
		(i, j) = (i + k, j - k)
	return res

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a / gcd(a, b) * b
for _ in range(int(input())):
	s = input()
	first = []
	second = []
	buffer = []
	x = 0
	fir = []
	sec = []
	for i in range(len(s)):
		if i % 2 == 0:
			if s[i] == '0':
				first.append(0)
			else:
				first.append(1)
			if s[i] == '1':
				fir.append(1)
			else:
				fir.append(0)
		else:
			if s[i] == '1':
				second.append(1)
			else:
				second.append(0)
			if s[i] == '0':
				sec.append(0)
			else:
				sec.append(1)
	win = 0
	j = 0
	lose = 0
	for i in range(5):
		if lose + 5 - i < win or win + 5 - i < lose:
			break
		if first[i]:
			win += 1
		j += 1
		if lose + 5 - i < win or win + 5 - i - 1 < lose:
			break
		if second[i]:
			lose += 1
		j += 1
		if lose + 5 - i - 1 < win or win + 5 - i - 1 < lose:
			break
	ans1 = j
	win = 0
	k = 0
	lose = 0
	for i in range(5):
		if lose + 5 - i < win or win + 5 - i < lose:
			break
		if fir[i]:
			win += 1
		k += 1
		if lose + 5 - i < win or win + 5 - i - 1 < lose:
			break
		if sec[i]:
			lose += 1
		k += 1
		if lose + 5 - i - 1 < win or win + 5 - i - 1 < lose:
			break
	ans2 = k
	print(min(ans1, ans2))


t = int(input())
while t:
	s = input()
	sa = 0
	sb = 0
	ta = 5
	tb = 5
	winA = 0
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '1' or s[i] == '?':
				sa += 1
			ta -= 1
		else:
			if s[i] == '1':
				sb += 1
			tb -= 1
		if sa > sb + tb:
			break
	winA = i + 1
	sa = 0
	sb = 0
	ta = 5
	tb = 5
	winB = 0
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '1':
				sa += 1
			ta -= 1
		else:
			if s[i] == '1' or s[i] == '?':
				sb += 1
			tb -= 1
		if sb > sa + ta:
			break
	winB = i + 1
	print(min(winA, winB))
	t -= 1


import sys
input = sys.stdin.readline
q = int(input())
for u in range(q):
	s = input()
	ans1 = 0
	p1 = 0
	p2 = 0
	q1 = 0
	q2 = 0
	for i in range(10):
		if i % 2 == 0:
			q1 += 1
			if s[i] == '?' or s[i] == '1':
				p1 += 1
		else:
			q2 += 1
			if s[i] == '1':
				p2 += 1
		if p2 + (5 - q2) < p1:
			ans1 = i + 1
			break
	if ans1 == 0:
		ans1 = 11
	p1 = 0
	p2 = 0
	q1 = 0
	q2 = 0
	ans2 = 0
	for i in range(10):
		if i % 2 == 0:
			q1 += 1
			if s[i] == '1':
				p1 += 1
		else:
			q2 += 1
			if s[i] == '?' or s[i] == '1':
				p2 += 1
		if p1 + (5 - q1) < p2:
			ans2 = i + 1
			break
	if ans2 == 0:
		ans2 = 11
	if ans1 == ans2 and ans1 == 11:
		print(10)
	else:
		print(min(ans1, ans2))


def getRange(t, n):
	mini = 0
	maxi = 0
	for i in range(n):
		if t[i] == '1':
			mini += 1
			maxi += 1
		elif t[i] != '0':
			maxi += 1
	return (mini, maxi)

def getResult(s):
	t1 = [s[0], s[2], s[4], s[6], s[8]]
	t2 = [s[1], s[3], s[5], s[7], s[9]]
	t1_3 = getRange(t1, 3)
	t2_3 = getRange(t2, 3)
	if t1_3[0] == 0 and t2_3[1] == 3 or (t2_3[0] == 0 and t1_3[1] == 3):
		return 6
	t1_4 = getRange(t1, 4)
	if t1_4[1] - t2_3[0] == 3 or t2_3[1] - t1_4[0] == 2:
		return 7
	t2_4 = getRange(t2, 4)
	if t1_4[1] - t2_4[0] == 2 or t2_4[1] - t1_4[0] == 2:
		return 8
	t1_5 = getRange(t1, 5)
	if t1_5[1] - t2_4[0] == 2 or t2_4[1] - t1_5[0] == 1:
		return 9
	return 10
t = int(input())
for i in range(t):
	s1 = input()
	print(getResult(s1))


from collections import defaultdict, deque
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 5)
A = []

def f(i, s, ct1, ct2):
	if i == len(s):
		return len(s)
	ans = float('inf')
	if s[i] == '?':
		s[i] = '1'
		ans = min(ans, f(i, list(s), ct1, ct2))
		s[i] = '0'
		ans = min(ans, f(i, list(s), ct1, ct2))
		return ans
	else:
		if i & 1:
			if s[i] == '1':
				ct2 += 1
			if ct1 > ct2 and (i + 1 < len(s) and ct1 > ct2 + C[i + 1][1]):
				return i + 1
			if ct2 > ct1 and (i + 1 < len(s) and ct2 > ct1 + C[i + 1][0]):
				return i + 1
		else:
			if s[i] == '1':
				ct1 += 1
			if ct1 > ct2 and (i + 1 < len(s) and ct1 > ct2 + C[i + 1][1]):
				return i + 1
			if ct2 > ct1 and (i + 1 < len(s) and ct2 > ct1 + C[i + 1][0]):
				return i + 1
		return f(i + 1, s, ct1, ct2)
for _ in range(int(input())):
	s = [*input()]
	C = [[0, 0] for _ in range(len(s))]
	for i in range(len(s) - 1, -1, -1):
		if i & 1:
			C[i][1] += 1
		else:
			C[i][0] += 1
		if i + 1 < len(s):
			C[i][0] += C[i + 1][0]
			C[i][1] += C[i + 1][1]
	print(f(0, s, 0, 0))


def score(s, player):
	score = [0]
	for (i, c) in enumerate(s):
		score.append(score[-1] + int(c) if i % 2 == player else score[-1])
	score.pop(0)
	return score
t = int(input())
for _ in range(t):
	s = input()
	a_worst = score(s.replace('?', '0'), player=0)
	b_worst = score(s.replace('?', '0'), player=1)
	a_best = score(s.replace('?', '1'), player=0)
	b_best = score(s.replace('?', '1'), player=1)
	a_best_possible = [a + p for (a, p) in zip(a_worst, [4, 4, 3, 3, 2, 2, 1, 1, 0, 0])]
	b_best_possible = [b + p for (b, p) in zip(b_worst, [5, 4, 4, 3, 3, 2, 2, 1, 1, 0])]
	for (i, (a, b)) in enumerate(zip(a_best_possible, b_best)):
		if a < b:
			break
	for (j, (b, a)) in enumerate(zip(b_best_possible, a_best)):
		if b < a:
			if j < i:
				i = j
			break
	print(i + 1)


T = int(input())

def splits(string):
	return [char for char in string]
for j in range(T):
	kicks = splits(input())
	goal_1 = 0
	goal_2 = 0
	answer_1 = 10
	answer_2 = 10
	for i in range(len(kicks)):
		if i % 2 == 0:
			if kicks[i] == '1':
				goal_1 += 1
			if kicks[i] == '?':
				goal_1 += 1
		elif kicks[i] == '1':
			goal_2 += 1
		if goal_1 - goal_2 > (10 - i) // 2 or goal_2 - goal_1 > (9 - i) // 2:
			answer_1 = i + 1
			break
	goal_1 = 0
	goal_2 = 0
	for i in range(len(kicks)):
		if i % 2 == 0:
			if kicks[i] == '1':
				goal_1 += 1
		else:
			if kicks[i] == '1':
				goal_2 += 1
			if kicks[i] == '?':
				goal_2 += 1
		if goal_1 - goal_2 > (10 - i) // 2 or goal_2 - goal_1 > (9 - i) // 2:
			answer_2 = i + 1
			break
	print(min(answer_1, answer_2))


for _ in range(int(input())):
	s = input()
	(o, e, c1, c2) = (0, 0, 0, 0)
	flag = 0
	for i in range(len(s)):
		if i % 2 == 0:
			if s[i] == '1':
				e += 1
			elif s[i] == '?':
				c1 += 1
		elif s[i] == '1':
			o += 1
		elif s[i] == '?':
			c2 += 1
		if o + c2 > e + (9 - i) // 2:
			print(i + 1)
			flag = 1
			break
		if e + c1 > o + (10 - i) // 2:
			print(i + 1)
			flag = 1
			break
	if not flag:
		print(10)


t = int(input())
while t:
	s = input()
	ans = 9
	c1 = 0
	c2 = 0
	for i in range(len(s)):
		if i % 2 == 0:
			if s[i] != '0':
				c1 += 1
		elif s[i] == '1':
			c2 += 1
		if c1 > c2 + (10 - i) // 2:
			ans = min(ans, i)
		if c2 > c1 + (9 - i) // 2:
			ans = min(ans, i)
	c1 = 0
	c2 = 0
	for i in range(len(s)):
		if i % 2 == 0:
			if s[i] == '1':
				c1 += 1
		elif s[i] != '0':
			c2 += 1
		if c1 > c2 + (10 - i) // 2:
			ans = min(ans, i)
		if c2 > c1 + (9 - i) // 2:
			ans = min(ans, i)
	print(ans + 1)
	t -= 1


import sys

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))
sys.setrecursionlimit(20000)
T = int(input())
for i in range(T):
	s = sys.stdin.readline()
	team1_max_lead = 0
	team2_max_lead = 0
	for i in range(1, 10 + 1):
		if i % 2 == 1:
			if s[i - 1] == '1':
				team1_max_lead += 1
				team2_max_lead -= 1
			elif s[i - 1] == '0':
				pass
			else:
				team1_max_lead += 1
			if team1_max_lead > (10 - i) // 2 + 1 or team2_max_lead > (10 - i) // 2:
				print(i)
				break
		else:
			if s[i - 1] == '1':
				team2_max_lead += 1
				team1_max_lead -= 1
			elif s[i - 1] == '0':
				pass
			else:
				team2_max_lead += 1
			if team1_max_lead > (10 - i) / 2 or team2_max_lead > (10 - i) / 2:
				print(i)
				break
		if i == 10:
			print(10)


for _ in range(int(input())):
	s = input()
	shot1 = 0
	shot2 = 0
	f1 = s[::2]
	f2 = s[1::2]
	f11 = f1[:3]
	f21 = f2[:3]
	if '0' not in f11 and '1' not in f21 or ('1' not in f11 and '0' not in f21):
		print(6)
		continue
	f11 = f1[:4]
	f21 = f2[:3]
	if f11.count('1') + f11.count('?') > f21.count('1') + 2 or f21.count('1') + f21.count('?') > f11.count('1') + 1:
		print(7)
		continue
	f11 = f1[:4]
	f21 = f2[:4]
	if f11.count('1') + f11.count('?') > f21.count('1') + 1 or f21.count('1') + f21.count('?') > f11.count('1') + 1:
		print(8)
		continue
	f11 = f1[:5]
	f21 = f2[:4]
	if f11.count('1') + f11.count('?') > f21.count('1') + 1 or f21.count('1') + f21.count('?') > f11.count('1'):
		print(9)
		continue
	print(10)


t = int(input())
for _ in range(t):
	s = input()
	(c11, c10, c21, c20) = (0, 0, 0, 0)
	(v1, v2) = (0, 0)
	(ostatok1, ostatok2) = (10, 10)
	counter = 0
	for i in range(len(s)):
		if i % 2 == 0:
			ostatok1 = (10 - i - 1) // 2
			if s[i] == '1':
				c11 += 1
			elif s[i] == '0':
				c10 += 1
			else:
				v1 += 1
		else:
			ostatok2 = (10 - i - 1) // 2
			if s[i] == '1':
				c21 += 1
			elif s[i] == '0':
				c20 += 1
			else:
				v2 += 1
		if c11 + v1 > c21 + v2 + ostatok2:
			print(i + 1)
			break
		elif c11 + v1 + ostatok1 < c21 + v2:
			print(i + 1)
			break
		elif c11 + ostatok1 < c21 + v2:
			print(i + 1)
			break
		elif c11 + v1 > c21 + ostatok2:
			print(i + 1)
			break
		else:
			counter += 1
	if counter == 10:
		print(10)


for _ in range(int(input())):
	s = input()
	s = list(s)
	o = []
	e = []
	for i in s:
		o.append(ord(i) - ord('0'))
		e.append(ord(i) - ord('0'))
	for i in range(10):
		if s[i] == '?':
			if i % 2 == 0:
				o[i] = 1
				e[i] = 0
			else:
				o[i] = 0
				e[i] = 1
	(o1, o2, e1, e2) = (0, 0, 0, 0)
	ans = 0
	for i in range(10):
		ans = i + 1
		if i % 2 == 0:
			o1 += o[i]
			e1 += e[i]
			if o1 > o2 + (10 - i) // 2:
				break
			if o2 > o1 + (9 - i) // 2:
				break
			if e1 > e2 + (10 - i) // 2:
				break
			if e2 > e1 + (9 - i) // 2:
				break
		else:
			o2 += o[i]
			e2 += e[i]
			if o1 > o2 + (10 - i) // 2:
				break
			if o2 > o1 + (10 - i) // 2:
				break
			if e1 > e2 + (10 - i) // 2:
				break
			if e2 > e1 + (10 - i) // 2:
				break
	print(ans)


import heapq
import sys
from math import *
import threading
from heapq import *
from itertools import count
from pprint import pprint
from collections import defaultdict
from heapq import heapify, heappop, heappush
mod = 10 ** 9 + 7
inf = 10 ** 15
decision = ['NO', 'YES']
yes = 'YES'
no = 'NO'
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

	def npr(self, n, k):
		if k < 0 or n < k:
			return 0
		f = self.factorial
		return f.calc(n) * f.invFactorial(n - k) % self.MOD

def lower_bound(li, num):
	answer = len(li)
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = len(li)
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			start = middle + 1
		else:
			answer = middle
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val):
	ans = -1
	lb = 0
	ub = len(li) - 1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def SieveOfEratosthenes(n):
	prime = [{1, i} for i in range(n + 1)]
	p = 2
	while p <= n:
		for i in range(p * 2, n + 1, p):
			prime[i].add(p)
		p += 1
	return prime

def primefactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n //= 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n //= i
	if n > 2:
		factors.append(n)
	return factors

def prod(li):
	ans = 1
	for i in li:
		ans *= i
	return ans

def sumk(a, b):
	print('called for', a, b)
	ans = a * (a + 1) // 2
	ans -= b * (b + 1) // 2
	return ans

def sumi(n):
	ans = 0
	if len(n) > 1:
		for x in n:
			ans += int(x)
		return ans
	else:
		return int(n)

def checkwin(x, a):
	if a[0][0] == a[1][1] == a[2][2] == x:
		return 1
	if a[0][2] == a[1][1] == a[2][0] == x:
		return 1
	if len(set(a[0])) == 1 and a[0][0] == x or (len(set(a[1])) == 1 and a[1][0] == x) or (len(set(a[2])) == 1 and a[2][0] == x):
		return 1
	if len(set(a[0][:])) == 1 and a[0][0] == x or (len(set(a[1][:])) == 1 and a[0][1] == x) or (len(set(a[2][:])) == 1 and a[0][0] == x):
		return 1
	return 0
inf = 10 ** 9 + 7

def main():
	karmanya = int(input())
	while karmanya != 0:
		karmanya -= 1
		s = list(input())
		(onehas, twohas) = (5, 5)
		(onescore, twoscore) = (0, 0)
		(ans1, ans2) = (10, 10)
		for i in range(10):
			if i & 1 == 0:
				onehas -= 1
				if s[i] != '0':
					onescore += 1
			else:
				twohas -= 1
				if s[i] == '1':
					twoscore += 1
			if onescore > twohas + twoscore or twoscore > onehas + onescore:
				ans1 = i + 1
				break
		(onehas, twohas) = (5, 5)
		(onescore, twoscore) = (0, 0)
		for i in range(10):
			if i & 1 == 0:
				onehas -= 1
				if s[i] == '1':
					onescore += 1
			else:
				twohas -= 1
				if s[i] != '0':
					twoscore += 1
			if onescore > twohas + twoscore or twoscore > onehas + onescore:
				ans2 = i + 1
				break
		print(min(ans1, ans2))
main()


n = int(input())
for i in range(n):
	s = input()
	a = 0
	b = 0
	a1 = 0
	b1 = 0
	for i in range(len(s)):
		if i % 2 == 0 and (s[i] == '?' or s[i] == '1'):
			a += 1
		if i % 2 == 0 and s[i] == '1':
			a1 += 1
		if i % 2 != 0 and (s[i] == '?' or s[i] == '1'):
			b += 1
		if i % 2 != 0 and s[i] == '1':
			b1 += 1
		if a - b1 > 5 - (i + 1) // 2 or b - a1 > 5 - (i + 2) // 2:
			print(i + 1)
			break
	else:
		print(10)


def test(a, b):
	try:
		pass
	except AssertionError:
		print(a, b)
		raise

def dfs(S) -> int:
	(A, B) = (S[::2], S[1::2])
	(a_lo, a_hi, b_lo, b_hi) = (0, 0, 0, 0)
	for (i, (a, b)) in enumerate(zip(A, B)):
		if a == '1':
			a_lo += 1
			a_hi += 1
		if a == '?':
			a_hi += 1
		if a_hi > b_lo + 5 - i or b_hi > a_lo + 4 - i:
			return i * 2 + 1
		if b == '1':
			b_lo += 1
			b_hi += 1
		if b == '?':
			b_hi += 1
		if a_hi > b_lo + 4 - i or b_hi > a_lo + 4 - i:
			return (i + 1) * 2
	return 10
test(dfs('??????????'), 6)
test(dfs('1?0???1001'), 7)
test(dfs('0100000000'), 9)
test(dfs('1010101010'), 6)
test(dfs('1111111111'), 10)
for _ in range(int(input())):
	A = input()
	print(dfs(A))


import time
import os, sys
from io import BytesIO, IOBase
from types import GeneratorType
from bisect import bisect_left, bisect_right
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string, heapq as h
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def getInt():
	return int(input())

def getStrs():
	return input().split()

def getInts():
	return list(map(int, input().split()))

def getStr():
	return input()

def listStr():
	return list(input())

def getMat(n):
	return [getInts() for _ in range(n)]

def getBin():
	return list(map(int, list(input())))

def isInt(s):
	return '0' <= s[0] <= '9'

def ceil_(a, b):
	return (a + b - 1) // b
MOD = 10 ** 9 + 7

def solve():
	S = listStr()
	ans = 10
	t1 = t2 = 0
	rem1 = rem2 = 5
	for i in range(10):
		if i % 2 == 0:
			if S[i] == '1' or S[i] == '?':
				t1 += 1
			rem1 -= 1
		else:
			if S[i] == '1':
				t2 += 1
			rem2 -= 1
		if t1 > t2 + rem2:
			ans = min(ans, i + 1)
		if t2 > t1 + rem1:
			ans = min(ans, i + 1)
	t1 = t2 = 0
	rem1 = rem2 = 5
	for i in range(10):
		if i % 2 == 0:
			if S[i] == '1':
				t1 += 1
			rem1 -= 1
		else:
			if S[i] == '1' or S[i] == '?':
				t2 += 1
			rem2 -= 1
		if t1 > t2 + rem2:
			ans = min(ans, i + 1)
		if t2 > t1 + rem1:
			ans = min(ans, i + 1)
	return ans
for _ in range(getInt()):
	print(solve())


def solve(s):
	s1 = s.copy()
	s2 = s.copy()
	first = 0
	second = 0
	(ans1, ans2) = (-1, -1)
	(p1, p2) = (5, 5)
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '?':
				s1[i] = '1'
				s2[i] = '0'
		elif s[i] == '?':
			s1[i] = '0'
			s2[i] = '1'
	for i in range(10):
		if i % 2 == 0:
			p1 -= 1
			if s1[i] == '1':
				first += 1
		else:
			p2 -= 1
			if s1[i] == '1':
				second += 1
		if p2 + second < first:
			ans1 = i + 1
			break
		if p1 + first < second:
			ans1 = i + 1
			break
	first = 0
	second = 0
	(p1, p2) = (5, 5)
	for i in range(10):
		if i % 2 == 0:
			p1 -= 1
			if s2[i] == '1':
				first += 1
		else:
			p2 -= 1
			if s2[i] == '1':
				second += 1
		if p2 + second < first:
			ans2 = i + 1
			break
		if p1 + first < second:
			ans2 = i + 1
			break
	if ans1 == -1:
		ans1 = 10
	if ans2 == -1:
		ans2 = 10
	return min(ans1, ans2)
for _ in range(int(input())):
	s = list(input())
	print(solve(s))


import math
t = int(input())
for i in range(t):
	s = list(input())
	(t1, t2) = (0, 0)
	(c1, c2) = (5, 5)
	(q1, q2) = (0, 0)
	for j in range(10):
		if j % 2 == 0:
			if s[j] == '1':
				t1 += 1
			if s[j] == '?':
				q1 += 1
			c1 -= 1
		else:
			if s[j] == '1':
				t2 += 1
			if s[j] == '?':
				q2 += 1
			c2 -= 1
		if j >= 5:
			if t1 + q1 - t2 > c2:
				break
			elif t2 + q2 - t1 > c1:
				break
	print(j + 1)


import math
t = int(input())
for p in range(t):
	s = str(input())
	n = len(s)
	count1 = 0
	count2 = 0
	c1 = 0
	c2 = 0
	f = 0
	if s.count('0') == 10 or s.count('1') == 10:
		print(10)
	else:
		for i in range(0, n):
			if i % 2 == 0:
				if s[i] == '1' or s[i] == '?':
					count1 += 1
				if s[i] == '1':
					c1 += 1
			else:
				if s[i] == '1' or s[i] == '?':
					count2 += 1
				if s[i] == '1':
					c2 += 1
			if i % 2 == 0:
				if c2 + math.ceil((n - i - 1) / 2) < count1:
					print(i + 1)
					f = 1
					break
				elif c1 + (n - i - 1) // 2 < count2:
					print(i + 1)
					f = 1
					break
			elif c2 + math.floor((n - i - 1) / 2) < count1:
				print(i + 1)
				f = 1
				break
			elif c1 + math.ceil((n - i - 1) // 2) < count2:
				print(i + 1)
				f = 1
				break
		if f == 0:
			print(10)


for _ in range(int(input())):
	s = input()
	a = 0
	b = 0
	aa = 0
	bb = 0
	ans = 10
	for i in range(10):
		if i % 2:
			if s[i] == '1':
				b += 1
			elif s[i] == '?':
				bb += 1
			c = (10 - i - 1) // 2
			if (10 - i - 1) % 2:
				c += 1
			z = (10 - i - 1) // 2
			if b + bb > a + c:
				ans = i + 1
				break
			if a + aa > b + z:
				ans = i + 1
				break
		else:
			if s[i] == '1':
				a += 1
			elif s[i] == '?':
				aa += 1
			c = (10 - i - 1) // 2
			if (10 - i - 1) % 2:
				c += 1
			z = (10 - i - 1) // 2
			if aa + a > b + c:
				ans = i + 1
				break
			if bb + b > a + z:
				ans = i + 1
				break
	print(ans)


def solve():
	s = input()
	n = len(s)
	arr1 = []
	arr2 = []
	for i in range(n):
		if s[i] == '?':
			if i % 2 == 0:
				arr1.append(1)
			else:
				arr1.append(0)
		else:
			arr1.append(int(s[i]))
		if s[i] == '?':
			if i % 2 == 1:
				arr2.append(1)
			else:
				arr2.append(0)
		else:
			arr2.append(int(s[i]))
	(a1, a2) = [n, n]
	(c1, c2) = [0, 0]
	for i in range(n):
		if i % 2 == 0:
			c1 += arr1[i]
		else:
			c2 += arr1[i]
		rem = n - i - 1
		if c1 - c2 > (rem + 1) // 2:
			a1 = min(a1, i + 1)
		if c2 - c1 > rem // 2:
			a1 = min(a1, i + 1)
	(c1, c2) = [0, 0]
	for i in range(n):
		if i % 2 == 0:
			c1 += arr2[i]
		else:
			c2 += arr2[i]
		rem = n - i - 1
		if c1 - c2 > (rem + 1) // 2:
			a2 = min(a2, i + 1)
		if c2 - c1 > rem // 2:
			a2 = min(a2, i + 1)
	print(min(a1, a2))

def main():
	for case in range(int(input())):
		solve()
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def p(s):
	ap = 0
	az = 5
	bp = 0
	bz = 5
	for i in range(10):
		if s[i] == '1':
			if i % 2 == 0:
				ap += 1
			else:
				bp += 1
		if i % 2 == 0:
			az -= 1
		else:
			bz -= 1
		if ap > bp + bz or ap + az < bp:
			return i + 1
	else:
		return 10
T = int(input())
for _ in range(T):
	S = input()
	s1 = ''
	s2 = ''
	for i in range(10):
		if S[i] == '?':
			if i % 2 == 0:
				s1 += '1'
				s2 += '0'
			else:
				s1 += '0'
				s2 += '1'
		else:
			s1 += S[i]
			s2 += S[i]
	print(min(p(s1), p(s2)))


from sys import stdin
_input = stdin.readline
(_str, _int, _enumerate, _range) = (str, int, enumerate, range)

def solution():
	for _ in _range(_int(_input())):
		s = _input().rstrip('\n')
		arr = [[0, 0, 0], [0, 0, 0]]
		for (i, v) in _enumerate(s):
			if v == '0':
				arr[i % 2][0] += 1
			elif v == '1':
				arr[i % 2][1] += 1
			else:
				arr[i % 2][2] += 1
			if arr[0][0] + arr[0][2] + arr[1][1] + arr[1][2] > 5 or arr[1][0] + arr[0][2] + arr[0][1] + arr[1][2] > 5:
				print(i + 1)
				break
		else:
			print(10)
solution()


for _ in range(int(input())):
	s = input()
	ans = 9
	(ans1, ans2) = (0, 0)
	for i in range(10):
		if i % 2 == 0:
			if s[i] != '0':
				ans1 += 1
		elif s[i] == '1':
			ans2 += 1
		if ans1 > ans2 + (10 - i) // 2:
			ans = min(ans, i)
		if ans2 > ans1 + (9 - i) // 2:
			ans = min(ans, i)
	(ans1, ans2) = (0, 0)
	for i in range(10):
		if i % 2 == 1:
			if s[i] != '0':
				ans2 += 1
		elif s[i] == '1':
			ans1 += 1
		if ans1 > ans2 + (10 - i) // 2:
			ans = min(ans, i)
		if ans2 > ans1 + (9 - i) // 2:
			ans = min(ans, i)
	print(ans + 1)


t = int(input())
for z in range(t):
	s = input()
	t1 = 0
	t2 = 0
	q1 = 0
	q2 = 0
	ans1 = 10
	ans2 = 10
	c1 = 0
	c2 = 0
	for i in range(0, 10):
		if i % 2 == 0:
			c1 += 1
			if s[i] == '1':
				t1 += 1
			if s[i] == '?':
				q1 += 1
		else:
			c2 += 1
			if s[i] == '1':
				t2 += 1
		if t1 + q1 > 5 + t2 - c2:
			ans1 = i + 1
			break
	c1 = 0
	c2 = 0
	t1 = 0
	t2 = 0
	for i in range(0, 10):
		if i % 2 == 0:
			c1 += 1
			if s[i] == '1':
				t1 += 1
		else:
			c2 += 1
			if s[i] == '1':
				t2 += 1
			if s[i] == '?':
				q2 += 1
		if t2 + q2 > 5 + t1 - c1:
			ans2 = i + 1
			break
	print(min(ans1, ans2))


def solve(s):
	a = 0
	b = 0
	ag = bg = 5
	g = 0
	at = bt = 0
	while g < 10 and (a <= b + bg and b <= a + ag and (at <= bt + bg) and (bt <= at + ag)):
		cg = s[g]
		if g % 2 == 0:
			ag -= 1
		else:
			bg -= 1
		if cg == '1' and g % 2 == 0:
			a += 1
			at += 1
		elif cg == '1' and g % 2 != 0:
			b += 1
			bt += 1
		elif cg == '?' and g % 2 == 0:
			a += 1
			at += 0
		elif cg == '?' and g % 2 != 0:
			bt += 1
			b += 0
		g += 1
	return g
t = int(input())
l = []
for _i in range(t):
	st = input()
	t = solve(st)
	l.append(t)
for i in l:
	print(i)


def fun(s, i):
	if i == 10:
		c = [0, 0]
		kl = [5, 5]
		for i in range(10):
			team = i & 1
			c[team] += ord(s[i]) - ord('0')
			kl[team] -= 1
			if c[0] > c[1] + kl[1] or c[1] > c[0] + kl[0]:
				return i + 1
		return 10
	if s[i] != '?':
		return fun(s, i + 1)
	s[i] = '0'
	p1 = fun(s, i + 1)
	s[i] = '1'
	p2 = fun(s, i + 1)
	s[i] = '?'
	return min(p1, p2)
for _ in range(int(input())):
	s = [i for i in input()]
	print(fun(s, 0))


def solve3(s):
	n = 10
	A = 0
	B = 0
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '1' or s[i] == '?':
				A += 1
			x = abs(A - B)
			if A >= B:
				B_kicks = 5 - (i + 1) // 2
				if x > B_kicks:
					return i + 1
			elif B > A:
				A_kicks = 5 - (i + 1) // 2 - 1
				if x > A_kicks:
					return i + 1
		elif i % 2 == 1:
			if s[i] == '1' or s[i] == '?':
				B += 1
			x = abs(A - B)
			if A >= B:
				B_kicks = 5 - (i + 1) // 2
				if x > B_kicks:
					return i + 1
			elif B > A:
				A_kicks = 5 - (i + 1) // 2
				if x > A_kicks:
					return i + 1
	return 10

def solve2(s):
	n = 10
	A = 0
	B = 0
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '1':
				A += 1
			x = abs(A - B)
			if A >= B:
				B_kicks = 5 - (i + 1) // 2
				if x > B_kicks:
					return i + 1
			elif B > A:
				A_kicks = 5 - (i + 1) // 2 - 1
				if x > A_kicks:
					return i + 1
		elif i % 2 == 1:
			if s[i] == '1' or s[i] == '?':
				B += 1
			x = abs(A - B)
			if A >= B:
				B_kicks = 5 - (i + 1) // 2
				if x > B_kicks:
					return i + 1
			elif B > A:
				A_kicks = 5 - (i + 1) // 2
				if x > A_kicks:
					return i + 1
	return 10

def solve(s):
	n = 10
	A = 0
	B = 0
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '1' or s[i] == '?':
				A += 1
			x = abs(A - B)
			if A >= B:
				B_kicks = 5 - (i + 1) // 2
				if x > B_kicks:
					return i + 1
			elif B > A:
				A_kicks = 5 - (i + 1) // 2 - 1
				if x > A_kicks:
					return i + 1
		elif i % 2 == 1:
			if s[i] == '1':
				B += 1
			x = abs(A - B)
			if A >= B:
				B_kicks = 5 - (i + 1) // 2
				if x > B_kicks:
					return i + 1
			elif B > A:
				A_kicks = 5 - (i + 1) // 2
				if x > A_kicks:
					return i + 1
	return 10
for t in range(int(input())):
	s = input()
	ans1 = solve(s)
	ans2 = solve2(s)
	ans3 = solve3(s)
	print(min(ans1, ans2, ans3))


t = int(input())
pred_list = []
for i in range(t):
	pred_list.append(input())
for pred in pred_list:
	a_win = 0
	b_win = 0
	a_lose = 0
	b_lose = 0
	remain_a = 5
	remain_b = 5
	for (i, chance) in enumerate(pred):
		if i % 2 == 0:
			if chance == '1' or chance == '?':
				a_win += 1
		else:
			remain_b -= 1
			if chance == '1':
				b_lose += 1
		if a_win - b_lose > remain_b:
			print(i + 1)
			break
		if i % 2 == 0:
			remain_a -= 1
			if chance == '1':
				a_lose += 1
		elif chance == '1' or chance == '?':
			b_win += 1
		if b_win - a_lose > remain_a:
			print(i + 1)
			break
	else:
		print(10)


for _ in range(int(input())):
	n = 5
	s = input()
	a = []
	b = []
	a1 = 0
	b1 = 0
	c = 0
	c1 = 0
	pp = list(s)
	gg = list(s)
	if '?' in s:
		for i in range(10):
			if i % 2 == 0 and pp[i] == '?':
				pp[i] = '1'
			elif i % 2 != 0 and pp[i] == '?':
				pp[i] = '0'
		for i in range(10):
			if i % 2 != 0 and gg[i] == '?':
				gg[i] = '1'
			elif i % 2 == 0 and gg[i] == '?':
				gg[i] = '0'
	pp = ''.join(pp)
	gg = ''.join(gg)
	for i in range(2 * n):
		if i % 2 == 0:
			a.append(pp[i])
		else:
			b.append(pp[i])
	for i in range(n):
		c += 1
		if a[i] == '1':
			a1 += 1
		if n - i + b1 < a1 or n - i - 1 + a1 < b1:
			break
		c += 1
		if b[i] == '1':
			b1 += 1
		if n - i - 1 + a1 < b1 or b1 + (n - i - 1) < a1:
			break
	a = []
	b = []
	a1 = 0
	b1 = 0
	c1 = 0
	for i in range(2 * n):
		if i % 2 == 0:
			a.append(gg[i])
		else:
			b.append(gg[i])
	for i in range(n):
		c1 += 1
		if a[i] == '1':
			a1 += 1
		if n - i + b1 < a1 or n - i - 1 + a1 < b1:
			break
		c1 += 1
		if b[i] == '1':
			b1 += 1
		if n - i - 1 + a1 < b1 or b1 + (n - i - 1) < a1:
			break
	print(min(c, c1))


for _ in range(int(input())):
	s = input()
	slen = len(s)
	evm = []
	for i in range(slen):
		if i % 2 == 0:
			if s[i] == '?':
				evm.append('0')
				continue
		elif s[i] == '?':
			evm.append('1')
			continue
		evm.append(s[i])
	evmn = ''.join(evm)
	evm = []
	for i in range(slen):
		if i % 2 == 0:
			if s[i] == '?':
				evm.append('1')
				continue
		elif s[i] == '?':
			evm.append('0')
			continue
		evm.append(s[i])
	evmx = ''.join(evm)
	mn = 10
	ev = 0
	od = 0
	for i in range(10, 0, -1):
		evenleft = i // 2
		oddleft = (i + 1) // 2
		if i % 2 == 0:
			if evmn[10 - i] == '1':
				ev += 1
			if od + oddleft < ev:
				mn = min(mn, 10 - i + 1)
			evenleft -= 1
			if ev + evenleft < od:
				mn = min(mn, 10 - i + 1)
		else:
			if evmn[10 - i] == '1':
				od += 1
			if ev + evenleft < od:
				mn = min(mn, 10 - i + 1)
			oddleft -= 1
			if od + oddleft < ev:
				mn = min(mn, 10 - i + 1)
	ev = 0
	od = 0
	for i in range(10, 0, -1):
		evenleft = i // 2
		oddleft = (i + 1) // 2
		if i % 2 == 0:
			if evmx[10 - i] == '1':
				ev += 1
			if od + oddleft < ev:
				mn = min(mn, 10 - i + 1)
			evenleft -= 1
			if ev + evenleft < od:
				mn = min(mn, 10 - i + 1)
		else:
			if evmx[10 - i] == '1':
				od += 1
			if ev + evenleft < od:
				mn = min(mn, 10 - i + 1)
			oddleft -= 1
			if od + oddleft < ev:
				mn = min(mn, 10 - i + 1)
	print(mn)


def f1(s):
	res = ''
	for i in range(len(s)):
		if s[i] == '?':
			if i % 2 == 0:
				res += '1'
			else:
				res += '0'
		else:
			res += s[i]
	return res

def f2(s):
	res = ''
	for i in range(len(s)):
		if s[i] == '?':
			if i % 2 == 0:
				res += '0'
			else:
				res += '1'
		else:
			res += s[i]
	return res
for _ in range(int(input())):
	s = input()
	s1 = f1(s)
	s2 = f2(s)
	mn = 10
	(c1, c2) = (0, 0)
	(n1, n2) = (5, 5)
	for i in range(len(s)):
		if i % 2 == 0:
			n1 -= 1
			if s1[i] == '1':
				c1 += 1
			if n2 + c2 < c1 or n1 + c1 < c2:
				mn = min(i + 1, mn)
				break
		if i % 2 == 1:
			n2 -= 1
			if s1[i] == '1':
				c2 += 1
			if n1 + c1 < c2 or n2 + c2 < c1:
				mn = min(i + 1, mn)
				break
	(c1, c2) = (0, 0)
	(n1, n2) = (5, 5)
	for i in range(len(s)):
		if i % 2 == 0:
			n1 -= 1
			if s2[i] == '1':
				c1 += 1
			if n2 + c2 < c1 or c1 + n1 < c2:
				mn = min(i + 1, mn)
				break
		if i % 2 == 1:
			n2 -= 1
			if s2[i] == '1':
				c2 += 1
			if n1 + c1 < c2 or n2 + c2 < c1:
				mn = min(i + 1, mn)
				break
	print(mn)


import sys
input = sys.stdin.readline

def S():
	return input()

def I():
	return int(S())

def M():
	return map(int, S().split())

def L():
	return list(M())
t = int(input())
for p in range(t):
	l = list(S())
	(first_score, second_score, neutal) = (0, 0, 0)
	chances1 = 5
	chances2 = 5
	ans = 10
	for i in range(10):
		if i % 2 == 0:
			if l[i] == '?' or l[i] == '1':
				first_score += 1
			chances1 -= 1
		else:
			if l[i] == '1':
				second_score += 1
			chances2 -= 1
		if first_score > chances2 + second_score:
			ans = i + 1
			break
		if second_score > chances1 + first_score:
			ans = i + 1
			break
	(first_score, second_score, neutal) = (0, 0, 0)
	chances1 = 5
	chances2 = 5
	ans2 = 10
	for i in range(10):
		if i % 2 == 1:
			if l[i] == '?' or l[i] == '1':
				second_score += 1
			chances2 -= 1
		else:
			if l[i] == '1':
				first_score += 1
			chances1 -= 1
		if first_score > chances2 + second_score:
			ans2 = i + 1
			break
		if second_score > chances1 + first_score:
			ans2 = i + 1
			break
	print(min(ans, ans2))


T = int(input().strip())

def calculateScore(s1, s2):
	sc1 = s1[0] + s1[1] + s1[2]
	sc2 = s2[0] + s2[1] + s2[2]
	i1 = 3
	i2 = 3
	if abs(sc1 - sc2) == 3:
		return 6
	sc1 += s1[3]
	if sc1 - sc2 == 3 or sc2 - sc1 == 2:
		return 7
	sc2 += s2[3]
	if abs(sc1 - sc2) == 2:
		return 8
	sc1 += s1[4]
	if sc1 - sc2 == 2 or sc2 - sc1 == 1:
		return 9
	return 10
for t in range(T):
	S = str(input().strip())
	s1 = []
	s2 = []
	for i in range(0, 10, 2):
		if S[i] == '?' or S[i] == '1':
			s1.append(1)
		else:
			s1.append(0)
	for i in range(1, 10, 2):
		if S[i] == '?' or S[i] == '0':
			s2.append(0)
		else:
			s2.append(1)
	n1 = calculateScore(s1, s2)
	s1 = []
	s2 = []
	for i in range(0, 10, 2):
		if S[i] == '?' or S[i] == '0':
			s1.append(0)
		else:
			s1.append(1)
	for i in range(1, 10, 2):
		if S[i] == '?' or S[i] == '1':
			s2.append(1)
		else:
			s2.append(0)
	n2 = calculateScore(s1, s2)
	print(min(n1, n2))


q = int(input())
while q:
	q -= 1
	s = input()
	n = len(s)
	oddpre = [[0, 0] for x in range(n)]
	evenpre = [[0, 0] for x in range(n)]
	if s[0] == '1':
		evenpre[0] = [1, 1]
	elif s[0] == '0':
		evenpre[0] = [0, 0]
	else:
		evenpre[0] = [1, 0]
	for i in range(1, n):
		if i % 2 == 0:
			oddpre[i] = oddpre[i - 1].copy()
			if s[i] == '1':
				evenpre[i] = [evenpre[i - 1][0] + 1, evenpre[i - 1][1] + 1]
			elif s[i] == '0':
				evenpre[i] = [evenpre[i - 1][0], evenpre[i - 1][1]]
			else:
				evenpre[i] = [evenpre[i - 1][0] + 1, evenpre[i - 1][1]]
		else:
			evenpre[i] = evenpre[i - 1].copy()
			if s[i] == '1':
				oddpre[i] = [oddpre[i - 1][0] + 1, oddpre[i - 1][1] + 1]
			elif s[i] == '0':
				oddpre[i] = [oddpre[i - 1][0], oddpre[i - 1][1]]
			else:
				oddpre[i] = [oddpre[i - 1][0] + 1, oddpre[i - 1][1]]
	oddsufix = [[0, 0] for x in range(n)]
	evensufix = [[0, 0] for x in range(n)]
	oddsufix[-1] = [1, 1]
	for i in reversed(range(len(s) - 1)):
		if i % 2 == 0:
			oddsufix[i] = oddsufix[i + 1].copy()
			evensufix[i] = [evensufix[i + 1][0] + 1, evensufix[i + 1][1] + 1]
		else:
			evensufix[i] = evensufix[i + 1].copy()
			oddsufix[i] = [oddsufix[i + 1][0] + 1, oddsufix[i + 1][1] + 1]
	for i in range(len(s) - 1):
		if oddpre[i][0] - evenpre[i][1] > evensufix[i + 1][0]:
			print(i + 1)
			break
		elif evenpre[i][0] - oddpre[i][1] > oddsufix[i + 1][0]:
			print(i + 1)
			break
	else:
		print(10)


t = int(input())
for i in range(t):
	s = input()
	p1 = 0
	p2 = 0
	r1 = 5
	r2 = 5
	ans1 = 0
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '?' or s[i] == '1':
				p1 += 1
				r1 -= 1
			else:
				r1 -= 1
		elif s[i] == '1':
			p2 += 1
			r2 -= 1
		else:
			r2 -= 1
		if p1 > r2 + p2:
			ans1 = i + 1
			break
	p1 = 0
	p2 = 0
	r1 = 5
	r2 = 5
	ans2 = 0
	for i in range(10):
		if i % 2 != 0:
			if s[i] == '?' or s[i] == '1':
				p2 += 1
				r2 -= 1
			else:
				r2 -= 1
		elif s[i] == '1':
			p1 += 1
			r1 -= 1
		else:
			r1 -= 1
		if p2 > r1 + p1:
			ans2 = i + 1
			break
	if ans1 > 0 and ans2 > 0:
		print(min(ans1, ans2))
	elif ans1 > 0:
		print(ans1)
	elif ans2 > 0:
		print(ans2)
	else:
		print(10)


from sys import stdin
for _ in range(int(stdin.readline())):
	s = stdin.readline().strip()
	max_odd = 0
	min_even = 0
	max_even = 0
	min_odd = 0
	res = 10
	even_remaining = 5
	odd_remaining = 5
	for i in range(10):
		if s[i] == '1':
			if i % 2 == 0:
				max_even += 1
				min_even += 1
			else:
				max_odd += 1
				min_odd += 1
		elif s[i] == '?':
			if i % 2 == 0:
				max_even += 1
			else:
				max_odd += 1
		if i % 2 == 0:
			even_remaining -= 1
		else:
			odd_remaining -= 1
		if max_even - min_odd > odd_remaining or max_odd - min_even > even_remaining:
			res = i + 1
			break
	print(res)


def fun(r, rr):
	ct = 0
	cm = 0
	i = 0
	m = 0
	vb = 10
	ii = 0
	for t in range(10):
		if t % 2 == 0:
			ii += 1
			q = a[t]
			if a[t] == '?':
				q = r
			cm += int(q)
			m += 1
			nb = 5 - ii + cm
			if cm > vb or ct > nb:
				break
		else:
			i += 1
			q = a[t]
			if a[t] == '?':
				q = rr
			ct += int(q)
			vb = 5 - i + ct
			m += 1
			if vb < cm or ct > nb:
				break
	return m
for _ in range(int(input())):
	a = input()
	e = fun(1, 0)
	ee = fun(0, 1)
	print(min(e, ee))


def fuc(s):
	ans = 9
	cnt0 = 0
	cnt1 = 0
	for i in range(0, 10):
		if i % 2 == 0:
			cnt0 += s[i] != '0'
		else:
			cnt1 += s[i] == '1'
		if cnt0 > cnt1 + (10 - i) / 2:
			ans = min(ans, i)
		if cnt1 > cnt0 + (9 - i) / 2:
			ans = min(ans, i)
	cnt0 = 0
	cnt1 = 0
	for i in range(0, 10):
		if i % 2 == 0:
			cnt0 += s[i] == '1'
		else:
			cnt1 += s[i] != '0'
		if cnt0 > cnt1 + (10 - i) / 2:
			ans = min(ans, i)
		if cnt1 > cnt0 + (9 - i) / 2:
			ans = min(ans, i)
	print(ans + 1)
t = int(input(' '))
for i in range(0, t):
	s = input(' ')
	fuc(s)


import sys, os
from math import *
from bisect import *
from heapq import *
from collections import *
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		s = input()
		out = []

		def all(i, cur=''):
			if i == 10:
				out.append(cur)
				return
			if s[i] == '1':
				all(i + 1, cur + '1')
			elif s[i] == '0':
				all(i + 1, cur + '0')
			else:
				all(i + 1, cur + '1')
				all(i + 1, cur + '0')

		def check(st):
			(a, b) = (0, 0)
			i = 0
			while i < 10:
				if st[i] == '1':
					if i % 2:
						b += 1
					else:
						a += 1
				if a > b and a > b + 5 - (i + 1) // 2:
					return i + 1
				if b > a and b > a + 4 - i // 2:
					return i + 1
				i += 1
			return 10
		all(0)
		ans = check(out[0])
		for j in out:
			ans = min(ans, check(j))
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def MI():
	return map(int, input().split())

def outP(var):
	sys.stdout.write(str(var) + '\n')
MOD = 10 ** 9 + 7
mod = 998244353
main()


import sys, random, bisect
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush
from math import gcd
mod = int(1000000000.0 + 7)
inf = int(1e+20)
input = lambda : sys.stdin.readline().rstrip()
mi = lambda : map(int, input().split())
li = lambda : list(mi())
ii = lambda : int(input())
py = lambda : print('YES')
pn = lambda : print('NO')
t = ii()

def check(s, f):
	s = list(s)
	for (i, c) in enumerate(s):
		if c == '?':
			s[i] = 1 if i % 2 == f % 2 else 0
	a = [int(s[i]) for i in range(0, 10, 2)][::-1]
	b = [int(s[i]) for i in range(1, 10, 2)][::-1]
	ca = cb = 0
	for i in range(1, 11):
		if i % 2 == 1:
			ca += a.pop()
		else:
			cb += b.pop()
		if ca > cb + len(b) or cb > ca + len(a):
			return i
	return 10
for _ in range(t):
	s = input()
	print(min(check(s, 0), check(s, 1)))


import math
t = int(input())
for _ in range(t):
	s = list(input())
	counta = 0
	countb = 0
	lefta = 5
	leftb = 5
	ans = 10
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '1' or s[i] == '?':
				counta += 1
			lefta -= 1
		else:
			if s[i] == '1':
				countb += 1
			leftb -= 1
		if counta - countb > leftb:
			ans = min(ans, i + 1)
	counta = 0
	countb = 0
	lefta = 5
	leftb = 5
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '1':
				counta += 1
			lefta -= 1
		else:
			if s[i] == '1' or s[i] == '?':
				countb += 1
			leftb -= 1
		if countb - counta > lefta:
			ans = min(ans, i + 1)
	print(ans)


def solve_test(s):
	variants = set()
	new_s = ''.join((c if c != '?' else '1' if i % 2 == 1 else '0' for (i, c) in enumerate(s, 1)))
	variants.add(new_s)
	new_s = ''.join((c if c != '?' else '0' if i % 2 == 1 else '1' for (i, c) in enumerate(s, 1)))
	variants.add(new_s)
	result = 10
	for s in variants:
		scores = [0, 0]
		left = [5, 5]
		for (i, c) in enumerate(s):
			pl = i % 2
			left[pl] -= 1
			if c == '1':
				scores[pl] += 1
			if scores[0] > scores[1] + left[1] or scores[1] > scores[0] + left[0]:
				result = min(result, i + 1)
				break
	return result

def main():
	t = int(input())
	for _ in range(t):
		s = input()
		print(solve_test(s))
main()


def fuck1(a):
	win = 0
	last = 5
	for i in range(10):
		if i % 2 == 0:
			win += a[i]
		else:
			win -= a[i]
			last -= 1
		if last < win:
			return i + 1
	return 10

def fuck2(a):
	win = 0
	last = 5
	for i in range(10):
		if i % 2 == 1:
			win += a[i]
		else:
			win -= a[i]
			last -= 1
		if last < win:
			return i + 1
	return 10

def sex(s):
	t1 = [0] * 10
	t2 = [0] * 10
	for i in range(10):
		if s[i] == '?':
			if i % 2 == 0:
				t1[i] = 1
			else:
				t2[i] = 1
		else:
			t1[i] = int(s[i])
			t2[i] = int(s[i])
	min_1 = fuck1(t1)
	min_2 = fuck2(t2)
	return min(min_1, min_2)
t = int(input())
for _ in range(t):
	s = input()
	print(sex(s))


t = int(input())
for _ in range(t):
	s = input()
	(e, ne) = ([], [])
	for i in range(0, 10, 2):
		if s[i] == '?':
			e.append(1)
		else:
			e.append(int(s[i]))
		if s[i + 1] == '?':
			ne.append(0)
		else:
			ne.append(int(s[i + 1]))
	n = 0
	x = 10
	y = 10
	for i in range(5):
		if e[i] == 1:
			n += 1
		if n > 0 and n > 4 - i + 1:
			x = 2 * i + 1
			break
		if n < 0 and abs(n) > 4 - i:
			x = 2 * i + 1
			break
		if ne[i] == 1:
			n -= 1
		if n > 0 and n > 4 - i:
			x = 2 * i + 2
			break
		if n < 0 and abs(n) > 4 - i:
			x = 2 * i + 2
			break
	(e, ne) = ([], [])
	for i in range(0, 10, 2):
		if s[i] == '?':
			e.append(0)
		else:
			e.append(int(s[i]))
		if s[i + 1] == '?':
			ne.append(1)
		else:
			ne.append(int(s[i + 1]))
	n = 0
	for i in range(5):
		if e[i] == 1:
			n += 1
		if n > 0 and n > 4 - i + 1:
			y = 2 * i + 1
			break
		if n < 0 and abs(n) > 4 - i:
			y = 2 * i + 1
			break
		if ne[i] == 1:
			n -= 1
		if n > 0 and n > 4 - i:
			y = 2 * i + 2
			break
		if n < 0 and abs(n) > 4 - i:
			y = 2 * i + 2
			break
	print(min(x, y))


import sys
input = sys.stdin.readline

def solve():
	s = input().strip()
	for i in range(0, len(s)):
		(a, b) = (0, 0)
		for j in range(0, i, 2):
			a += s[j] != '0'
		for j in range(1, i, 2):
			b += s[j] == '1'
		for j in range(1, 10, 2):
			b += j >= i
		if b < a:
			print(i)
			return
		(a, b) = (0, 0)
		for j in range(0, i, 2):
			a += s[j] == '1'
		for j in range(0, 10, 2):
			a += j >= i
		for j in range(1, i, 2):
			b += s[j] != '0'
		if a < b:
			print(i)
			return
	print(10)
for i in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	s = input()
	a = [0, 0, 0, 0, 0]
	b = [0, 0, 0, 0, 0]
	a[0] = s[0] == '1'
	b[0] = s[1] == '1'
	for i in range(1, 5):
		a[i] = a[i - 1] + (s[2 * i] == '1')
		b[i] = b[i - 1] + (s[2 * i + 1] == '1')
	a.append(a[-1])
	b.append(b[-1])
	flag = 1
	aa = [0, 0, 0, 0, 0]
	bb = [0, 0, 0, 0, 0]
	aa[0] = s[0] == '1' or s[0] == '?'
	bb[0] = s[1] == '1' or s[1] == '?'
	for i in range(1, 5):
		aa[i] = aa[i - 1] + (s[2 * i] == '1' or s[2 * i] == '?')
		if aa[i] - b[i - 1] > 5 - i or bb[i - 1] - a[i] > 4 - i:
			print(2 * i + 1)
			flag = 0
			break
		bb[i] = bb[i - 1] + (s[2 * i + 1] == '1' or s[2 * i + 1] == '?')
		if bb[i] - a[i] > 4 - i or aa[i] - b[i] > 4 - i:
			print(2 * i + 2)
			flag = 0
			break
	if flag:
		print(10)
4


t = int(input())
for _ in range(t):
	s = input()
	(fn, sn, ans) = (0, 0, 10)
	(a, b) = (5, 5)
	for i in range(len(s)):
		if i % 2 == 0:
			fn += s[i] == '1' or s[i] == '?'
		else:
			sn += s[i] == '1'
			b -= 1
		if fn > sn + b:
			ans = i + 1
			break
	fn = 0
	sn = 0
	for i in range(len(s)):
		if i % 2 == 1:
			sn += s[i] == '1' or s[i] == '?'
		else:
			fn += s[i] == '1'
			a -= 1
		if sn > fn + a:
			ans = min(ans, i + 1)
			break
	print(ans)


import sys
import math
tc_num = int(sys.stdin.readline())
for _ in range(tc_num):
	predict = sys.stdin.readline().strip()
	min_kicks_odd = 10
	min_kicks_even = 10
	even_score = 0
	odd_score = 0
	for i in range(10):
		if i % 2 == 0:
			if predict[i] == '1' or predict[i] == '?':
				odd_score += 1
		if i % 2 == 1:
			if predict[i] == '1':
				even_score += 1
		if odd_score > even_score + math.ceil((9 - i) / 2):
			min_kicks_odd = i + 1
			break
	even_score = 0
	odd_score = 0
	for i in range(10):
		if i % 2 == 0:
			if predict[i] == '1':
				odd_score += 1
		if i % 2 == 1:
			if predict[i] == '1' or predict[i] == '?':
				even_score += 1
		if even_score > odd_score + math.floor((9 - i) / 2):
			min_kicks_even = i + 1
			break
	print(min(min_kicks_odd, min_kicks_even))


def f():
	T = int(input())
	for _ in range(T):
		s = input()
		idx = solve(s)
		print(idx + 1)

def solve(s):
	n = len(s)
	(A_min, A_max) = (0, 0)
	(B_min, B_max) = (0, 0)
	for i in range(n):
		c = 0
		try:
			c = int(s[i])
		except:
			pass
		if i % 2 == 0:
			A_min += c
			if s[i] == '?':
				A_max += 1
			else:
				A_max += c
		else:
			B_min += c
			if s[i] == '?':
				B_max += 1
			else:
				B_max += c
		A_remain = 5 - (i + 2) // 2
		B_remain = 5 - (i + 1) // 2
		if A_max > B_min + B_remain:
			return i
		if B_max > A_min + A_remain:
			return i
	return 9
f()


for _ in [0] * int(input()):
	a = list(input())
	k = sa = sb = 0
	x = 10
	for i in range(10):
		val = a[i]
		sa = int(k == 0) * (int(val == '?') + int(val == '1')) + sa
		sb = int(k == 1) * int(val == '1') + sb
		k = 1 - k
		if sa > sb + (5 - (i + 1) // 2) or sb > sa + (5 - (i + 2) // 2):
			x = i + 1
			break
	k = sa = sb = 0
	for i in range(10):
		val = a[i]
		sb = int(k == 1) * (int(val == '?') + int(val == '1')) + sb
		sa = int(k == 0) * int(val == '1') + sa
		k = 1 - k
		if sa > sb + (5 - (i + 1) // 2) or sb > sa + (5 - (i + 2) // 2):
			x = min(i + 1, x)
			break
	print(x)


def fun(s):
	s1 = ''
	s2 = ''
	for i in range(len(s)):
		if s[i] == '?':
			if i % 2 == 0:
				s1 += '1'
				s2 += '0'
			else:
				s1 += '0'
				s2 += '1'
		else:
			s1 += s[i]
			s2 += s[i]
	return (s1, s2)
x = int(input())
while x != 0:
	s = input()
	s1 = ''
	s2 = ''
	(s1, s2) = fun(s)
	p1 = 0
	p2 = 0
	ans = 10
	for i in range(len(s1)):
		if i % 2 == 0:
			if s1[i] == '1':
				p1 += 1
		elif s1[i] == '1':
			p2 += 1
		sz = 10 - i - 1
		rem = sz / 2
		if sz % 2 != 0:
			rem += 1
		total = rem + p2
		if total < p1:
			ans = min(ans, i + 1)
	p1 = 0
	p2 = 0
	for i in range(len(s2)):
		if i % 2 == 0:
			if s2[i] == '1':
				p1 += 1
		elif s2[i] == '1':
			p2 += 1
		sz = 10 - i - 1
		rem = sz / 2
		total = rem + p1
		if total < p2:
			ans = min(ans, i + 1)
	print(ans)
	x -= 1


def minPossibleKicks(predictions):
	n = len(predictions)
	d = n
	scores = [0, 0]
	for turn in range(n):
		if turn % 2 == 0:
			scores[0] += predictions[turn] == '1'
		else:
			scores[1] += predictions[turn] != '0'
		if scores[0] > scores[1] + (10 - turn) // 2:
			d = min(d, turn)
		if scores[1] > scores[0] + (9 - turn) // 2:
			d = min(d, turn)
	scores = [0, 0]
	for turn in range(n):
		if turn % 2 != 0:
			scores[1] += predictions[turn] == '1'
		else:
			scores[0] += predictions[turn] != '0'
		if scores[0] > scores[1] + (10 - turn) // 2:
			d = min(d, turn)
		if scores[1] > scores[0] + (9 - turn) // 2:
			d = min(d, turn)
	return min(n, d + 1)
t = int(input())
for case in range(t):
	s = input()
	print(minPossibleKicks(s))


for _ in range(int(input())):
	s = input()
	ans = 10
	(e, ec, o, oc) = (5, 0, 5, 0)
	ans1 = -1
	for i in range(10):
		if i % 2 == 0:
			e -= 1
			if s[i] == '1':
				ec += 1
			elif s[i] == '0':
				pass
			else:
				ec += 1
		else:
			o -= 1
			if s[i] == '1':
				oc += 1
			elif s[i] == '0':
				pass
			else:
				pass
		if ec > oc and ec - oc > o:
			ans1 = i + 1
			break
		elif oc > ec and oc - ec > e:
			ans1 = i + 1
			break
	(e, ec, o, oc) = (5, 0, 5, 0)
	ans2 = -1
	for i in range(10):
		if i % 2 == 0:
			e -= 1
			if s[i] == '1':
				ec += 1
			elif s[i] == '0':
				pass
			else:
				pass
		else:
			o -= 1
			if s[i] == '1':
				oc += 1
			elif s[i] == '0':
				pass
			else:
				oc += 1
		if ec > oc and ec - oc > o:
			ans2 = i + 1
			break
		elif oc > ec and oc - ec > e:
			ans2 = i + 1
			break
	if ans1 == -1 and ans2 == -1:
		ans = 10
	elif ans1 == -1:
		ans = ans2
	elif ans2 == -1:
		ans = ans1
	else:
		ans = min(ans1, ans2)
	print(ans)


for _ in range(int(input())):
	a = input()
	b1 = 0
	d1 = 0
	b2 = 0
	d2 = 0
	t1 = 10
	t2 = 10
	for i in range(10):
		if i % 2 == 0:
			if a[i] != '?':
				b1 += int(a[i])
			else:
				b1 += 1
		elif a[i] != '?':
			d1 += int(a[i])
		if (i == 5 or i == 6) and b1 - d1 > 2 or ((i == 8 or i == 9 or i == 7) and b1 - d1 > 1):
			t1 = i + 1
			break
	for i in range(10):
		if i % 2 == 0:
			if a[i] != '?':
				b2 += int(a[i])
		elif a[i] != '?':
			d2 += int(a[i])
		else:
			d2 += 1
		if i == 5 and d2 - b2 > 2 or ((i == 6 or i == 7) and d2 - b2 > 1) or ((i == 8 or i == 9) and d2 - b2 > 0):
			t2 = i + 1
			break
	print(min(t1, t2))


from math import sqrt, ceil, floor
import sys
from collections import Counter, deque
from collections import defaultdict as dd

def check(s):
	e = 0
	o = 0
	ee = 5
	oo = 5
	for i in range(10):
		e += (i + 1) % 2 * int(s[i])
		o += i % 2 * int(s[i])
		ee -= (i + 1) % 2
		oo -= i % 2
		if e - o > oo or o - e > ee:
			return i + 1
	return 10
t = int(input())
for tt in range(t):
	s = list(input())
	s1 = ''
	s2 = ''
	for i in range(10):
		if s[i] == '?':
			s1 += chr(48 + (i + 1) % 2)
			s2 += chr(48 + i % 2)
		else:
			s1 += s[i]
			s2 += s[i]
	print(min(check(s1), check(s2)))


import sys
pos = []

def check(a, i, osf):
	global pos
	if i == len(a):
		pos.append(osf)
		return
	if a[i] == '?':
		check(a, i + 1, osf + '0')
		check(a, i + 1, osf + '1')
	else:
		check(a, i + 1, osf + a[i])

def cal(a):
	s1 = 0
	s2 = 0
	t1 = 5
	t2 = 5
	i = 0
	while True:
		if i == len(a):
			break
		if s2 - s1 > t1:
			break
		if s1 - s2 > t2:
			break
		if a[i] == '?':
			if s1 > s2 and i % 2 == 0:
				s1 += 1
			if s2 > s1 and i % 2 == 1:
				s2 += 1
			if s2 == s1:
				count1 = 0
				count2 = 0
				for j in range(i + 1, len(a)):
					if j % 2 == 0 and a[j] == '1':
						count1 += 1
					if j % 2 == 1 and a[j] == '1':
						count2 += 1
				if count2 > count1:
					s2 += 1
				else:
					s1 += 1
		if a[i] == '1' and i % 2 == 0:
			s1 += 1
		if a[i] == '1' and i % 2 == 1:
			s2 += 1
		if i % 2 == 0:
			t1 -= 1
		if i % 2 == 1:
			t2 -= 1
		i += 1
	return 10 - t1 - t2
for i in range(int(input())):
	a = input()
	check(a, 0, '')
	ans = sys.maxsize
	for i in pos:
		ans = min(ans, cal(i))
	pos = []
	print(ans)


import sys, os, io
input = sys.stdin.readline
for _ in range(int(input())):
	s = input().strip()
	t1win = 0
	t1any = 0
	t2win = 0
	t2any = 0
	ans = 10
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '1':
				t1win += 1
			elif s[i] == '?':
				t1any += 1
		elif s[i] == '1':
			t2win += 1
		elif s[i] == '?':
			t2any += 1
		rem1 = (9 - i) // 2
		rem2 = (10 - i) // 2
		if t1win + t1any - t2win > rem2:
			ans = i + 1
			break
		if t2win + t2any - t1win > rem1:
			ans = i + 1
			break
	print(ans)


t = int(input())
while t > 0:
	s = str(input())
	s1 = s[0] + s[2] + s[4] + s[6] + s[8]
	s2 = s[1] + s[3] + s[5] + s[7] + s[9]
	s1a = [0, 0, 0, 0]
	s2a = [0, 0, 0, 0]
	f = 0
	for i in range(5):
		if s1a[3] > s2a[1] + 5 - i or s2a[3] > s1a[1] + 5 - i:
			print(2 * i)
			f = 1
			break
		if s1[i] == '0':
			s1a[0] += 1
		elif s1[i] == '1':
			s1a[1] += 1
		else:
			s1a[2] += 1
		s1a[3] = s1a[1] + s1a[2]
		if s1a[3] > s2a[1] + 5 - i or s2a[3] > s1a[1] + 4 - i:
			print(2 * i + 1)
			f = 1
			break
		if s2[i] == '0':
			s2a[0] += 1
		elif s2[i] == '1':
			s2a[1] += 1
		else:
			s2a[2] += 1
		s2a[3] = s2a[1] + s2a[2]
	if f == 0:
		print(10)
	t = t - 1


from sys import stdin, stdout
from heapq import heapify, heappush, heappop
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
import math
from itertools import permutations
sys.setrecursionlimit(10 ** 5)
mod = 10 ** 9 + 7

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	ans = []
	for p in range(n + 1):
		if prime[p]:
			ans.append(p)
	return ans

def f(a):
	t = a
	a = t // 10
	while a > 0:
		t *= 10
		t += a % 10
		a //= 10
	return t

def mapinput():
	return map(int, stdin.readline().split())

def strinput():
	return stdin.readline().strip()

def listinput():
	return list(map(int, stdin.readline().split()))

def intinput():
	return int(stdin.readline().strip())
for test in range(intinput()):

	def solve():
		s = strinput()
		ans = 10
		sc1 = 0
		sc2 = 0
		for i in range(10):
			if i & 1 == 0 and (s[i] == '1' or s[i] == '?'):
				sc1 += 1
			elif i & 1 == 1 and s[i] == '1':
				sc2 += 1
			if sc1 - sc2 > (10 - i) // 2:
				ans = min(i + 1, ans)
		sc1 = 0
		sc2 = 0
		for i in range(10):
			if i & 1 == 1 and (s[i] == '1' or s[i] == '?'):
				sc2 += 1
			elif i & 1 == 0 and s[i] == '1':
				sc1 += 1
			if sc2 - sc1 > (9 - i) // 2:
				ans = min(i + 1, ans)
		return ans
	print(solve())


def algo(lst):
	A = 0
	B = 0
	kickA = 0
	kickB = 0
	for i in range(len(lst)):
		if i % 2 == 0:
			if lst[i] == 1:
				A += 1
			kickA += 1
		else:
			if lst[i] == 1:
				B += 1
			kickB += 1
		if A > B + 5 - kickB:
			return i + 1
		if B > A + 5 - kickA:
			return i + 1
	return 10
for i in range(int(input())):
	s = list(input())
	awin = []
	bwin = []
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '?':
				awin.append(1)
			else:
				awin.append(int(s[i]))
		elif s[i] == '?':
			awin.append(0)
		else:
			awin.append(int(s[i]))
	for i in range(10):
		if i % 2 == 1:
			if s[i] == '?':
				bwin.append(1)
			else:
				bwin.append(int(s[i]))
		elif s[i] == '?':
			bwin.append(0)
		else:
			bwin.append(int(s[i]))
	print(min(algo(awin), algo(bwin)))


import sys, math, os
from math import factorial, inf, gcd, pi, sqrt, ceil
from heapq import *
from functools import *
from itertools import *
from collections import *
sys.setrecursionlimit(10 ** 5)
if os.environ.get('HOME') == '/Users/clarity':
	os.chdir(os.path.dirname(os.path.abspath(__file__)))
	inp = open('C_test.txt', 'r').readline

	def debug(*args):
		print(*args, file=sys.stderr)
else:
	inp = sys.stdin.readline

	def debug(*args):
		pass

def line():
	return list(map(int, inp().rstrip().split()))

def fline():
	return list(map(float, inp().rstrip().split()))

def number():
	return int(inp())

def print_array(l):
	print(' '.join(list(map(str, l))))

def testcase(t):
	for p in range(t):
		solve()

def solve_determined(s):
	a = s[0::2]
	b = s[1::2]
	if sum(a[:3]) > 2 and sum(b[:3]) == 0 or (sum(b[:3]) > 2 and sum(a[:3]) == 0):
		return 6
	if sum(a[:4]) - sum(b[:3]) > 2 or sum(b[:3]) - sum(a[:4]) > 1:
		return 7
	if sum(a[:4]) - sum(b[:4]) > 1 or sum(b[:4]) - sum(a[:4]) > 1:
		return 8
	if sum(a[:5]) - sum(b[:4]) > 1 or sum(b[:4]) - sum(a[:5]) > 0:
		return 9
	return 10

def solve():
	s = inp().strip()
	ba = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]
	bb = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]
	best_a = [int(s[i]) if s[i] != '?' else ba[i] for i in range(len(s))]
	best_b = [int(s[i]) if s[i] != '?' else bb[i] for i in range(len(s))]
	ans = min(solve_determined(best_a), solve_determined(best_b))
	print(ans)

def main():
	testcase(number())
main()


from sys import stdin, stdout

def read():
	return stdin.readline().strip()

def read_int():
	return [int(i) for i in read().split()]

def write(s):
	stdout.write(s)

def count(s):
	score = [0] * 5
	for i in range(10):
		if s[i] == '1':
			score[i & 1] += 1
		if i & 1:
			if score[1] > score[0] + (10 - i) // 2:
				return i + 1
			if score[1] + (9 - i) // 2 < score[0]:
				return i + 1
		else:
			if score[0] > score[1] + (10 - i) // 2:
				return i + 1
			if score[0] + (9 - i) // 2 < score[1]:
				return i + 1
	return 10
for _ in range(int(read())):
	s = read()
	t = s
	s = [s[i] if s[i] != '?' else '1' if i & 1 else '0' for i in range(len(s))]
	t = [t[i] if t[i] != '?' else '0' if i & 1 else '1' for i in range(len(s))]
	print(min(count(s), count(t)))


def solve(s1, s2) -> int:
	assert len(s1) == len(s2)
	l = len(s1)
	s1 = list(map(int, s1))
	s2 = list(map(int, s2))
	s1Cnt = 0
	s2Cnt = 0
	for i in range(l):
		s1Cnt += s1[i]
		if s1Cnt - s2Cnt > l - i or s2Cnt - s1Cnt > l - i - 1:
			return i * 2 + 1
		s2Cnt += s2[i]
		if s1Cnt - s2Cnt > l - i - 1 or s2Cnt - s1Cnt > l - i - 1:
			return (i + 1) * 2
	return 10
t = int(input())
anss = []
for _ in range(t):
	s = str(input())
	first = s[::2]
	second = s[1::2]
	firstBest = first.replace('?', '1')
	firstWorst = first.replace('?', '0')
	secondBest = second.replace('?', '1')
	secondWorst = second.replace('?', '0')
	anss.append(min(solve(firstBest, secondWorst), solve(firstWorst, secondBest)))
for ans in anss:
	print(ans)


n = int(input())
for _ in range(n):
	seq = str(input())
	maxs = [0] * 2
	mins = [0] * 2
	left = [5] * 2
	for i in range(len(seq)):
		if seq[i] == '1':
			maxs[i % 2] += 1
			mins[i % 2] += 1
		elif seq[i] == '?':
			maxs[i % 2] += 1
		if i % 2 == 0:
			left[0] -= 1
		else:
			left[1] -= 1
		if left[0] < maxs[1] - mins[0] or left[1] < maxs[0] - mins[1]:
			print(i + 1)
			break
	else:
		print('10')


def main():
	S = list(map(lambda x: int(x) if x != '?' else -1, input()))
	Ans = 10
	for P in range(2):
		X = [0, 0]
		for i in range(10):
			X[i % 2] += S[i] if S[i] != -1 else P ^ i % 2
			if X[0] > X[1]:
				if X[0] - X[1] > (10 - i) // 2:
					Ans = min(Ans, i + 1)
					break
			elif X[1] > X[0]:
				if X[1] - X[0] > (10 - i - 1) // 2:
					Ans = min(Ans, i + 1)
					break
	print(Ans)
T = int(input())
for _ in range(T):
	main()


test_cases = int(input())
for test_case in range(test_cases):
	s = input()
	a = ''
	b = ''
	for i in range(len(s)):
		if i % 2 == 0:
			a += s[i]
		else:
			b += s[i]
	aa = 0
	bb = 0
	ans = 10
	lead = 0
	sr = 5
	c = 0
	for i in range(5):
		if a[i] == '1' or a[i] == '?':
			aa += 1
		c += 1
		if aa - bb > sr:
			ans = c
			break
		if b[i] == '1':
			bb += 1
		sr -= 1
		c += 1
		if aa - bb > sr:
			ans = c
			break
	aa = 0
	bb = 0
	sr = 5
	c = 0
	for i in range(5):
		if a[i] == '1':
			aa += 1
		sr -= 1
		c += 1
		if bb - aa > sr:
			if ans > c:
				ans = c
			break
		if b[i] == '1' or b[i] == '?':
			bb += 1
		c += 1
		if bb - aa > sr:
			if ans > c:
				ans = c
			break
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	score = input().strip()
	minA = maxA = minB = maxB = 0
	ans = 10
	for i in range(10):
		if i % 2:
			if score[i] == '1':
				minB += 1
				maxB += 1
			elif score[i] == '?':
				maxB += 1
		elif score[i] == '1':
			minA += 1
			maxA += 1
		elif score[i] == '?':
			maxA += 1
		chanceA = 4 - i // 2
		chanceB = 4 - (i - 1) // 2
		if maxA > minB + chanceB or maxB > minA + chanceA:
			ans = i + 1
			break
	print(ans)


from collections import *
from math import *
TT = int(input())
for y in range(TT):
	s = input()
	ans = 0
	minna = minnb = maxxa = maxxb = 0
	foo = 1
	rema = remb = 5
	for i in range(10):
		foo ^= 1
		ans += 1
		if foo:
			if s[i] == '1':
				minna += 1
				maxxa += 1
			elif s[i] == '0':
				pass
			else:
				maxxa += 1
			rema -= 1
		else:
			if s[i] == '1':
				minnb += 1
				maxxb += 1
			elif s[i] == '0':
				pass
			else:
				maxxb += 1
			remb -= 1
		if maxxb - minna > rema or maxxa - minnb > remb:
			break
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = input().strip()
	a = 0
	b = 0
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '1':
				a += 1
			elif s[i] == '0':
				pass
			else:
				a += 1
		elif s[i] == '1':
			b += 1
		elif s[i] == '0':
			pass
		else:
			pass
		if 5 - (i + 1) // 2 < a - b:
			break
	an = i
	a = 0
	b = 0
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '1':
				a += 1
			elif s[i] == '0':
				pass
			else:
				a += 0
		elif s[i] == '1':
			b += 1
		elif s[i] == '0':
			pass
		else:
			b += 1
		if 5 - (i + 2) // 2 < b - a:
			break
	an = min(an, i)
	print(an + 1)


def solve():
	s = input()
	left = [5, 5]
	diff = 0
	for (i, a) in enumerate(s):
		team = i & 1
		left[team] -= 1
		if a == '?':
			left[not team] -= 1
		elif a == '1':
			diff += (-1) ** team
		for winner in (0, 1):
			if diff * (-1) ** winner > left[not winner]:
				return i + 1
	return 10
t = int(input())
for __ in range(t):
	print(solve())


tst = int(input())
for _ in range(tst):
	s = list(input())
	result = [9]

	def recur(move, A, B, Arest, Brest):
		if move == 10:
			return
		if s[move] == '?':
			s[move] = '0'
			(a, b) = (A, B)
			(x, y) = (Arest, Brest)
			if move % 2 == 0:
				x -= 1
			else:
				y -= 1
			if a > b + y or b > a + x:
				result[0] = min(result[0], move)
			else:
				recur(move + 1, a, b, x, y)
			s[move] = '1'
			(a, b) = (A, B)
			(x, y) = (Arest, Brest)
			if move % 2 == 0:
				a += 1
				x -= 1
			else:
				b += 1
				y -= 1
			if a > b + y or b > a + x:
				result[0] = min(result[0], move)
			else:
				recur(move + 1, a, b, x, y)
			s[move] = '?'
		else:
			(a, b, x, y) = (A, B, Arest, Brest)
			if move % 2 == 0:
				if s[move] == '1':
					a += 1
					x -= 1
				else:
					x -= 1
			elif s[move] == '1':
				b += 1
				y -= 1
			else:
				y -= 1
			if a > b + y or b > a + x:
				result[0] = min(result[0], move)
			else:
				recur(move + 1, a, b, x, y)
	recur(0, 0, 0, 5, 5)
	print(result[0] + 1)


def solve():
	s = input()
	(goals_1, goals_2, unknown_1, unknown_2) = (0, 0, 0, 0)
	(left_1, left_2) = (5, 5)
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '1':
				goals_1 += 1
			elif s[i] == '?':
				unknown_1 += 1
			left_1 -= 1
		else:
			if s[i] == '1':
				goals_2 += 1
			elif s[i] == '?':
				unknown_2 += 1
			left_2 -= 1
		if goals_1 + unknown_1 > goals_2 + left_2:
			return i + 1
		elif goals_2 + unknown_2 > goals_1 + left_1:
			return i + 1
	return 10
for _ in range(int(input())):
	print(solve())