import java.util.Scanner;
class Solution{
public static void main(String args[]) throws Exception{
Scanner sc = new Scanner(System.in);
int T;
T=sc.nextInt();
for(int test_case = 1; test_case <= T; test_case++){
char[] c = sc.next().toCharArray();
char temp = '0';
int count = 0;
for(int i = 0 ; i < c.length ; i++){
if(c[i] != temp){
temp =c[i];
count ++;
}
}
System.out.println("#"+test_case + " " + count);
}
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Test_2751 {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int TC = Integer.parseInt(br.readLine());
StringBuilder sb = new StringBuilder();
for(int testCase = 1; testCase <= TC; testCase++) {
String val = br.readLine();
int cnt = 0;
char pre = '0';
for (int i = 0 ; i< val.length(); i++) {
if (pre != val.charAt(i)) {
cnt++;
pre=val.charAt(i);
}
}
sb.append('#').append(testCase).append(" ").append(cnt).append("\n");
}
System.out.print(sb);
}
}