Under construction

Still being built. Things may change

Occupy the Cities

Time limit1sMemory limit1024 MB

Summary
Given a row of cities with some occupied, find the fewest rounds needed for every occupied city to take one adjacent empty city until all are occupied.
Level

Medium7 of 10

Topics
String, Binary search, Greedy
Solved
No attempts yet

Problem

JB is playing a game. The game has nn cities, numbered 1,2,⋯ ,n1, 2, \cdots, n. The ii-th and jj-th cities are adjacent if and only if i=j−1i = j - 1 or i=j+1i = j + 1. Initially, some of the cities are occupied by JB.

The game runs in rounds. At the start of a round, each occupied city can mark at most one adjacent unoccupied city as its attack target. At the end of the round, all marked attack targets become occupied. The game ends when all the cities are occupied.

JB wants to occupy all the cities in the minimum number of rounds. Can you help him?

Input

There are multiple test cases. The first line contains a positive integer TT, the number of test cases. Each test case is as follows.

The first line contains an integer nn (1≤n≤1061 \le n \le 10^6), the number of cities.

The next line contains a string ss of length nn, consisting only of '0' and '1'. The ii-th character describes the initial state of the ii-th city: if sis_i is '1', the ii-th city is initially occupied by JB. Otherwise, it is not.

The sum of nn over all test cases does not exceed 10610^6. At least one '1' is in ss.

Output

For each test case, output one line containing the minimum number of rounds needed to occupy all the cities.

Hint

In the second test case, the best way is 0100→0110→11110100 \rightarrow 0110 \rightarrow 1111.

Examples1

  1. Example 1

    Input
    5
    3
    010
    4
    0100
    7
    0001000
    5
    11111
    6
    010101
    
    Expected output
    2
    2
    4
    0
    1