#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() {
  int lns, count, i;
  char ch;
  scanf("%d", &lns);
  getchar();
  while (lns--) {
    count = 0;
    while ((ch = getchar()) != '\n') {
      if (ch == 'A' || ch == 'D' || ch == 'O' || ch == 'Q' || ch == 'R' ||
          ch == 'P')
        count++;
      else if (ch == 'B')
        count += 2;
    }
    printf("%d\n", count);
  }
  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>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1217 <main+0xe7>
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     1203 <main+0xd3>
movsbl -0x11(%rbp),%eax
cmp    $0x41,%eax
je     11d5 <main+0xa5>
movsbl -0x11(%rbp),%eax
cmp    $0x44,%eax
je     11d5 <main+0xa5>
movsbl -0x11(%rbp),%eax
cmp    $0x4f,%eax
je     11d5 <main+0xa5>
movsbl -0x11(%rbp),%eax
cmp    $0x51,%eax
je     11d5 <main+0xa5>
movsbl -0x11(%rbp),%eax
cmp    $0x52,%eax
je     11d5 <main+0xa5>
movsbl -0x11(%rbp),%eax
cmp    $0x50,%eax
jne    11e3 <main+0xb3>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11fe <main+0xce>
movsbl -0x11(%rbp),%eax
cmp    $0x42,%eax
jne    11f9 <main+0xc9>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    11fe <main+0xce>
jmp    1171 <main+0x41>
mov    -0xc(%rbp),%esi
lea    0xdf6(%rip),%rdi
call   1030 <printf@plt>
jmp    1156 <main+0x26>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xfe5(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
subl   $0x1,0xc(%rsp)
jae    1162 <main+0x32>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe97(%rip),%rbx
lea    0xfb7(%rip),%r14
xor    %ebp,%ebp
jmp    1180 <main+0x50>
add    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getchar@plt>
add    $0xf6,%al
cmp    $0x48,%al
ja     1180 <main+0x50>
movzbl %al,%eax
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
jmp    *%rax
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
subl   $0x1,0xc(%rsp)
mov    $0x0,%ebp
jae    1180 <main+0x50>
jmp    1157 <main+0x27>
add    $0x2,%ebp
jmp    1180 <main+0x50>

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

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