#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 findgirl(char);
scalar_t__ scanf(char *, ...);
int main() {
  int n, s;
  scanf("%d", &n);
  for (int a = 1; a <= n && scanf("%d", &s); a++) {
    char stud[s * 2 + 1];
    scanf("%s", s);
    for (int b = 0; stud[b] != '\0'; s++) {
      if (stud[b] == 'B')
        if (stud[b + 1] == 'B') {
          int pos = findgirl(stud[b]);
          char g = stud[pos];
          stud[pos] = stud[b];
          stud[b] = stud[pos];
        }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
xor    %eax,%eax
cmp    -0x8(%rbp),%ecx
mov    %al,-0x2a(%rbp)
jg     1175 <main+0x55>
lea    0xea0(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
test   $0x1,%al
jne    1185 <main+0x65>
jmp    127a <main+0x15a>
mov    -0xc(%rbp),%ecx
mov    %ecx,%eax
lea    0x1(%rax,%rax,1),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1265 <main+0x145>
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x42,%eax
jne    1252 <main+0x132>
mov    -0x38(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x42,%eax
jne    124d <main+0x12d>
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <findgirl@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,-0x28(%rbp)
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    %cl,-0x29(%rbp)
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
movslq -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1252 <main+0x132>
jmp    1257 <main+0x137>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c9 <main+0xa9>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1148 <main+0x28>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xecb(%rip),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,-0x30(%rbp)
jle    11ea <main+0xca>
mov    $0x1,%r13d
xor    %ebx,%ebx
lea    -0x2c(%rbp),%r12
jmp    1170 <main+0x50>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rsp
lea    0x1(%r13),%eax
cmp    -0x30(%rbp),%r13d
mov    %eax,%r13d
jge    11ea <main+0xca>
lea    0xe89(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
test   %rax,%rax
je     11ea <main+0xca>
mov    %rsp,%r15
mov    -0x2c(%rbp),%eax
add    %eax,%eax
add    $0x1,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r14
sub    %rax,%r14
mov    %r14,%rsp
mov    -0x2c(%rbp),%esi
lea    0xe57(%rip),%rdi
xor    %eax,%eax
call   1040 <scanf@plt>
jmp    11c8 <main+0xa8>
cs nopw 0x0(%rax,%rax,1)
nop
test   %bl,%bl
je     1160 <main+0x40>
addl   $0x1,-0x2c(%rbp)
test   %bl,%bl
je     11c0 <main+0xa0>
cmpb   $0x42,0x1(%r14)
jne    11c4 <main+0xa4>
mov    $0x42,%edi
call   1030 <findgirl@plt>
cltq
movb   $0x42,(%r14,%rax,1)
movb   $0x42,(%r14)
jmp    11c4 <main+0xa4>
xor    %eax,%eax
lea    -0x28(%rbp),%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"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i32 0, i32* %1
%10 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 1, i32* %4
br label %11
11: ; preds = %82, %0
%12 = load i32, i32* %4
%13 = load i32, i32* %2
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%17 = icmp ne i64 %16, 0
br label %18
18: ; preds = %15, %11
%19 = phi i1 [ false, %11 ], [ %17, %15 ]
br i1 %19, label %20, label %85
20: ; preds = %18
%21 = load i32, i32* %3
%22 = mul nsw i32 %21, 2
%23 = add nsw i32 %22, 1
%24 = zext i32 %23 to i64
%25 = call i8* @llvm.stacksave()
store i8* %25, i8** %5
%26 = alloca i8, i64 %24
store i64 %24, i64* %6
%27 = load i32, i32* %3
%28 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %27)
store i32 0, i32* %7
br label %29
29: ; preds = %77, %20
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %26, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %80
36: ; preds = %29
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %26, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 66
br i1 %42, label %43, label %76
43: ; preds = %36
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %26, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 66
br i1 %50, label %51, label %75
51: ; preds = %43
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %26, i64 %53
%55 = load i8, i8* %54
%56 = call i32 @findgirl(i8 signext %55)
store i32 %56, i32* %8
%57 = load i32, i32* %8
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %26, i64 %58
%60 = load i8, i8* %59
store i8 %60, i8* %9
%61 = load i32, i32* %7
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %26, i64 %62
%64 = load i8, i8* %63
%65 = load i32, i32* %8
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %26, i64 %66
store i8 %64, i8* %67
%68 = load i32, i32* %8
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %26, i64 %69
%71 = load i8, i8* %70
%72 = load i32, i32* %7
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %26, i64 %73
store i8 %71, i8* %74
br label %75
75: ; preds = %51, %43
br label %76
76: ; preds = %75, %36
br label %77
77: ; preds = %76
%78 = load i32, i32* %3
%79 = add nsw i32 %78, 1
store i32 %79, i32* %3
br label %29
80: ; preds = %29
%81 = load i8*, i8** %5
br label %82
82: ; preds = %80
%83 = load i32, i32* %4
%84 = add nsw i32 %83, 1
store i32 %84, i32* %4
br label %11
85: ; preds = %18
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i64 (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 slt i32 %6, 1
br i1 %7, label %12, label %8
8: ; preds = %0, %24
%9 = phi i32 [ %25, %24 ], [ 1, %0 ]
%10 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8, %24, %0
ret i32 0
13: ; preds = %8
%14 = load i32, i32* %2
%15 = shl nsw i32 %14, 1
%16 = or i32 %15, 1
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
%19 = alloca i8, i64 %17
%20 = load i32, i32* %2
%21 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds i8, i8* %19, i64 1
br label %23
23: ; preds = %35, %13
switch i8 undef, label %35 [
i8 0, label %24
i8 66, label %28
]
24: ; preds = %23
%25 = add nuw nsw i32 %9, 1
%26 = load i32, i32* %1
%27 = icmp slt i32 %9, %26
br i1 %27, label %8, label %12
28: ; preds = %23
%29 = load i8, i8* %22
%30 = icmp eq i8 %29, 66
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = call i32 @findgirl(i8 signext 66)
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %19, i64 %33
store i8 66, i8* %34
store i8 66, i8* %19
br label %35
35: ; preds = %23, %31, %28
%36 = load i32, i32* %2
%37 = add nsw i32 %36, 1
store i32 %37, i32* %2
br label %23
}