#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 /*<<< orphan*/ scanf(char *, ...);
int strcmp(char *, char *);
int main() {
  int t = 0, n = 0, k = 0, i = 0;
  char turn[40][50], road[40][50];
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (i = 0; i < n; i++)
      scanf("%s %[^\n]%*c", turn[i], road[i]);
    for (i = n - 1; i >= 0; i--) {
      if (i == (n - 1))
        printf("Begin %s", road[i]);
      else {
        k = strcmp(turn[i + 1], "Left");
        if (k != 0)
          printf("Left %s", road[i]);
        else
          printf("Right %s", road[i]);
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfc0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe9b(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     12da <main+0x1aa>
lea    0xe75(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e9 <main+0xb9>
movslq -0x14(%rbp),%rax
lea    -0x7f0(%rbp),%rsi
imul   $0x32,%rax,%rax
add    %rax,%rsi
movslq -0x14(%rbp),%rax
lea    -0xfc0(%rbp),%rdx
imul   $0x32,%rax,%rax
add    %rax,%rdx
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119d <main+0x6d>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     12c7 <main+0x197>
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1232 <main+0x102>
movslq -0x14(%rbp),%rax
lea    -0xfc0(%rbp),%rsi
imul   $0x32,%rax,%rax
add    %rax,%rsi
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ab <main+0x17b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
lea    -0x7f0(%rbp),%rdi
imul   $0x32,%rax,%rax
add    %rax,%rdi
lea    0xdc9(%rip),%rsi
call   1040 <strcmp@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1286 <main+0x156>
movslq -0x14(%rbp),%rax
lea    -0xfc0(%rbp),%rsi
imul   $0x32,%rax,%rax
add    %rax,%rsi
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a6 <main+0x176>
movslq -0x14(%rbp),%rax
lea    -0xfc0(%rbp),%rsi
imul   $0x32,%rax,%rax
add    %rax,%rsi
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ab <main+0x17b>
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11f2 <main+0xc2>
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1170 <main+0x40>
xor    %eax,%eax
add    $0xfc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xfb8,%rsp
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xe98(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
subl   $0x1,0xc(%rsp)
jae    118f <main+0x4f>
xor    %eax,%eax
add    $0xfb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe6d(%rip),%r14
lea    0xe72(%rip),%r12
lea    0xe74(%rip),%r13
jmp    11c1 <main+0x81>
cs nopw 0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
subl   $0x1,0xc(%rsp)
jb     117b <main+0x3b>
lea    0xe38(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11b0 <main+0x70>
lea    0x10(%rsp),%r15
lea    0x7e0(%rsp),%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%rbp
movslq 0x8(%rsp),%rax
add    $0x32,%rbx
add    $0x32,%r15
cmp    %rax,%rbp
jl     11f0 <main+0xb0>
test   %eax,%eax
jle    11b0 <main+0x70>
mov    %eax,%ebx
imul   $0x32,%rbx,%rcx
lea    (%rsp,%rcx,1),%r15
add    $0x7e0,%r15
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rbx),%rbp
mov    %eax,%eax
cmp    %rax,%rbx
jne    1250 <main+0x110>
mov    %ebp,%eax
imul   $0x32,%rax,%rax
lea    (%rsp,%rax,1),%rsi
add    $0x10,%rsi
mov    %r12,%rdi
jmp    1280 <main+0x140>
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r13,%rsi
call   1050 <strcmp@plt>
mov    %ebp,%ecx
imul   $0x32,%rcx,%rcx
lea    (%rsp,%rcx,1),%rsi
add    $0x10,%rsi
test   %eax,%eax
je     1276 <main+0x136>
lea    0xda9(%rip),%rdi
jmp    1280 <main+0x140>
lea    0xda8(%rip),%rdi
nopl   (%rax)
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmp    $0x2,%rbx
jb     11b0 <main+0x70>
mov    0x8(%rsp),%eax
add    $0xffffffffffffffce,%r15
mov    %rbp,%rbx
jmp    1230 <main+0xf0>

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

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