CF1244B.Rooms and Staircases

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Rooms and Staircases

Nikolay lives in a two-storied house. There are nn rooms on each floor, arranged in a row and numbered from one from left to right. So each room can be represented by the number of the floor and the number of the room on this floor (room number is an integer between 11 and nn).

If Nikolay is currently in some room, he can move to any of the neighbouring rooms (if they exist). Rooms with numbers ii and i+1i+1 on each floor are neighbouring, for all 1in11 \leq i \leq n - 1. There may also be staircases that connect two rooms from different floors having the same numbers. If there is a staircase connecting the room xx on the first floor and the room xx on the second floor, then Nikolay can use it to move from one room to another.

The picture illustrates a house with n=4n = 4. There is a staircase between the room 22 on the first floor and the room 22 on the second floor, and another staircase between the room 44 on the first floor and the room 44 on the second floor. The arrows denote possible directions in which Nikolay can move. The picture corresponds to the string "0101" in the input.

Nikolay wants to move through some rooms in his house. To do this, he firstly chooses any room where he starts. Then Nikolay moves between rooms according to the aforementioned rules. Nikolay never visits the same room twice (he won't enter a room where he has already been).

Calculate the maximum number of rooms Nikolay can visit during his tour, if:

  • he can start in any room on any floor of his choice,
  • and he won't visit the same room twice.

Input

The first line of the input contains one integer tt (1t1001 \le t \le 100) — the number of test cases in the input. Then test cases follow. Each test case consists of two lines.

The first line contains one integer nn (1n1000)(1 \le n \le 1\,000) — the number of rooms on each floor.

The second line contains one string consisting of nn characters, each character is either a '0' or a '1'. If the ii-th character is a '1', then there is a staircase between the room ii on the first floor and the room ii on the second floor. If the ii-th character is a '0', then there is no staircase between the room ii on the first floor and the room ii on the second floor.

In hacks it is allowed to use only one test case in the input, so t=1t = 1 should be satisfied.

Output

For each test case print one integer — the maximum number of rooms Nikolay can visit during his tour, if he can start in any room on any floor, and he won't visit the same room twice.

Note

In the first test case Nikolay may start in the first room of the first floor. Then he moves to the second room on the first floor, and then — to the third room on the first floor. Then he uses a staircase to get to the third room on the second floor. Then he goes to the fourth room on the second floor, and then — to the fifth room on the second floor. So, Nikolay visits 66 rooms.

There are no staircases in the second test case, so Nikolay can only visit all rooms on the same floor (if he starts in the leftmost or in the rightmost room).

In the third test case it is possible to visit all rooms: first floor, first room \rightarrow second floor, first room \rightarrow second floor, second room \rightarrow first floor, second room \rightarrow first floor, third room \rightarrow second floor, third room \rightarrow second floor, fourth room \rightarrow first floor, fourth room \rightarrow first floor, fifth room \rightarrow second floor, fifth room.

In the fourth test case it is also possible to visit all rooms: second floor, third room \rightarrow second floor, second room \rightarrow second floor, first room \rightarrow first floor, first room \rightarrow first floor, second room \rightarrow first floor, third room.

Samples

4
5
00100
8
00000000
5
11111
3
110
6
8
10
6

在线编程 IDE

建议全屏模式获得最佳体验