#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 *, long long);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  long long int test, j;
  scanf("%lld", &test);
  for (j = 0; j < test; j++) {
    long long int activity = 0, totalLaddu = 0, i = 0;
    long long int bugCount = 0, rank = 0, bonus = 0, months = 0;
    char origin[30], subActivity[100];
    scanf("%lld", &activity);
    scanf("%s", &origin);
    for (i = 0; i < activity; i++) {
      scanf("%s", &subActivity);
      if (subActivity[0] == 'B') {
        scanf("%lld", &bugCount);
        totalLaddu += bugCount;
      } else if (subActivity[0] == 'C') {
        if (subActivity[8] == 'W') {
          scanf("%lld", &rank);
          if (rank < 21) {
            bonus = 20 - rank;
          }
          totalLaddu += (300 + bonus);
          bonus = 0;
        } else {
          totalLaddu += 50;
        }
      } else {
        totalLaddu += 300;
      }
    }
    if (origin[0] == 'I') {
      months = totalLaddu / 200;
      printf("%ld\n", months);
    } else {
      months = totalLaddu / 400;
      printf("%ld\n", months);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    1323 <main+0x203>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
lea    0xe67(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xe5a(%rip),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    12b7 <main+0x197>
lea    0xe32(%rip),%rdi
lea    -0xe0(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movsbl -0xe0(%rbp),%eax
cmp    $0x42,%eax
jne    1214 <main+0xf4>
lea    0xe08(%rip),%rdi
lea    -0x38(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x38(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    12a1 <main+0x181>
movsbl -0xe0(%rbp),%eax
cmp    $0x43,%eax
jne    128e <main+0x16e>
movsbl -0xd8(%rbp),%eax
cmp    $0x57,%eax
jne    127d <main+0x15d>
lea    0xdc5(%rip),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpq   $0x15,-0x40(%rbp)
jge    125e <main+0x13e>
mov    $0x14,%eax
sub    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
add    $0x12c,%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x48(%rbp)
jmp    1289 <main+0x169>
mov    -0x28(%rbp),%rax
add    $0x32,%rax
mov    %rax,-0x28(%rbp)
jmp    129c <main+0x17c>
mov    -0x28(%rbp),%rax
add    $0x12c,%rax
mov    %rax,-0x28(%rbp)
jmp    12a1 <main+0x181>
jmp    12a6 <main+0x186>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11be <main+0x9e>
movsbl -0x70(%rbp),%eax
cmp    $0x49,%eax
jne    12eb <main+0x1cb>
mov    -0x28(%rbp),%rax
mov    $0xc8,%ecx
cqto
idiv   %rcx
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rsi
lea    0xd27(%rip),%rdi
call   1030 <printf@plt>
jmp    130d <main+0x1ed>
mov    -0x28(%rbp),%rax
mov    $0x190,%ecx
cqto
idiv   %rcx
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rsi
lea    0xd00(%rip),%rdi
call   1030 <printf@plt>
jmp    1312 <main+0x1f2>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    114c <main+0x2c>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
lea    0xec8(%rip),%rdi
lea    0x18(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpq   $0x0,0x18(%rsp)
jle    12a1 <main+0x181>
lea    0xea9(%rip),%r15
lea    0xea7(%rip),%rbx
lea    0x40(%rsp),%r13
xor    %ebp,%ebp
jmp    1196 <main+0x76>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rax
cqto
idiv   %rcx
mov    %rax,%rsi
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
add    $0x1,%rbp
cmp    0x18(%rsp),%rbp
jge    12a1 <main+0x181>
movq   $0x0,(%rsp)
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    %r15,%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %rbx,%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpq   $0x0,(%rsp)
jle    1270 <main+0x150>
xor    %r14d,%r14d
xor    %r12d,%r12d
jmp    11f1 <main+0xd1>
nop
add    %rax,%r12
add    $0x1,%r14
cmp    (%rsp),%r14
jge    1273 <main+0x153>
mov    %rbx,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
movzbl 0x40(%rsp),%ecx
cmp    $0x43,%cl
je     1230 <main+0x110>
mov    $0x12c,%eax
cmp    $0x42,%cl
jne    11e0 <main+0xc0>
mov    %r15,%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x10(%rsp),%rax
jmp    11e0 <main+0xc0>
nopl   0x0(%rax,%rax,1)
mov    $0x32,%eax
cmpb   $0x57,0x48(%rsp)
jne    11e0 <main+0xc0>
mov    %r15,%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x8(%rsp),%rcx
mov    $0x140,%eax
sub    %rcx,%rax
cmp    $0x15,%rcx
mov    $0x12c,%ecx
cmovge %rcx,%rax
jmp    11e0 <main+0xc0>
nopw   0x0(%rax,%rax,1)
xor    %r12d,%r12d
cmpb   $0x49,0x20(%rsp)
mov    $0x190,%ecx
mov    $0xc8,%eax
cmove  %rax,%rcx
mov    %r12,%rax
shr    $0x20,%rax
jne    1170 <main+0x50>
mov    %r12d,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%esi
jmp    117b <main+0x5b>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%lld\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca [30 x i8]
%12 = alloca [100 x i8]
store i32 0, i32* %1
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %2)
store i64 0, i64* %3
br label %14
14: ; preds = %86, %0
%15 = load i64, i64* %3
%16 = load i64, i64* %2
%17 = icmp slt i64 %15, %16
br i1 %17, label %18, label %89
18: ; preds = %14
store i64 0, i64* %4
store i64 0, i64* %5
store i64 0, i64* %6
store i64 0, i64* %7
store i64 0, i64* %8
store i64 0, i64* %9
store i64 0, i64* %10
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %4)
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), [30 x i8]* %11)
store i64 0, i64* %6
br label %21
21: ; preds = %67, %18
%22 = load i64, i64* %6
%23 = load i64, i64* %4
%24 = icmp slt i64 %22, %23
br i1 %24, label %25, label %70
25: ; preds = %21
%26 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), [100 x i8]* %12)
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 66
br i1 %30, label %31, label %36
31: ; preds = %25
%32 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %7)
%33 = load i64, i64* %7
%34 = load i64, i64* %5
%35 = add nsw i64 %34, %33
store i64 %35, i64* %5
br label %66
36: ; preds = %25
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 67
br i1 %40, label %41, label %62
41: ; preds = %36
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 8
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 87
br i1 %45, label %46, label %58
46: ; preds = %41
%47 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %8)
%48 = load i64, i64* %8
%49 = icmp slt i64 %48, 21
br i1 %49, label %50, label %53
50: ; preds = %46
%51 = load i64, i64* %8
%52 = sub nsw i64 20, %51
store i64 %52, i64* %9
br label %53
53: ; preds = %50, %46
%54 = load i64, i64* %9
%55 = add nsw i64 300, %54
%56 = load i64, i64* %5
%57 = add nsw i64 %56, %55
store i64 %57, i64* %5
store i64 0, i64* %9
br label %61
58: ; preds = %41
%59 = load i64, i64* %5
%60 = add nsw i64 %59, 50
store i64 %60, i64* %5
br label %61
61: ; preds = %58, %53
br label %65
62: ; preds = %36
%63 = load i64, i64* %5
%64 = add nsw i64 %63, 300
store i64 %64, i64* %5
br label %65
65: ; preds = %62, %61
br label %66
66: ; preds = %65, %31
br label %67
67: ; preds = %66
%68 = load i64, i64* %6
%69 = add nsw i64 %68, 1
store i64 %69, i64* %6
br label %21
70: ; preds = %21
%71 = getelementptr inbounds [30 x i8], [30 x i8]* %11, i64 0, i64 0
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = icmp eq i32 %73, 73
br i1 %74, label %75, label %80
75: ; preds = %70
%76 = load i64, i64* %5
%77 = sdiv i64 %76, 200
store i64 %77, i64* %10
%78 = load i64, i64* %10
%79 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %78)
br label %85
80: ; preds = %70
%81 = load i64, i64* %5
%82 = sdiv i64 %81, 400
store i64 %82, i64* %10
%83 = load i64, i64* %10
%84 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %83)
br label %85
85: ; preds = %80, %75
br label %86
86: ; preds = %85
%87 = load i64, i64* %3
%88 = add nsw i64 %87, 1
store i64 %88, i64* %3
br label %14
89: ; preds = %14
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%lld\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca [30 x i8]
%6 = alloca [100 x i8]
%7 = bitcast i64* %1 to i8*
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %1)
%9 = load i64, i64* %1
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %57
11: ; preds = %0
%12 = bitcast i64* %2 to i8*
%13 = bitcast i64* %3 to i8*
%14 = bitcast i64* %4 to i8*
%15 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 8
br label %18
18: ; preds = %11, %47
%19 = phi i64 [ 0, %11 ], [ %54, %47 ]
store i64 0, i64* %2
store i64 0, i64* %3
store i64 0, i64* %4
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %2)
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), [30 x i8]* %5)
%22 = load i64, i64* %2
%23 = icmp sgt i64 %22, 0
br i1 %23, label %24, label %47
24: ; preds = %18, %41
%25 = phi i64 [ %44, %41 ], [ 0, %18 ]
%26 = phi i64 [ %43, %41 ], [ 0, %18 ]
%27 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), [100 x i8]* %6)
%28 = load i8, i8* %16
switch i8 %28, label %41 [
i8 66, label %29
i8 67, label %32
]
29: ; preds = %24
%30 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %3)
%31 = load i64, i64* %3
br label %41
32: ; preds = %24
%33 = load i8, i8* %17
%34 = icmp eq i8 %33, 87
br i1 %34, label %35, label %41
35: ; preds = %32
%36 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %4)
%37 = load i64, i64* %4
%38 = icmp slt i64 %37, 21
%39 = sub i64 320, %37
%40 = select i1 %38, i64 %39, i64 300
br label %41
41: ; preds = %24, %32, %29, %35
%42 = phi i64 [ %31, %29 ], [ %40, %35 ], [ 50, %32 ], [ 300, %24 ]
%43 = add nsw i64 %42, %26
%44 = add nuw nsw i64 %25, 1
%45 = load i64, i64* %2
%46 = icmp slt i64 %44, %45
br i1 %46, label %24, label %47
47: ; preds = %41, %18
%48 = phi i64 [ 0, %18 ], [ %43, %41 ]
%49 = load i8, i8* %15
%50 = icmp eq i8 %49, 73
%51 = select i1 %50, i64 200, i64 400
%52 = sdiv i64 %48, %51
%53 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %52)
%54 = add nuw nsw i64 %19, 1
%55 = load i64, i64* %1
%56 = icmp slt i64 %54, %55
br i1 %56, label %18, label %57
57: ; preds = %47, %0
ret i32 0
}