#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*/ getchar();
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ scanf(char *, int *);
scalar_t__ strcasecmp(char *, char *);
int main() {
  int n, temp;
  char str[10];
  while (scanf("%d", &n) && n) {
    getchar();
    int up = 1, down = 6, north = 2, south = 5, west = 3, east = 4;
    while (n--) {
      gets(str);
      if (strcasecmp(str, "north") == 0) {
        temp = up;
        up = south;
        south = down;
        down = north;
        north = temp;
      } else if (strcasecmp(str, "east") == 0) {
        temp = up;
        up = west;
        west = down;
        down = east;
        east = temp;
      } else if (strcasecmp(str, "south") == 0) {
        temp = up;
        up = north;
        north = down;
        down = south;
        south = temp;
      } else if (strcasecmp(str, "west") == 0) {
        temp = up;
        up = east;
        east = down;
        down = west;
        west = temp;
      }
    }
    printf("%d\n", up);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x31(%rbp)
je     118b <main+0x3b>
cmpl   $0x0,-0x8(%rbp)
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    119b <main+0x4b>
jmp    1300 <main+0x1b0>
mov    $0x0,%al
call   1050 <getchar@plt>
movl   $0x1,-0x1c(%rbp)
movl   $0x6,-0x20(%rbp)
movl   $0x2,-0x24(%rbp)
movl   $0x5,-0x28(%rbp)
movl   $0x3,-0x2c(%rbp)
movl   $0x4,-0x30(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     12ec <main+0x19c>
lea    -0x16(%rbp),%rdi
call   1060 <gets@plt>
lea    -0x16(%rbp),%rdi
lea    0xe0f(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1226 <main+0xd6>
mov    -0x1c(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    12e7 <main+0x197>
lea    -0x16(%rbp),%rdi
lea    0xdd8(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1263 <main+0x113>
mov    -0x1c(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    12e2 <main+0x192>
lea    -0x16(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    12a0 <main+0x150>
mov    -0x1c(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    12dd <main+0x18d>
lea    -0x16(%rbp),%rdi
lea    0xd69(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    12d8 <main+0x188>
mov    -0x1c(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    12dd <main+0x18d>
jmp    12e2 <main+0x192>
jmp    12e7 <main+0x197>
jmp    11cc <main+0x7c>
mov    -0x1c(%rbp),%esi
lea    0xd23(%rip),%rdi
call   1040 <printf@plt>
jmp    115f <main+0xf>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe9b(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
test   %rax,%rax
je     12d5 <main+0x185>
cmpl   $0x0,0x4(%rsp)
je     12d5 <main+0x185>
lea    0xe(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getchar@plt>
mov    $0x1,%esi
subl   $0x1,0x4(%rsp)
jae    11e0 <main+0x90>
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
lea    0xe4a(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
test   %rax,%rax
je     12d5 <main+0x185>
cmpl   $0x0,0x4(%rsp)
jne    1190 <main+0x40>
jmp    12d5 <main+0x185>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1,%r12d
mov    $0x6,%r15d
mov    $0x2,%r14d
mov    $0x5,%ebp
movl   $0x3,0x8(%rsp)
mov    $0x4,%r13d
jmp    1232 <main+0xe2>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%esi
mov    %r14d,%eax
mov    %r12d,%r14d
mov    %r15d,%ebp
mov    %r13d,%r15d
subl   $0x1,0x4(%rsp)
mov    %r15d,%r13d
mov    %eax,%r15d
mov    %esi,%r12d
jb     11a3 <main+0x53>
mov    %rbx,%rdi
call   1060 <gets@plt>
mov    %rbx,%rdi
lea    0xdbf(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1210 <main+0xc0>
mov    %rbx,%rdi
lea    0xdb1(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     12a0 <main+0x150>
mov    %rbx,%rdi
lea    0xda2(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     12b4 <main+0x164>
mov    %rbx,%rdi
lea    0xd94(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     12c4 <main+0x174>
mov    %r12d,%esi
mov    %r15d,%eax
jmp    121b <main+0xcb>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x8(%rsp),%esi
mov    %r13d,%eax
mov    %r15d,0x8(%rsp)
mov    %r12d,%r15d
jmp    121e <main+0xce>
mov    %r14d,%esi
mov    %ebp,%eax
mov    %r15d,%r14d
mov    %r12d,%ebp
jmp    121b <main+0xcb>
mov    %r13d,%esi
mov    0x8(%rsp),%eax
mov    %r12d,0x8(%rsp)
jmp    121e <main+0xce>
xor    %eax,%eax
add    $0x18,%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 = [6 x i8] c"north\00"
@.str.2 = [5 x i8] c"east\00"
@.str.3 = [6 x i8] c"south\00"
@.str.4 = [5 x i8] c"west\00"
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
br label %11
11: ; preds = %71, %0
%12 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* %2
%16 = icmp ne i32 %15, 0
br label %17
17: ; preds = %14, %11
%18 = phi i1 [ false, %11 ], [ %16, %14 ]
br i1 %18, label %19, label %74
19: ; preds = %17
%20 = call i32 (...) @getchar()
store i32 1, i32* %5
store i32 6, i32* %6
store i32 2, i32* %7
store i32 5, i32* %8
store i32 3, i32* %9
store i32 4, i32* %10
br label %21
21: ; preds = %70, %19
%22 = load i32, i32* %2
%23 = add nsw i32 %22, -1
store i32 %23, i32* %2
%24 = icmp ne i32 %22, 0
br i1 %24, label %25, label %71
25: ; preds = %21
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%27 = call i32 @gets(i8* %26)
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%29 = call i64 @strcasecmp(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %25
%32 = load i32, i32* %5
store i32 %32, i32* %3
%33 = load i32, i32* %8
store i32 %33, i32* %5
%34 = load i32, i32* %6
store i32 %34, i32* %8
%35 = load i32, i32* %7
store i32 %35, i32* %6
%36 = load i32, i32* %3
store i32 %36, i32* %7
br label %70
37: ; preds = %25
%38 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%39 = call i64 @strcasecmp(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %37
%42 = load i32, i32* %5
store i32 %42, i32* %3
%43 = load i32, i32* %9
store i32 %43, i32* %5
%44 = load i32, i32* %6
store i32 %44, i32* %9
%45 = load i32, i32* %10
store i32 %45, i32* %6
%46 = load i32, i32* %3
store i32 %46, i32* %10
br label %69
47: ; preds = %37
%48 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%49 = call i64 @strcasecmp(i8* %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %57
51: ; preds = %47
%52 = load i32, i32* %5
store i32 %52, i32* %3
%53 = load i32, i32* %7
store i32 %53, i32* %5
%54 = load i32, i32* %6
store i32 %54, i32* %7
%55 = load i32, i32* %8
store i32 %55, i32* %6
%56 = load i32, i32* %3
store i32 %56, i32* %8
br label %68
57: ; preds = %47
%58 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%59 = call i64 @strcasecmp(i8* %58, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %67
61: ; preds = %57
%62 = load i32, i32* %5
store i32 %62, i32* %3
%63 = load i32, i32* %10
store i32 %63, i32* %5
%64 = load i32, i32* %6
store i32 %64, i32* %10
%65 = load i32, i32* %9
store i32 %65, i32* %6
%66 = load i32, i32* %3
store i32 %66, i32* %9
br label %67
67: ; preds = %61, %57
br label %68
68: ; preds = %67, %51
br label %69
69: ; preds = %68, %41
br label %70
70: ; preds = %69, %31
br label %21
71: ; preds = %21
%72 = load i32, i32* %5
%73 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %72)
br label %11
74: ; preds = %17
ret i32 0
}

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