Given a string containing characters A and B only, he wants to change it into a string he likes.

Strings in which consecutive characters are different. For example, he likes ABABA, while he doesn’t like ABAA. Given a string containing characters A and B only, he wants to change it into a string he likes. To do this, he is allowed to delete the characters in the string. Your task is to find the minimum number of required deletions.

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int T;
String str;
int d=0;
T=sc.nextInt();

if(T<=10&&T>0)
{

for(int k=0;k<T;k++){
str=sc.next();

for(int i=0;i<(str.length()-1);)
{
char ch=str.charAt(i);

int j=i+1;
while((j<str.length())&&str.charAt(j)==ch)
{

d++;
j++;
}
i=j;
}
System.out.println(d);
d=0;
}
}

}
}