#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 */
char getchar();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int t;
  scanf("%d\n", &t);
  int i, holes;
  char c;
  for (i = 0; i < t; i++) {
    holes = 0;
    do {
      c = getchar();
      if (c == 'B') {
        holes += 2;
      } else if (c == 'A' || c == 'D' || c == 'O' || c == 'P' || c == 'Q' ||
                 c == 'R') {
        holes += 1;
      } else {
      }
    } while (c != '\n');
    printf("%d\n", holes);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1223 <main+0xf3>
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x42,%eax
jne    118e <main+0x5e>
mov    -0x10(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x10(%rbp)
jmp    11f4 <main+0xc4>
movsbl -0x11(%rbp),%eax
cmp    $0x41,%eax
je     11dc <main+0xac>
movsbl -0x11(%rbp),%eax
cmp    $0x44,%eax
je     11dc <main+0xac>
movsbl -0x11(%rbp),%eax
cmp    $0x4f,%eax
je     11dc <main+0xac>
movsbl -0x11(%rbp),%eax
cmp    $0x50,%eax
je     11dc <main+0xac>
movsbl -0x11(%rbp),%eax
cmp    $0x51,%eax
je     11dc <main+0xac>
movsbl -0x11(%rbp),%eax
cmp    $0x52,%eax
jne    11ea <main+0xba>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11ef <main+0xbf>
jmp    11ef <main+0xbf>
jmp    11f4 <main+0xc4>
jmp    11f9 <main+0xc9>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
jne    1169 <main+0x39>
mov    -0x10(%rbp),%esi
lea    0xdf0(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1156 <main+0x26>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xec2(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jle    11aa <main+0x7a>
lea    0xeaa(%rip),%r14
mov    $0x3c009,%ebx
xor    %r15d,%r15d
jmp    1175 <main+0x45>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
add    $0x1,%r15d
cmp    0x4(%rsp),%r15d
jge    11aa <main+0x7a>
xor    %ebp,%ebp
jmp    1187 <main+0x57>
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    $0xa,%al
je     1160 <main+0x30>
xor    %eax,%eax
call   1040 <getchar@plt>
lea    -0x41(%rax),%ecx
cmp    $0x11,%cl
ja     1183 <main+0x53>
movzbl %cl,%ecx
bt     %rcx,%rbx
jb     1180 <main+0x50>
cmp    $0x1,%rcx
jne    1183 <main+0x53>
add    $0x2,%ebp
jmp    1183 <main+0x53>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 0, i32* %1
%6 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 0, i32* %3
br label %7
7: ; preds = %57, %0
%8 = load i32, i32* %3
%9 = load i32, i32* %2
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %60
11: ; preds = %7
store i32 0, i32* %4
br label %12
12: ; preds = %50, %11
%13 = call signext i8 (...) @getchar()
store i8 %13, i8* %5
%14 = load i8, i8* %5
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 66
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 2
store i32 %19, i32* %4
br label %49
20: ; preds = %12
%21 = load i8, i8* %5
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 65
br i1 %23, label %44, label %24
24: ; preds = %20
%25 = load i8, i8* %5
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 68
br i1 %27, label %44, label %28
28: ; preds = %24
%29 = load i8, i8* %5
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 79
br i1 %31, label %44, label %32
32: ; preds = %28
%33 = load i8, i8* %5
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 80
br i1 %35, label %44, label %36
36: ; preds = %32
%37 = load i8, i8* %5
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 81
br i1 %39, label %44, label %40
40: ; preds = %36
%41 = load i8, i8* %5
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 82
br i1 %43, label %44, label %47
44: ; preds = %40, %36, %32, %28, %24, %20
%45 = load i32, i32* %4
%46 = add nsw i32 %45, 1
store i32 %46, i32* %4
br label %48
47: ; preds = %40
br label %48
48: ; preds = %47, %44
br label %49
49: ; preds = %48, %17
br label %50
50: ; preds = %49
%51 = load i8, i8* %5
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 10
br i1 %53, label %12, label %54
54: ; preds = %50
%55 = load i32, i32* %4
%56 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %54
%58 = load i32, i32* %3
%59 = add nsw i32 %58, 1
store i32 %59, i32* %3
br label %7
60: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %23
6: ; preds = %0, %18
%7 = phi i32 [ %20, %18 ], [ 0, %0 ]
br label %8
8: ; preds = %6, %15
%9 = phi i32 [ %16, %15 ], [ 0, %6 ]
%10 = call signext i8 (...) @getchar()
switch i8 %10, label %15 [
i8 66, label %11
i8 82, label %13
i8 81, label %13
i8 80, label %13
i8 79, label %13
i8 68, label %13
i8 65, label %13
]
11: ; preds = %8
%12 = add nsw i32 %9, 2
br label %15
13: ; preds = %8, %8, %8, %8, %8, %8
%14 = add nsw i32 %9, 1
br label %15
15: ; preds = %8, %11, %13
%16 = phi i32 [ %12, %11 ], [ %14, %13 ], [ %9, %8 ]
%17 = icmp eq i8 %10, 10
br i1 %17, label %18, label %8
18: ; preds = %15
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %16)
%20 = add nuw nsw i32 %7, 1
%21 = load i32, i32* %1
%22 = icmp slt i32 %20, %21
br i1 %22, label %6, label %23
23: ; preds = %18, %0
ret i32 0
}