#P1553C. Penalty

    ID: 1969 Type: RemoteJudge 3000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 4 Uploaded By: Tags>bitmasksbrute forcedpgreedy*1200

Penalty

Description

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

A penalty phase consists of at most 1010 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 77-th kick the first team has scored 11 goal, and the second team has scored 33 goals, the penalty phase ends — the first team cannot reach 33 goals.

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

  • if sis_i is 1, then the ii-th kick will definitely score a goal;
  • if sis_i is 0, then the ii-th kick definitely won't score a goal;
  • if sis_i is ?, then the ii-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.

The first line contains one integer tt (1t10001 \le t \le 1\,000) — the number of test cases.

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

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

Input

The first line contains one integer tt (1t10001 \le t \le 1\,000) — the number of test cases.

Each test case is represented by one line containing the string ss, consisting of exactly 1010 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.

Sample Input 1

4
1?0???1001
1111111111
??????????
0100000000

Sample Output 1

7
10
6
9

Note

Consider the example test:

In the first test case, consider the situation when the 11-st, 55-th and 77-th kicks score goals, and kicks 22, 33, 44 and 66 are unsuccessful. Then the current number of goals for the first team is 33, for the second team is 00, and the referee sees that the second team can score at most 22 goals in the remaining kicks. So the penalty phase can be stopped after the 77-th kick.

In the second test case, the penalty phase won't be stopped until all 1010 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 66-th kick, the first team has scored 00 goals and the second team has scored 33 goals, and the referee sees that the first team can score at most 22 goals in the remaining kicks. So, the penalty phase can be stopped after the 66-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 99-th kick.