Given a string consisting of only A’s and B’s. We can transform the given string to another string by toggling any character. Thus many transformations of the given string are possible. The task is to find Weight of the maximum weight transformation.
Weight of a sting is calculated using below formula.
Weight of string = Weight of total pairs + weight of single characters - Total number of toggles. Two consecutive characters are considered as pair only if they are different. Weight of a single pair (both character are different) = 4 Weight of a single character = 1
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains an integer N denoting the length of string.
The second line of each test case contains the string containing only 'A' and 'B'.
Print the weight of the maximum weight transformation for each test case in a new line.
1<= T <=100
1<= N <=1000
Input: str = "AA" Output: 3 Transformations of given string are "AA", "AB", "BA" and "BB". Maximum weight transformation is "AB" or "BA". And weight is "One Pair - One Toggle" = 4-1 = 3. Input: str = "ABB" Output: 5 Transformations are "ABB", "ABA", "AAB", "AAA", "BBB", "BBA", "BAB" and "BAA" Maximum weight is of original string 4+1 (One Pair + 1 character)