CF2166A.Same Difference

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

Same Difference

You are given a string ss of length nn, consisting of lowercase letters.

In one operation, you can select an integer ii such that 1i<n1\leq i \lt n and change sis_i into si+1s_{i+1}.

What is the minimum number of operations needed to make every character the same? It can be proved that this is always possible.

Input

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

The first line of each test case contains an integer nn (2n1002\le n\le 100) — the length of the string.

The following line contains a string ss of length nn, consisting of lowercase letters.

It is guaranteed that the sum of nn over all test cases does not exceed 100100.

Output

For each test case, output a single integer — the minimum number of operations needed to make every character the same.

Note

In the first test case, you can change s2s_2 to s3s_3 using 11 operation to reach the goal.

In the third test case, you can change s3s_3 to s4s_4 and then change s2s_2 to s3s_3, using 22 operations in total. It can be proved that the answer is not less than 22.

Samples

5
3
qwq
2
aa
4
test
5
abbac
6
abcabc
1
0
2
4
4

在线编程 IDE

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