A and B Problem

Time Limit: 1000ms
Memory Limit: 32768KB
This problem will be judged on HDU. Original ID: 3819
64-bit integer IO format: %I64d      Java class name: Main

Description

After calculating A + B, let’s consider another easy problem which only contains A and B.
You are given a string s containing only the letters 'A' and 'B'. The letters are arranged in a circle, so the last and first characters are adjacent. You will perform a series of swaps until all the 'A's form one consecutive sequence and all the 'B's form another consecutive sequence. In each swap, you can select any two characters and swap them. Find the minimal number of swaps necessary to reach your goal.

Input

The first line contains a single integer T, indicating the number of test cases.
Each test case only contains a string as description.

Technical Specification

1. 1 <= T <= 100
2. 1 <= |S| <= 100000, |S| indicating the length of the string.

Output

For each test case, output the case number first, then the minimal number of swaps.

Sample Input

3
AABB
ABAB
AABABA

Sample Output

Case 1: 0
Case 2: 1
Case 3: 1

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .