#CF1107C. RemovevomeR 移除一些 R

RemovevomeR 移除一些 R

当前没有测试数据。

CF测试跳转:https://codeforces.com/contest/2241/problem/C

You are given a binary string ss consisting only of the characters 0\texttt{0} and 1\texttt{1}.

In one operation, you can do the following:

  • Choose a substring^{\text{∗}} of ss that is a palindrome^{\text{†}} of length at least 22.
  • Delete exactly one character from this chosen substring.

The remaining parts of the string are then concatenated to form the new string ss.

Find the minimum possible length of the string ss that can be achieved after applying this operation any number of times (possibly zero).

^{\text{∗}}A string aa is a substring of a string bb if aa can be obtained from bb by the deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

^{\text{†}}A string aa of length mm is said to be palindrome if ai=am+1ia_i = a_{m + 1 - i} for all 1im1 \le i \le m.

Input

The first line contains a single integer tt (1t1001 \le t \le 100) — the number of test cases. Description of each test case follows.

The first line of each test case contains a single integer nn (1n1001 \le n \le 100) — the length of the binary string ss.

The second line of each test case contains a binary string ss of length nn. It is guaranteed that each character of ss is either 0\texttt{0} or 1\texttt{1}.

Output

For each test case, print the minimum possible length of the string ss that can be achieved after applying the operation any number of times.

Example

4
4
0000
3
110
6
110011
6
101100
1
2
1
1

Note

In the first test case, the initial string is 0000\texttt{0000}. We can perform the following sequence of operations:

  • Choose the palindromic substring 0000\texttt{0000}. Delete one 0\texttt{0}. The string becomes 000\texttt{000}.
  • Choose the palindromic substring 000\texttt{000}. Delete one 0\texttt{0}. The string becomes 00\texttt{00}.
  • Choose the palindromic substring 00\texttt{00}. Delete one 0\texttt{0}. The string becomes 0\texttt{0}.

The string 0\texttt{0} contains no palindromic substrings of length at least 22, so no further operations can be performed. The minimum possible length is 11.

In the second test case, the initial string is 110\texttt{110}.

  • Choose the palindromic substring 11\texttt{11}. Delete one 1\texttt{1}. The string becomes 10\texttt{10}.

The string 10\texttt{10} contains no palindromic substrings of length at least 22, so no further operations can be performed. The minimum possible length is 22.