最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

CF 1791C. Prepend and Append

2023-07-03 08:56 作者:您是打尖兒還是住店呢  | 我要投稿

Timur initially had a binary string s (possibly of length 0). He performed the following operation several (possibly zero) times:


Add 0 to one end of the string and 1 to the other end of the string. For example, starting from the string 1011, you can obtain either 010111

?or 110110.

You are given Timur's final string. What is the length of the shortest possible string he could have started with?


?A binary string is a string (possibly the empty string) whose characters are either 0 or 1.


Input

The first line of the input contains an integer t (1≤t≤100) — the number of testcases.


The first line of each test case contains an integer n (1≤n≤2000) — the length of Timur's final string.


The second line of each test case contains a string s of length n consisting of characters 0 or 1, denoting the final string.


Output

For each test case, output a single nonnegative integer — the shortest possible length of Timur's original string. Note that Timur's original string could have been empty, in which case you should output 0.


Example

input

9

3

100

4

0111

5

10101

6

101010

7

1010110

1

1

2

10

2

11

10

1011011010

output

1

2

5

0

3

1

0

2

4

Note

In the first test case, the shortest possible string Timur started with is 0, and he performed the following operation: 0→100.


In the second test case, the shortest possible string Timur started with is 11, and he performed the following operation: 11→0111.


In the third test case, the shortest possible string Timur started with is 10101, and he didn't perform any operations.


In the fourth test case, the shortest possible string Timur started with is the empty string (which we denote by ε), and he performed the following operations: ε→10→0101→101010.


In the fifth test case, the shortest possible string Timur started with is 101, and he performed the following operations: 101→01011→1010110.

-----------------------------------

只要首末兩端的數(shù)字不一樣,就可以一直循環(huán)下去,直到相等的時候,然后再去看字符的長度即可;

下面是代碼:


CF 1791C. Prepend and Append的評論 (共 條)

分享到微博請遵守國家法律
宁城县| 安丘市| 湘潭市| 綦江县| 新民市| 和田县| 西和县| 沭阳县| 博兴县| 岑溪市| 改则县| 屯门区| 沽源县| 华亭县| 勃利县| 江山市| 贵定县| 长岭县| 渭源县| 涡阳县| 陆河县| 丽水市| 谢通门县| 土默特右旗| 巫山县| 延庆县| 闵行区| 濮阳县| 广州市| 周至县| 台北市| 汽车| 镇宁| 凤山市| 车险| 柏乡县| 泽普县| 且末县| 炉霍县| 额敏县| 阜阳市|