#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 main() {
  int t, i, j, holes;
  char arr[40][100];
  scanf("%d", &t);
  for (i = 0; i < t; i++) {
    scanf("%s", arr[i]);
    holes = 0;
    for (j = 0; arr[i][j]; j++) {
      switch (arr[i][j]) {
      case 'A':
      case 'D':
      case 'O':
      case 'P':
      case 'R':
      case 'Q':
        holes++;
        break;
      case 'B':
        holes += 2;
        break;
      default:
        break;
      }
    }
    printf("%d\n", holes);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfd0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1261 <main+0x141>
movslq -0xc(%rbp),%rax
lea    -0xfc0(%rbp),%rsi
imul   $0x64,%rax,%rax
add    %rax,%rsi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
movslq -0xc(%rbp),%rcx
lea    -0xfc0(%rbp),%rax
imul   $0x64,%rcx,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1244 <main+0x124>
movslq -0xc(%rbp),%rax
imul   $0x64,%rax,%rax
lea    -0xfc0(%rbp,%rax,1),%rcx
ff
movslq -0x10(%rbp),%rax
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0xfc4(%rbp)
sub    $0x41,%eax
je     1210 <main+0xf0>
jmp    11d1 <main+0xb1>
mov    -0xfc4(%rbp),%eax
sub    $0x42,%eax
je     121e <main+0xfe>
jmp    11e5 <main+0xc5>
mov    -0xfc4(%rbp),%eax
sub    $0x44,%eax
je     1210 <main+0xf0>
jmp    11f9 <main+0xd9>
mov    -0xfc4(%rbp),%eax
add    $0xffffffb1,%eax
sub    $0x3,%eax
ja     122c <main+0x10c>
jmp    1210 <main+0xf0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1231 <main+0x111>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    1231 <main+0x111>
jmp    1231 <main+0x111>
jmp    1236 <main+0x116>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1185 <main+0x65>
mov    -0x14(%rbp),%esi
lea    0xdb8(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114b <main+0x2b>
xor    %eax,%eax
add    $0xfd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xfb8,%rsp
lea    0xec8(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11e8 <main+0xc8>
lea    0x11(%rsp),%r12
lea    0xea8(%rip),%r14
lea    0xea4(%rip),%r15
mov    $0x3c009,%ebp
xor    %r13d,%r13d
jmp    118a <main+0x6a>
nopl   0x0(%rax)
mov    %r15,%rdi
call   1030 <printf@plt>
add    $0x1,%r13
movslq 0xc(%rsp),%rax
add    $0x64,%r12
cmp    %rax,%r13
jge    11e8 <main+0xc8>
imul   $0x64,%r13,%rbx
lea    (%rsp,%rbx,1),%rsi
add    $0x10,%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x10(%rsp,%rbx,1),%cl
mov    $0x0,%esi
test   %cl,%cl
je     1170 <main+0x50>
xor    %esi,%esi
mov    %r12,%rax
jmp    11ce <main+0xae>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%esi
movzbl (%rax),%ecx
add    $0x1,%rax
test   %cl,%cl
je     1170 <main+0x50>
movsbl %cl,%ecx
add    $0xffffffbf,%ecx
cmp    $0x11,%ecx
ja     11c3 <main+0xa3>
bt     %ecx,%ebp
jb     11c0 <main+0xa0>
cmp    $0x1,%ecx
jne    11c3 <main+0xa3>
add    $0x2,%esi
jmp    11c3 <main+0xa3>
xor    %eax,%eax
add    $0xfb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
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 i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [40 x [100 x i8]]
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 0, i32* %3
br label %8
8: ; preds = %50, %0
%9 = load i32, i32* %3
%10 = load i32, i32* %2
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %53
12: ; preds = %8
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [40 x [100 x i8]], [40 x [100 x i8]]* %6, i64 0, i64 %14
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %15, i64 0, i64 0
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %16)
store i32 0, i32* %5
store i32 0, i32* %4
br label %18
18: ; preds = %44, %12
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [40 x [100 x i8]], [40 x [100 x i8]]* %6, i64 0, i64 %20
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %21, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 0
br i1 %26, label %27, label %47
27: ; preds = %18
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [40 x [100 x i8]], [40 x [100 x i8]]* %6, i64 0, i64 %29
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %30, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
switch i32 %35, label %42 [
i32 65, label %36
i32 68, label %36
i32 79, label %36
i32 80, label %36
i32 82, label %36
i32 81, label %36
i32 66, label %39
]
36: ; preds = %27, %27, %27, %27, %27, %27
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %43
39: ; preds = %27
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 2
store i32 %41, i32* %5
br label %43
42: ; preds = %27
br label %43
43: ; preds = %42, %39, %36
br label %44
44: ; preds = %43
%45 = load i32, i32* %4
%46 = add nsw i32 %45, 1
store i32 %46, i32* %4
br label %18
47: ; preds = %18
%48 = load i32, i32* %5
%49 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %47
%51 = load i32, i32* %3
%52 = add nsw i32 %51, 1
store i32 %52, i32* %3
br label %8
53: ; preds = %8
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 [40 x [100 x i8]]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [40 x [100 x i8]], [40 x [100 x i8]]* %2, i64 0, i64 0, i64 0
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %36
8: ; preds = %0, %29
%9 = phi i64 [ %32, %29 ], [ 0, %0 ]
%10 = getelementptr inbounds [40 x [100 x i8]], [40 x [100 x i8]]* %2, i64 0, i64 %9, i64 0
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = load i8, i8* %10
%13 = icmp eq i8 %12, 0
br i1 %13, label %29, label %14
14: ; preds = %8, %23
%15 = phi i64 [ %25, %23 ], [ 0, %8 ]
%16 = phi i8 [ %27, %23 ], [ %12, %8 ]
%17 = phi i32 [ %24, %23 ], [ 0, %8 ]
%18 = sext i8 %16 to i32
switch i32 %18, label %23 [
i32 65, label %19
i32 68, label %19
i32 79, label %19
i32 80, label %19
i32 82, label %19
i32 81, label %19
i32 66, label %21
]
19: ; preds = %14, %14, %14, %14, %14, %14
%20 = add nsw i32 %17, 1
br label %23
21: ; preds = %14
%22 = add nsw i32 %17, 2
br label %23
23: ; preds = %19, %21, %14
%24 = phi i32 [ %17, %14 ], [ %22, %21 ], [ %20, %19 ]
%25 = add nuw i64 %15, 1
%26 = getelementptr inbounds [40 x [100 x i8]], [40 x [100 x i8]]* %2, i64 0, i64 %9, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %14
29: ; preds = %23, %8
%30 = phi i32 [ 0, %8 ], [ %24, %23 ]
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = add nuw nsw i64 %9, 1
%33 = load i32, i32* %1
%34 = sext i32 %33 to i64
%35 = icmp slt i64 %32, %34
br i1 %35, label %8, label %36
36: ; preds = %29, %0
ret i32 0
}