Universal Cup Judging System

Universal Cup

実行時間制限: 2.0 s メモリ制限: 2048 MB 満点: 100 難易度: [表示] ハック可能 ✓
統計

Architecture is often the result of friction between two brilliant but opposing minds. Kotori and Umi, lead architects for a new metropolitan promenade, find themselves in a deadlock regarding the pavement's aesthetic direction. The promenade is modeled as a sequence of $n$ cells in a single row.

Some cells have already been paved: some contain Kotori's signature white marble, while others contain Umi's preferred black granite. Many cells remain empty (marked as "?"). Kotori and Umi must now fill the remaining cells one by one.

To ensure total fairness in their collaboration and to prevent any single philosophy from dominating without a struggle, they have agreed to a formal design protocol:

  • Kotori and Umi take turns placing a single stone into an empty cell, with Kotori going first.
  • Kotori always places a white marble stone, as she believes the beauty of the promenade is measured by its longest contiguous segment of white marbles. She naturally seeks to maximize this length.
  • Umi, seeking to provide structural contrast and rhythm, believes that long, uninterrupted white segments are monotonous. She always places a black granite stone, aiming to minimize that same maximum length.

Once a stone is placed, it cannot be moved or replaced. The process continues until all empty cells are filled.

Given the initial state of the promenade, your task is to determine the final "Aesthetic Score" — the length of the longest contiguous segment of white marbles — assuming both architects play optimally to achieve their respective aesthetic goals.

Input

There are multiple test cases. The first line of the input contains an integer $T$ ($1 \le T \le 10^4$) indicating the number of test cases. For each test case:

The first and only line contains a single string $s_1 s_2 \dots s_n$ of length $n$ ($1 \le n \le 10^5$), where:

  • 0 represents a cell already containing Kotori's white marble;
  • 1 represents a cell already containing Umi's black granite;
  • ? represents a currently empty cell.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

Output

For each test case, output one line that contains an integer indicating the final score of the game.

Examples

Input 1

6
??
000
111
0??0??0
0?0?0?0
00?00?100?0

Output 1

1
3
0
3
5
5

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.