#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 loop, loop2, i, j, hit = 0;
  scanf("%d", &loop);
  int s[60];
  char c;
  for (i = 0; i < loop; i++) {
    scanf("%d", &loop2);
    for (j = 0; j < loop2; j++) {
      scanf("%d", &s[j]);
    }
    for (j = 0; j < loop2; j++) {
      scanf(" %c", &c);
      if (c == 'J' && s[j] > 2) {
        hit++;
      } else if (c == 'S' && s[j] <= 2) {
        hit++;
      }
    }
    printf("%d\n", hit);
    hit = 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xec0(%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    1270 <main+0x150>
lea    0xe9b(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b1 <main+0x91>
movslq -0x14(%rbp),%rax
lea    -0x110(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1177 <main+0x57>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    124c <main+0x12c>
lea    0xe38(%rip),%rdi
lea    -0x111(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movsbl -0x111(%rbp),%eax
cmp    $0x4a,%eax
jne    1209 <main+0xe9>
movslq -0x14(%rbp),%rax
cmpl   $0x2,-0x110(%rbp,%rax,4)
02
jle    1209 <main+0xe9>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1239 <main+0x119>
movsbl -0x111(%rbp),%eax
cmp    $0x53,%eax
jne    1234 <main+0x114>
movslq -0x14(%rbp),%rax
cmpl   $0x2,-0x110(%rbp,%rax,4)
02
jg     1234 <main+0x114>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1239 <main+0x119>
jmp    123e <main+0x11e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b8 <main+0x98>
mov    -0x18(%rbp),%esi
lea    0xdb1(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1152 <main+0x32>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xec8(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1214 <main+0xf4>
lea    0xeaa(%rip),%r15
lea    0x7(%rsp),%r12
xor    %r13d,%r13d
jmp    117d <main+0x5d>
lea    0xea0(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
add    $0x1,%r13d
cmp    0xc(%rsp),%r13d
jge    1214 <main+0xf4>
xor    %ebp,%ebp
mov    %r15,%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    1160 <main+0x40>
lea    0x10(%rsp),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0x4,%r14
cmp    %rax,%rbx
jl     11a0 <main+0x80>
test   %eax,%eax
lea    0xe3b(%rip),%r14
jle    1160 <main+0x40>
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    11ee <main+0xce>
xor    %eax,%eax
cmpl   $0x3,0x10(%rsp,%rbx,4)
setl   %al
add    %eax,%ebp
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
cmp    %rax,%rbx
jge    1160 <main+0x40>
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
movzbl 0x7(%rsp),%eax
cmp    $0x53,%al
je     11d0 <main+0xb0>
cmp    $0x4a,%al
jne    11dc <main+0xbc>
xor    %eax,%eax
cmpl   $0x3,0x10(%rsp,%rbx,4)
setge  %al
jmp    11da <main+0xba>
xor    %eax,%eax
add    $0x108,%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 = [4 x i8] c" %c\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 i32
%6 = alloca i32
%7 = alloca [60 x i32]
%8 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %6
%9 = 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 %10
10: ; preds = %68, %0
%11 = load i32, i32* %4
%12 = load i32, i32* %2
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %71
14: ; preds = %10
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
store i32 0, i32* %5
br label %16
16: ; preds = %25, %14
%17 = load i32, i32* %5
%18 = load i32, i32* %3
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [60 x i32], [60 x i32]* %7, i64 0, i64 %22
%24 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %23)
br label %25
25: ; preds = %20
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %16
28: ; preds = %16
store i32 0, i32* %5
br label %29
29: ; preds = %62, %28
%30 = load i32, i32* %5
%31 = load i32, i32* %3
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %65
33: ; preds = %29
%34 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%35 = load i8, i8* %8
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 74
br i1 %37, label %38, label %47
38: ; preds = %33
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [60 x i32], [60 x i32]* %7, i64 0, i64 %40
%42 = load i32, i32* %41
%43 = icmp sgt i32 %42, 2
br i1 %43, label %44, label %47
44: ; preds = %38
%45 = load i32, i32* %6
%46 = add nsw i32 %45, 1
store i32 %46, i32* %6
br label %61
47: ; preds = %38, %33
%48 = load i8, i8* %8
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 83
br i1 %50, label %51, label %60
51: ; preds = %47
%52 = load i32, i32* %5
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [60 x i32], [60 x i32]* %7, i64 0, i64 %53
%55 = load i32, i32* %54
%56 = icmp sle i32 %55, 2
br i1 %56, label %57, label %60
57: ; preds = %51
%58 = load i32, i32* %6
%59 = add nsw i32 %58, 1
store i32 %59, i32* %6
br label %60
60: ; preds = %57, %51, %47
br label %61
61: ; preds = %60, %44
br label %62
62: ; preds = %61
%63 = load i32, i32* %5
%64 = add nsw i32 %63, 1
store i32 %64, i32* %5
br label %29
65: ; preds = %29
%66 = load i32, i32* %6
%67 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %66)
store i32 0, i32* %6
br label %68
68: ; preds = %65
%69 = load i32, i32* %4
%70 = add nsw i32 %69, 1
store i32 %70, i32* %4
br label %10
71: ; preds = %10
ret i32 0
}

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