#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(void) {
  int testCases;
  int ch = 0;
  int count = 0;
  char str[100];
  scanf("%d", &testCases);
  while (testCases--) {
    scanf("%s", &str);
    while (str[ch] != '\0') {
      if (str[ch] == 'A' || str[ch] == 'D' || str[ch] == 'O' ||
          str[ch] == 'P' || str[ch] == 'Q' || str[ch] == 'R')
        count += 1;
      if (str[ch] == 'B')
        count += 2;
      ch++;
    }
    printf("%d\n", count);
    count = 0;
    ch = 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xeb9(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     124a <main+0x12a>
lea    0xe96(%rip),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movslq -0xc(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     1228 <main+0x108>
movslq -0xc(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0x41,%eax
je     11f6 <main+0xd6>
movslq -0xc(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0x44,%eax
je     11f6 <main+0xd6>
movslq -0xc(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0x4f,%eax
je     11f6 <main+0xd6>
movslq -0xc(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0x50,%eax
je     11f6 <main+0xd6>
movslq -0xc(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0x51,%eax
je     11f6 <main+0xd6>
movslq -0xc(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0x52,%eax
jne    11ff <main+0xdf>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
movslq -0xc(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0x42,%eax
jne    121a <main+0xfa>
mov    -0x10(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1178 <main+0x58>
mov    -0x10(%rbp),%esi
lea    0xdd4(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
jmp    1152 <main+0x32>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x80,%rsp
lea    0xec9(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subl   $0x1,0xc(%rsp)
jae    115d <main+0x3d>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe9f(%rip),%r14
lea    0x10(%rsp),%r12
lea    0xe96(%rip),%r15
mov    $0x3c009,%r13d
jmp    1191 <main+0x71>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
subl   $0x1,0xc(%rsp)
jb     114a <main+0x2a>
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %r12,%rax
jmp    11bf <main+0x9f>
test   %cl,%cl
je     1180 <main+0x60>
nopl   0x0(%rax)
lea    0x2(%rbx),%edx
cmp    $0x42,%cl
cmovne %ebx,%edx
add    $0x1,%rax
mov    %edx,%ebx
movzbl (%rax),%ecx
lea    -0x41(%rcx),%edx
cmp    $0x11,%dl
ja     11a5 <main+0x85>
movzbl %dl,%edx
bt     %rdx,%r13
jae    11a5 <main+0x85>
add    $0x1,%ebx
jmp    11b0 <main+0x90>

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 [100 x i8]
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %7
7: ; preds = %78, %0
%8 = load i32, i32* %2
%9 = add nsw i32 %8, -1
store i32 %9, i32* %2
%10 = icmp ne i32 %8, 0
br i1 %10, label %11, label %81
11: ; preds = %7
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), [100 x i8]* %5)
br label %13
13: ; preds = %75, %11
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %78
20: ; preds = %13
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 65
br i1 %26, label %62, label %27
27: ; preds = %20
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 68
br i1 %33, label %62, label %34
34: ; preds = %27
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 79
br i1 %40, label %62, label %41
41: ; preds = %34
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 80
br i1 %47, label %62, label %48
48: ; preds = %41
%49 = load i32, i32* %3
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %50
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 81
br i1 %54, label %62, label %55
55: ; preds = %48
%56 = load i32, i32* %3
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %57
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 82
br i1 %61, label %62, label %65
62: ; preds = %55, %48, %41, %34, %27, %20
%63 = load i32, i32* %4
%64 = add nsw i32 %63, 1
store i32 %64, i32* %4
br label %65
65: ; preds = %62, %55
%66 = load i32, i32* %3
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %67
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %70, 66
br i1 %71, label %72, label %75
72: ; preds = %65
%73 = load i32, i32* %4
%74 = add nsw i32 %73, 2
store i32 %74, i32* %4
br label %75
75: ; preds = %72, %65
%76 = load i32, i32* %3
%77 = add nsw i32 %76, 1
store i32 %77, i32* %3
br label %13
78: ; preds = %13
%79 = load i32, i32* %4
%80 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %79)
store i32 0, i32* %4
store i32 0, i32* %3
br label %7
81: ; preds = %7
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 [100 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, 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 = add nsw i32 %6, -1
store i32 %7, i32* %1
%8 = icmp eq i32 %6, 0
br i1 %8, label %29, label %9
9: ; preds = %0, %24
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), [100 x i8]* %2)
br label %11
11: ; preds = %18, %9
%12 = phi i64 [ %23, %18 ], [ 0, %9 ]
%13 = phi i32 [ %22, %18 ], [ 0, %9 ]
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %12
%15 = load i8, i8* %14
switch i8 %15, label %18 [
i8 0, label %24
i8 65, label %16
i8 68, label %16
i8 79, label %16
i8 80, label %16
i8 81, label %16
i8 82, label %16
]
16: ; preds = %11, %11, %11, %11, %11, %11
%17 = add nsw i32 %13, 1
br label %18
18: ; preds = %11, %16
%19 = phi i32 [ %17, %16 ], [ %13, %11 ]
%20 = icmp eq i8 %15, 66
%21 = add nsw i32 %19, 2
%22 = select i1 %20, i32 %21, i32 %19
%23 = add nuw i64 %12, 1
br label %11
24: ; preds = %11
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%26 = load i32, i32* %1
%27 = add nsw i32 %26, -1
store i32 %27, i32* %1
%28 = icmp eq i32 %26, 0
br i1 %28, label %29, label %9
29: ; preds = %24, %0
ret i32 0
}