#K51977. Minimum Baton Swaps

    ID: 29207 Type: Default 1000ms 256MiB

Minimum Baton Swaps

Minimum Baton Swaps

You are given T test cases. In each test case, there are N participants holding batons, where each baton is of one of two types: R or G. The arrangement of batons is given as a string S of length N containing only the characters R and G.

Your task is to determine the minimum number of swaps (i.e. changes) required to make all batons the same type. In one swap, you can change a baton from R to G or vice versa. The optimal strategy is to change the batons of the type that occurs less frequently, hence the answer for each test case is:

[ \min(#R,,#G) ]

For example, if S = RGRGRG then there are 3 R and 3 G; hence, 3 swaps are needed. If all batons are already the same, no swaps are required.

inputFormat

The input is read from standard input (stdin) and has the following format:

  1. The first line contains an integer T, the number of test cases.
  2. For each test case:
    1. The first line contains an integer N, indicating the number of participants.
    2. The second line contains a string S of length N composed of the characters R and G.

outputFormat

For each test case, print a single line to standard output (stdout) containing the minimum number of swaps required to make all batons the same type.

## sample
3
6
RGRGRG
4
GGGR
5
RRRRR
3

1 0

</p>