#P3819. A and B Problem

    ID: 2697 远端评测题 1000ms 32MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>The 6th Central China Invitational Programming Contest and 9th Wuhan University Programming Contest Final

A and B Problem

Problem 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.

3 AABB ABAB AABABA
Case 1: 0 Case 2: 1 Case 3: 1

Author

iSea@WHU