#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() {
  char s[101], c;
  int i, j, num, n;
  scanf("%d", &n);
  for (int j = 0; j < n; j++) {
    scanf("%d", &num);
    scanf("%s", s);
    for (i = 0; i <= 100; i++) {
      c = s[i];
      if (c == '\0') {
        break;
      } else if (c == 'w') {
        num = num + 3;
      } else if (c == 'c') {
        num = num / 2;
        if (num == 0) {
          break;
        }
      }
    }
    printf("%d\n", num);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
lea    -0x84(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%eax
cmp    -0x84(%rbp),%eax
jge    123f <main+0x11f>
lea    0xe96(%rip),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    -0x70(%rbp),%rsi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x78(%rbp)
cmpl   $0x64,-0x78(%rbp)
jg     121c <main+0xfc>
movslq -0x78(%rbp),%rax
mov    -0x70(%rbp,%rax,1),%al
mov    %al,-0x71(%rbp)
movsbl -0x71(%rbp),%eax
cmp    $0x0,%eax
jne    11b5 <main+0x95>
jmp    121c <main+0xfc>
movsbl -0x71(%rbp),%eax
cmp    $0x77,%eax
jne    11d0 <main+0xb0>
mov    -0x80(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x80(%rbp)
jmp    1204 <main+0xe4>
movsbl -0x71(%rbp),%eax
cmp    $0x63,%eax
jne    11ff <main+0xdf>
mov    -0x80(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x80(%rbp)
cmpl   $0x0,-0x80(%rbp)
jne    11fa <main+0xda>
jmp    121c <main+0xfc>
jmp    11ff <main+0xdf>
jmp    1204 <main+0xe4>
jmp    1209 <main+0xe9>
jmp    120e <main+0xee>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    118e <main+0x6e>
mov    -0x80(%rbp),%esi
lea    0xde0(%rip),%rdi
call   1030 <printf@plt>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    1151 <main+0x31>
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
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11fc <main+0xdc>
lea    0xead(%rip),%r14
lea    0x8(%rsp),%r15
lea    0xea4(%rip),%r12
lea    0x10(%rsp),%r13
lea    0xe9b(%rip),%rbx
xor    %ebp,%ebp
jmp    1181 <main+0x61>
nop
mov    %rbx,%rdi
call   1030 <printf@plt>
add    $0x1,%ebp
cmp    0xc(%rsp),%ebp
jge    11fc <main+0xdc>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x8(%rsp),%esi
xor    %eax,%eax
jmp    11c1 <main+0xa1>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x3,%esi
mov    %esi,0x8(%rsp)
add    $0x1,%rax
cmp    $0x65,%rax
je     1170 <main+0x50>
movzbl 0x10(%rsp,%rax,1),%ecx
cmp    $0x63,%cl
je     11e0 <main+0xc0>
cmp    $0x77,%cl
je     11b0 <main+0x90>
test   %cl,%cl
jne    11b7 <main+0x97>
jmp    1170 <main+0x50>
cs nopw 0x0(%rax,%rax,1)
mov    %esi,%ecx
shr    $0x1f,%ecx
add    %esi,%ecx
sar    %ecx
mov    %ecx,0x8(%rsp)
add    $0x1,%esi
cmp    $0x3,%esi
mov    %ecx,%esi
jae    11b7 <main+0x97>
jmp    1170 <main+0x50>
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 [101 x i8]
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
store i32 0, i32* %8
br label %10
10: ; preds = %57, %0
%11 = load i32, i32* %8
%12 = load i32, i32* %7
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %60
14: ; preds = %10
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%16 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %16)
store i32 0, i32* %4
br label %18
18: ; preds = %51, %14
%19 = load i32, i32* %4
%20 = icmp sle i32 %19, 100
br i1 %20, label %21, label %54
21: ; preds = %18
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 %23
%25 = load i8, i8* %24
store i8 %25, i8* %3
%26 = load i8, i8* %3
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %21
br label %54
30: ; preds = %21
%31 = load i8, i8* %3
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 119
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 3
store i32 %36, i32* %6
br label %49
37: ; preds = %30
%38 = load i8, i8* %3
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 99
br i1 %40, label %41, label %48
41: ; preds = %37
%42 = load i32, i32* %6
%43 = sdiv i32 %42, 2
store i32 %43, i32* %6
%44 = load i32, i32* %6
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %41
br label %54
47: ; preds = %41
br label %48
48: ; preds = %47, %37
br label %49
49: ; preds = %48, %34
br label %50
50: ; preds = %49
br label %51
51: ; preds = %50
%52 = load i32, i32* %4
%53 = add nsw i32 %52, 1
store i32 %53, i32* %4
br label %18
54: ; preds = %46, %29, %18
%55 = load i32, i32* %6
%56 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %54
%58 = load i32, i32* %8
%59 = add nsw i32 %58, 1
store i32 %59, i32* %8
br label %10
60: ; preds = %10
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 [101 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = getelementptr inbounds [101 x i8], [101 x i8]* %1, i64 0, i64 0
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %3
%9 = icmp sgt i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %31, %0
ret i32 0
11: ; preds = %0, %31
%12 = phi i32 [ %34, %31 ], [ 0, %0 ]
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%15 = load i32, i32* %2
br label %16
16: ; preds = %11, %27
%17 = phi i64 [ 0, %11 ], [ %29, %27 ]
%18 = phi i32 [ %15, %11 ], [ %28, %27 ]
%19 = getelementptr inbounds [101 x i8], [101 x i8]* %1, i64 0, i64 %17
%20 = load i8, i8* %19
switch i8 %20, label %27 [
i8 0, label %31
i8 119, label %21
i8 99, label %23
]
21: ; preds = %16
%22 = add nsw i32 %18, 3
store i32 %22, i32* %2
br label %27
23: ; preds = %16
%24 = sdiv i32 %18, 2
store i32 %24, i32* %2
%25 = add i32 %18, 1
%26 = icmp ult i32 %25, 3
br i1 %26, label %31, label %27
27: ; preds = %16, %23, %21
%28 = phi i32 [ %18, %16 ], [ %24, %23 ], [ %22, %21 ]
%29 = add nuw nsw i64 %17, 1
%30 = icmp eq i64 %29, 101
br i1 %30, label %31, label %16
31: ; preds = %16, %23, %27
%32 = phi i32 [ %18, %16 ], [ %24, %23 ], [ %28, %27 ]
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = add nuw nsw i32 %12, 1
%35 = load i32, i32* %3
%36 = icmp slt i32 %34, %35
br i1 %36, label %11, label %10
}