CF2192A.String Rotation Game

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

String Rotation Game

Define a block in a string as a contiguous substring of characters of the same type that cannot be extended either to the left or the right. For example, in the string aabcccdaa, there are five blocks:

  • aa (11-st to 22-nd characters)
  • b (33-rd character)
  • ccc (44-th to 66-th characters)
  • d (77-th character)
  • aa (88-th to 99-th characters).

You are playing a game where you are given a string ss of length nn. You can cyclically rotate^{\text{∗}} the string however you want. Your score is then calculated as the number of blocks in the final string. Please find the maximum score possible.

^{\text{∗}}Formally, choose an index 1in1 \leq i \leq n, and replace the string s1s2sns_1s_2\ldots s_n with the string si+1si+2sns1s2sis_{i+1}s_{i+2}\ldots s_ns_1s_2\ldots s_{i}. For example, the string abcde can be rotated to string deabc by choosing i=3i=3.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t5001 \le t \le 500). The description of the test cases follows.

The first line of each test case contains a single integer nn (1n1001 \le n \le 100).

The second line of each test case contains the string ss of length nn.

Strings ss consist of lowercase Latin characters only.

Output

For each testcase, output a single integer denoting the maximum score you can achieve.

Note

In the first test case, score of the original string abcd is 44. It can be shown that a score greater than 44 cannot be achieved.

In the second test case, cyclically rotating the string by 22 positions will give us string bcab. Score of this string is 44. It can be shown that a score greater than 44 cannot be achieved.

Samples

4
4
abcd
4
abbc
4
abba
6
abbccc
4
4
3
4

在线编程 IDE

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