#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 cases, char_count;
  register int i;
  char text[100], *c;
  scanf("%d", &cases);
  for (i = 0; i < cases; i++) {
    scanf("%s", &text);
    c = &text[0];
    char_count = 0;
    while (*c != '\0') {
      if (*c == 'A' || *c == 'D' || *c == 'O' || *c == 'P' || *c == 'Q' ||
          *c == 'R')
        char_count++;
      else if (*c == 'B')
        char_count += 2;
      c++;
    }
    printf("%d\n", char_count);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1263 <main+0x143>
lea    0xea5(%rip),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    -0x80(%rbp),%rax
mov    %rax,-0x88(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x88(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1246 <main+0x126>
mov    -0x88(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x41,%eax
je     1200 <main+0xe0>
mov    -0x88(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x44,%eax
je     1200 <main+0xe0>
mov    -0x88(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x4f,%eax
je     1200 <main+0xe0>
mov    -0x88(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x50,%eax
je     1200 <main+0xe0>
mov    -0x88(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x51,%eax
je     1200 <main+0xe0>
mov    -0x88(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x52,%eax
jne    120e <main+0xee>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    122f <main+0x10f>
mov    -0x88(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x42,%eax
jne    122a <main+0x10a>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    122f <main+0x10f>
mov    -0x88(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x88(%rbp)
jmp    117b <main+0x5b>
mov    -0xc(%rbp),%esi
lea    0xdb6(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114b <main+0x2b>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
lea    0xecb(%rip),%rdi
xor    %r13d,%r13d
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11d0 <main+0xb0>
lea    0x10(%rsp),%r12
lea    0xea8(%rip),%r14
lea    0xea4(%rip),%r15
mov    $0x3c009,%ebx
jmp    1185 <main+0x65>
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
add    $0x1,%r13d
cmp    0xc(%rsp),%r13d
jge    11d0 <main+0xb0>
xor    %ebp,%ebp
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %r12,%rax
jmp    11a7 <main+0x87>
nopl   0x0(%rax)
add    $0x1,%ebp
add    $0x1,%rax
movzbl (%rax),%ecx
lea    -0x41(%rcx),%edx
cmp    $0x11,%dl
ja     11c6 <main+0xa6>
movzbl %dl,%edx
bt     %rdx,%rbx
jb     11a0 <main+0x80>
cmp    $0x1,%rdx
jne    11c6 <main+0xa6>
add    $0x2,%ebp
jmp    11ca <main+0xaa>
test   %cl,%cl
je     1170 <main+0x50>
add    $0x1,%rax
jmp    11a7 <main+0x87>
xor    %eax,%eax
add    $0x78,%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 [100 x i8]
%6 = alloca 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* %4
br label %8
8: ; preds = %68, %0
%9 = load i32, i32* %4
%10 = load i32, i32* %2
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %71
12: ; preds = %8
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), [100 x i8]* %5)
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
store i8* %14, i8** %6
store i32 0, i32* %3
br label %15
15: ; preds = %62, %12
%16 = load i8*, i8** %6
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %65
20: ; preds = %15
%21 = load i8*, i8** %6
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 65
br i1 %24, label %50, label %25
25: ; preds = %20
%26 = load i8*, i8** %6
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 68
br i1 %29, label %50, label %30
30: ; preds = %25
%31 = load i8*, i8** %6
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 79
br i1 %34, label %50, label %35
35: ; preds = %30
%36 = load i8*, i8** %6
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 80
br i1 %39, label %50, label %40
40: ; preds = %35
%41 = load i8*, i8** %6
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 81
br i1 %44, label %50, label %45
45: ; preds = %40
%46 = load i8*, i8** %6
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 82
br i1 %49, label %50, label %53
50: ; preds = %45, %40, %35, %30, %25, %20
%51 = load i32, i32* %3
%52 = add nsw i32 %51, 1
store i32 %52, i32* %3
br label %62
53: ; preds = %45
%54 = load i8*, i8** %6
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 66
br i1 %57, label %58, label %61
58: ; preds = %53
%59 = load i32, i32* %3
%60 = add nsw i32 %59, 2
store i32 %60, i32* %3
br label %61
61: ; preds = %58, %53
br label %62
62: ; preds = %61, %50
%63 = load i8*, i8** %6
%64 = getelementptr inbounds i8, i8* %63, i32 1
store i8* %64, i8** %6
br label %15
65: ; preds = %15
%66 = load i32, i32* %3
%67 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %66)
br label %68
68: ; preds = %65
%69 = load i32, i32* %4
%70 = add nsw i32 %69, 1
store i32 %70, i32* %4
br label %8
71: ; 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 [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 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %27
8: ; preds = %0, %22
%9 = phi i32 [ %24, %22 ], [ 0, %0 ]
%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 = %19, %8
%12 = phi i32 [ 0, %8 ], [ %20, %19 ]
%13 = phi i8* [ %4, %8 ], [ %21, %19 ]
%14 = load i8, i8* %13
switch i8 %14, label %19 [
i8 0, label %22
i8 65, label %15
i8 68, label %15
i8 79, label %15
i8 80, label %15
i8 81, label %15
i8 82, label %15
i8 66, label %17
]
15: ; preds = %11, %11, %11, %11, %11, %11
%16 = add nsw i32 %12, 1
br label %19
17: ; preds = %11
%18 = add nsw i32 %12, 2
br label %19
19: ; preds = %11, %17, %15
%20 = phi i32 [ %16, %15 ], [ %18, %17 ], [ %12, %11 ]
%21 = getelementptr inbounds i8, i8* %13, i64 1
br label %11
22: ; preds = %11
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%24 = add nuw nsw i32 %9, 1
%25 = load i32, i32* %1
%26 = icmp slt i32 %24, %25
br i1 %26, label %8, label %27
27: ; preds = %22, %0
ret i32 0
}