Codeforces Round 1064 (Div. 2)
A
Same Difference
Codeforces
800
原题
←B →
翻译中…

You are given a string $s$ of length $n$, consisting of lowercase letters.

翻译中…

In one operation, you can select an integer $i$ such that $1\leq i \lt n$ and change $s_i$ into $s_{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 $t$ ($1 \le t \le 20$). The description of the test cases follows.

翻译中…

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

翻译中…

The following line contains a string $s$ of length $n$, consisting of lowercase letters.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $100$.

翻译中…

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 $s_2$ to $s_3$ using $1$ operation to reach the goal.

翻译中…

In the third test case, you can change $s_3$ to $s_4$ and then change $s_2$ to $s_3$, using $2$ operations in total. It can be proved that the answer is not less than $2$.

翻译中…

样例

Input #1
5
3
qwq
2
aa
4
test
5
abbac
6
abcabc
Output #1
1
0
2
4
4
InputCopy OutputCopy
题目信息
题号
2166A
时间限制
1 s
内存限制
256 MB
标签
暴力
贪心
字符串

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