Codeforces Round 1081 (Div. 2)
A
String Rotation Game
Codeforces
800
原题
←B →
翻译中…

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 ($1$-st to $2$-nd characters)
  • b ($3$-rd character)
  • ccc ($4$-th to $6$-th characters)
  • d ($7$-th character)
  • aa ($8$-th to $9$-th characters).
翻译中…

You are playing a game where you are given a string $s$ of length $n$. 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 $1 \leq i \leq n$, and replace the string $s_1s_2\ldots s_n$ with the string $s_{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=3$.

翻译中…

Input

翻译中…

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

翻译中…

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

翻译中…

The second line of each test case contains the string $s$ of length $n$.

翻译中…

Strings $s$ 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 $4$. It can be shown that a score greater than $4$ cannot be achieved.

翻译中…

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

翻译中…

样例

Input #1
4
4
abcd
4
abbc
4
abba
6
abbccc
Output #1
4
4
3
4
InputCopy OutputCopy
题目信息
题号
2192A
时间限制
1 s
内存限制
256 MB
标签
暴力
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。