You are given a string containing characters  and  only. Your task is to change it into a string such that every two consecutive characters are different. To do this, you are allowed to delete one or more characters in the string.

Your task is to find the minimum number of required deletions.

Input Format

The first line contains an integer , the number of test cases.
The next  lines contain a string .

Constraints

  • Each string  will consist only of characters  and 

Output Format

For each test case, print the minimum number of deletions required in a new line.

Sample Input

5
AAAA
BBBBB
ABABABAB
BABABA
AAABBB

Sample Output

3
4
0
0
4

Explanation

The characters marked red are the ones that can be deleted so that the string doesn’t have matching consecutive characters.

image

using System;
using System.Text;
class Solution {

    static int alternatingCharacters(string s){
        // Complete this function
            int deletecount = 0;
            StringBuilder str = new StringBuilder();
            str.Append(s[0]);
            for (int i = 1; i < s.Length; i++)
            {
                if (s[i - 1] == s[i])
                    deletecount++;
                else
                    str.Append(s[i]);
            }

            return deletecount;
    }

    static void Main(String[] args) {
        int q = Convert.ToInt32(Console.ReadLine());
        for(int a0 = 0; a0 < q; a0++){
            string s = Console.ReadLine();
            int result = alternatingCharacters(s);
            Console.WriteLine(result);
        }
    }
}