#K51347. Minimum Swaps to Uniform String

    ID: 29067 Type: Default 1000ms 256MiB

Minimum Swaps to Uniform String

Minimum Swaps to Uniform String

You are given a string S of length N. In one operation (swap), you can change any character in S to any other character. Your goal is to make all characters in the string identical using the minimum number of operations. The key observation is that the optimal strategy is to convert all characters to the one that appears most frequently. Mathematically, if the frequency of the most common character is \(f_{max}\) and the length of the string is \(N\), then the minimum number of swaps required is given by:

$$ N - f_{max} $$

This problem requires you to process multiple test cases.

inputFormat

The input begins with a single integer T, the number of test cases. For each test case, the first line contains an integer N (the length of the string), followed by a line containing the string S.

outputFormat

For each test case, output a single line containing the minimum number of swap operations required to make all the characters in the string equal.

## sample
3
1
a
3
abc
4
aabb
0

2 2

</p>