#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, ...);
int strlen(char *);
int main() {
  int T;
  scanf("%d", &T);
  while (T-- > 0) {
    char str[1000000 + 1];
    scanf("%s", str);
    int length = strlen(str);
    int total = 0;
    char previous = str[0];
    for (int i = 1; i < length; i++) {
      if (previous == str[i]) {
        total++;
      } else {
        previous = str[i];
      }
    }
    printf("%d\n", total);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf4260,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
jle    1237 <main+0x107>
lea    -0xf4250(%rbp),%rsi
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    -0xf4250(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xf4254(%rbp)
movl   $0x0,-0xf4258(%rbp)
mov    -0xf4250(%rbp),%al
mov    %al,-0xf4259(%rbp)
movl   $0x1,-0xf4260(%rbp)
mov    -0xf4260(%rbp),%eax
cmp    -0xf4254(%rbp),%eax
jge    1220 <main+0xf0>
movsbl -0xf4259(%rbp),%eax
movslq -0xf4260(%rbp),%rcx
movsbl -0xf4250(%rbp,%rcx,1),%ecx
ff
cmp    %ecx,%eax
jne    11f3 <main+0xc3>
mov    -0xf4258(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf4258(%rbp)
jmp    1207 <main+0xd7>
movslq -0xf4260(%rbp),%rax
mov    -0xf4250(%rbp,%rax,1),%al
mov    %al,-0xf4259(%rbp)
jmp    120c <main+0xdc>
mov    -0xf4260(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf4260(%rbp)
jmp    11af <main+0x7f>
mov    -0xf4258(%rbp),%esi
lea    0xdd9(%rip),%rdi
call   1040 <printf@plt>
jmp    1154 <main+0x24>
xor    %eax,%eax
add    $0xf4260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xf4258,%rsp
lea    0xedb(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
test   %eax,%eax
jle    12ff <main+0x1cf>
lea    0xeb8(%rip),%r14
lea    0x10(%rsp),%r12
lea    0xeaf(%rip),%r15
jmp    119b <main+0x6b>
nopl   0x0(%rax)
mov    %r15,%rdi
call   1040 <printf@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
test   %eax,%eax
jle    12ff <main+0x1cf>
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    $0x0,%esi
cmp    $0x2,%eax
jl     1180 <main+0x50>
mov    0x10(%rsp),%bl
mov    %eax,%eax
lea    -0x1(%rax),%rdx
cmp    $0x8,%rdx
jae    11e0 <main+0xb0>
xor    %esi,%esi
mov    $0x1,%ecx
jmp    12e0 <main+0x1b0>
cs nopw 0x0(%rax,%rax,1)
mov    %rdx,%rdi
and    $0xfffffffffffffff8,%rdi
lea    0x1(%rdi),%rcx
movzbl %bl,%esi
movd   %esi,%xmm0
pslld  $0x18,%xmm0
pxor   %xmm1,%xmm1
xor    %esi,%esi
pxor   %xmm2,%xmm2
movdqa 0xdf7(%rip),%xmm6
movdqa 0xdff(%rip),%xmm7
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movd   0x11(%rsp,%rsi,1),%xmm3
movdqa %xmm6,%xmm4
pandn  %xmm0,%xmm4
movd   0x15(%rsp,%rsi,1),%xmm0
movdqa %xmm3,%xmm5
pand   %xmm6,%xmm5
por    %xmm4,%xmm5
punpcklbw %xmm5,%xmm5
pshufd $0x44,%xmm5,%xmm4
pshuflw $0xc7,%xmm4,%xmm4
pshufhw $0xe5,%xmm4,%xmm4
movdqa %xmm6,%xmm5
pandn  %xmm3,%xmm5
punpcklbw %xmm3,%xmm3
punpcklwd %xmm3,%xmm3
pcmpeqb %xmm4,%xmm3
pand   %xmm7,%xmm3
paddd  %xmm3,%xmm1
movdqa %xmm0,%xmm3
pand   %xmm6,%xmm3
por    %xmm5,%xmm3
punpcklbw %xmm3,%xmm3
pshufd $0x44,%xmm3,%xmm3
pshuflw $0xc7,%xmm3,%xmm3
pshufhw $0xe5,%xmm3,%xmm3
movdqa %xmm0,%xmm4
punpcklbw %xmm4,%xmm4
punpcklwd %xmm4,%xmm4
pcmpeqb %xmm3,%xmm4
pand   %xmm7,%xmm4
paddd  %xmm4,%xmm2
add    $0x8,%rsi
cmp    %rsi,%rdi
jne    1220 <main+0xf0>
paddd  %xmm1,%xmm2
pshufd $0xee,%xmm2,%xmm1
paddd  %xmm2,%xmm1
pshufd $0x55,%xmm1,%xmm2
paddd  %xmm1,%xmm2
movd   %xmm2,%esi
cmp    %rdi,%rdx
je     1180 <main+0x50>
movd   %xmm0,%ebx
shr    $0x18,%ebx
nopl   (%rax)
movzbl 0x10(%rsp,%rcx,1),%edx
xor    %edi,%edi
cmp    %dl,%bl
sete   %dil
add    %edi,%esi
add    $0x1,%rcx
mov    %edx,%ebx
cmp    %rcx,%rax
jne    12e0 <main+0x1b0>
jmp    1180 <main+0x50>
xor    %eax,%eax
add    $0xf4258,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1000001 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %9
9: ; preds = %45, %0
%10 = load i32, i32* %2
%11 = add nsw i32 %10, -1
store i32 %11, i32* %2
%12 = icmp sgt i32 %10, 0
br i1 %12, label %13, label %48
13: ; preds = %9
%14 = getelementptr inbounds [1000001 x i8], [1000001 x i8]* %3, i64 0, i64 0
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = getelementptr inbounds [1000001 x i8], [1000001 x i8]* %3, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %4
store i32 0, i32* %5
%18 = getelementptr inbounds [1000001 x i8], [1000001 x i8]* %3, i64 0, i64 0
%19 = load i8, i8* %18
store i8 %19, i8* %6
store i32 1, i32* %7
br label %20
20: ; preds = %42, %13
%21 = load i32, i32* %7
%22 = load i32, i32* %4
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %45
24: ; preds = %20
%25 = load i8, i8* %6
%26 = sext i8 %25 to i32
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [1000001 x i8], [1000001 x i8]* %3, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %26, %31
br i1 %32, label %33, label %36
33: ; preds = %24
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %41
36: ; preds = %24
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [1000001 x i8], [1000001 x i8]* %3, i64 0, i64 %38
%40 = load i8, i8* %39
store i8 %40, i8* %6
br label %41
41: ; preds = %36, %33
br label %42
42: ; preds = %41
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
br label %20
45: ; preds = %20
%46 = load i32, i32* %5
%47 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %46)
br label %9
48: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000001 x i8]
%3 = bitcast i32* %1 to i8*
%4 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = add nsw i32 %5, -1
store i32 %6, i32* %1
%7 = icmp sgt i32 %5, 0
br i1 %7, label %8, label %71
8: ; preds = %0
%9 = getelementptr inbounds [1000001 x i8], [1000001 x i8]* %2, i64 0, i64 0
br label %10
10: ; preds = %8, %54
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%12 = call i32 @strlen(i8* %9)
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %54
14: ; preds = %10
%15 = load i8, i8* %9
%16 = zext i32 %12 to i64
%17 = add nsw i64 %16, -1
%18 = icmp ult i64 %17, 8
br i1 %18, label %50, label %19
19: ; preds = %14
%20 = and i64 %17, -8
%21 = or i64 %20, 1
%22 = insertelement <4 x i8> poison, i8 %15, i64 3
br label %23
23: ; preds = %23, %19
%24 = phi i64 [ 0, %19 ], [ %43, %23 ]
%25 = phi <4 x i8> [ %22, %19 ], [ %34, %23 ]
%26 = phi <4 x i32> [ zeroinitializer, %19 ], [ %41, %23 ]
%27 = phi <4 x i32> [ zeroinitializer, %19 ], [ %42, %23 ]
%28 = or i64 %24, 1
%29 = getelementptr inbounds [1000001 x i8], [1000001 x i8]* %2, i64 0, i64 %28
%30 = bitcast i8* %29 to <4 x i8>*
%31 = load <4 x i8>, <4 x i8>* %30
%32 = getelementptr inbounds i8, i8* %29, i64 4
%33 = bitcast i8* %32 to <4 x i8>*
%34 = load <4 x i8>, <4 x i8>* %33
%35 = shufflevector <4 x i8> %25, <4 x i8> %31, <4 x i32> <i32 3, i32 4, i32 5, i32 6>
%36 = shufflevector <4 x i8> %31, <4 x i8> %34, <4 x i32> <i32 3, i32 4, i32 5, i32 6>
%37 = icmp eq <4 x i8> %35, %31
%38 = icmp eq <4 x i8> %36, %34
%39 = zext <4 x i1> %37 to <4 x i32>
%40 = zext <4 x i1> %38 to <4 x i32>
%41 = add <4 x i32> %26, %39
%42 = add <4 x i32> %27, %40
%43 = add nuw i64 %24, 8
%44 = icmp eq i64 %43, %20
br i1 %44, label %45, label %23
45: ; preds = %23
%46 = add <4 x i32> %42, %41
%47 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %46)
%48 = icmp eq i64 %17, %20
%49 = extractelement <4 x i8> %34, i64 3
br i1 %48, label %54, label %50
50: ; preds = %14, %45
%51 = phi i64 [ %21, %45 ], [ 1, %14 ]
%52 = phi i8 [ %49, %45 ], [ %15, %14 ]
%53 = phi i32 [ %47, %45 ], [ 0, %14 ]
br label %60
54: ; preds = %60, %45, %10
%55 = phi i32 [ 0, %10 ], [ %47, %45 ], [ %68, %60 ]
%56 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %55)
%57 = load i32, i32* %1
%58 = add nsw i32 %57, -1
store i32 %58, i32* %1
%59 = icmp sgt i32 %57, 0
br i1 %59, label %10, label %71
60: ; preds = %50, %60
%61 = phi i64 [ %69, %60 ], [ %51, %50 ]
%62 = phi i8 [ %65, %60 ], [ %52, %50 ]
%63 = phi i32 [ %68, %60 ], [ %53, %50 ]
%64 = getelementptr inbounds [1000001 x i8], [1000001 x i8]* %2, i64 0, i64 %61
%65 = load i8, i8* %64
%66 = icmp eq i8 %62, %65
%67 = zext i1 %66 to i32
%68 = add nuw nsw i32 %63, %67
%69 = add nuw nsw i64 %61, 1
%70 = icmp eq i64 %69, %16
br i1 %70, label %54, label %60
71: ; preds = %54, %0
ret i32 0
}