#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 *);
int main(void) {
  int t, year, leap, i;
  scanf("%d", &t);
  while (t--) {
    leap = 0;
    scanf("%d", &year);
    for (i = 1900; i < year; i++)
      if ((i % 4 == 0 && i % 100 != 0) || (i % 400 == 0))
        leap++;
    switch (((year + leap - 1900)) % 7) {
    case 0:
      printf("monday\n");
      break;
    case 1:
      printf("tuesday\n");
      break;
    case 2:
      printf("wednesday\n");
      break;
    case 3:
      printf("thursday\n");
      break;
    case 4:
      printf("friday\n");
      break;
    case 5:
      printf("saturday\n");
      break;
    case 6:
      printf("sunday\n");
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xee6(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     12b8 <main+0x198>
movl   $0x0,-0x10(%rbp)
lea    0xebb(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x76c,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d5 <main+0xb5>
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11a5 <main+0x85>
mov    -0x14(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11b9 <main+0x99>
mov    -0x14(%rbp),%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11c2 <main+0xa2>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11c7 <main+0xa7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1171 <main+0x51>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%eax
mov    %esi,%edx
add    %eax,%edx
mov    %eax,%ecx
mov    %esi,%eax
lea    -0x76c(%rax,%rcx,1),%eax
cltq
imul   $0xffffffff92492493,%rax,%rax
shr    $0x20,%rax
mov    %eax,%ecx
mov    %ecx,%eax
mov    %edx,%ecx
lea    -0x76c(%rax,%rcx,1),%edx
mov    %edx,%eax
shr    $0x1f,%eax
sar    $0x2,%edx
add    %eax,%edx
mov    %edx,%eax
shl    $0x3,%eax
sub    %eax,%edx
mov    %edx,%eax
lea    -0x76c(%rax,%rcx,1),%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x6,%eax
ja     12b3 <main+0x193>
mov    -0x20(%rbp),%rax
lea    0xdc8(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xdd7(%rip),%rdi
call   1030 <printf@plt>
jmp    12b3 <main+0x193>
lea    0xdce(%rip),%rdi
call   1030 <printf@plt>
jmp    12b3 <main+0x193>
lea    0xdc6(%rip),%rdi
call   1030 <printf@plt>
jmp    12b3 <main+0x193>
lea    0xdc0(%rip),%rdi
call   1030 <printf@plt>
jmp    12b3 <main+0x193>
lea    0xdb9(%rip),%rdi
call   1030 <printf@plt>
jmp    12b3 <main+0x193>
lea    0xdb0(%rip),%rdi
call   1030 <printf@plt>
jmp    12b3 <main+0x193>
lea    0xda9(%rip),%rdi
call   1030 <printf@plt>
jmp    113f <main+0x1f>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xf61(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
subl   $0x1,(%rsp)
jae    114b <main+0x2b>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xf3e(%rip),%r14
lea    0x4(%rsp),%r15
lea    0xf6e(%rip),%r12
jmp    1166 <main+0x46>
subl   $0x1,(%rsp)
jb     113d <main+0x1d>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%r8d
xor    %edi,%edi
cmp    $0x76d,%r8d
jl     135e <main+0x23e>
lea    -0x76c(%r8),%edx
cmp    $0x8,%edx
jae    11a0 <main+0x80>
xor    %edi,%edi
mov    $0x76c,%ecx
jmp    1320 <main+0x200>
nopl   (%rax)
mov    %edx,%esi
and    $0xfffffff8,%esi
lea    0x76c(%rsi),%ecx
pxor   %xmm0,%xmm0
mov    %esi,%edi
movdqa 0xe47(%rip),%xmm2
pxor   %xmm1,%xmm1
movdqa 0xe4a(%rip),%xmm8
movdqa 0xe51(%rip),%xmm10
movdqa 0xe58(%rip),%xmm11
movdqa 0xe5f(%rip),%xmm12
movdqa 0xe66(%rip),%xmm13
movdqa 0xe6d(%rip),%xmm14
pcmpeqd %xmm15,%xmm15
movdqa 0xe6f(%rip),%xmm9
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movdqa %xmm2,%xmm3
pmuludq %xmm10,%xmm3
pshufd $0xe8,%xmm3,%xmm3
pshufd $0xf5,%xmm2,%xmm4
pmuludq %xmm10,%xmm4
pshufd $0xe8,%xmm4,%xmm4
punpckldq %xmm4,%xmm3
movdqa %xmm3,%xmm4
psrld  $0x2,%xmm4
movdqa %xmm3,%xmm6
pslld  $0x1e,%xmm6
por    %xmm4,%xmm6
movdqa %xmm3,%xmm4
paddd  %xmm13,%xmm4
movdqa %xmm4,%xmm7
psrld  $0x2,%xmm7
movdqa %xmm4,%xmm5
pslld  $0x1e,%xmm5
por    %xmm7,%xmm5
movdqa %xmm2,%xmm7
pand   %xmm8,%xmm7
pcmpeqd 0xe09(%rip),%xmm7
pxor   %xmm11,%xmm6
pcmpgtd %xmm12,%xmm6
pxor   %xmm11,%xmm5
pcmpgtd %xmm12,%xmm5
pand   %xmm7,%xmm6
pand   %xmm7,%xmm5
movdqa %xmm3,%xmm7
psrld  $0x4,%xmm7
pslld  $0x1c,%xmm3
por    %xmm7,%xmm3
pxor   %xmm11,%xmm3
pcmpgtd %xmm14,%xmm3
pxor   %xmm15,%xmm3
por    %xmm6,%xmm3
psubd  %xmm3,%xmm0
movdqa %xmm4,%xmm3
psrld  $0x4,%xmm3
pslld  $0x1c,%xmm4
por    %xmm3,%xmm4
pxor   %xmm11,%xmm4
pcmpgtd %xmm14,%xmm4
pxor   %xmm15,%xmm4
por    %xmm5,%xmm4
psubd  %xmm4,%xmm1
paddd  %xmm9,%xmm2
add    $0xfffffff8,%edi
jne    1210 <main+0xf0>
paddd  %xmm0,%xmm1
pshufd $0xee,%xmm1,%xmm0
paddd  %xmm1,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%edi
cmp    %esi,%edx
je     135e <main+0x23e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ecx,%edx
imul   $0x51eb851f,%rdx,%rdx
mov    %rdx,%rsi
shr    $0x25,%rsi
imul   $0x64,%esi,%esi
shr    $0x27,%rdx
imul   $0x190,%edx,%edx
test   $0x3,%cl
sete   %bl
cmp    %ecx,%esi
setne  %al
and    %bl,%al
cmp    %ecx,%edx
sete   %dl
or     %al,%dl
movzbl %dl,%eax
add    %eax,%edi
add    $0x1,%ecx
cmp    %ecx,%r8d
jne    1320 <main+0x200>
lea    (%rdi,%r8,1),%eax
lea    (%rdi,%r8,1),%ecx
add    $0xfffff894,%ecx
movslq %ecx,%rcx
imul   $0xffffffff92492493,%rcx,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
add    $0xfffff894,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x2,%ecx
add    %edx,%ecx
lea    0x0(,%rcx,8),%edx
sub    %edx,%ecx
add    %ecx,%eax
add    $0xfffff894,%eax
cmp    $0x6,%eax
ja     1160 <main+0x40>
cltq
movslq (%r12,%rax,4),%rdi
add    %r12,%rdi
call   1030 <puts@plt>
jmp    1160 <main+0x40>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [8 x i8] c"monday\0A\00"
@.str.2 = [9 x i8] c"tuesday\0A\00"
@.str.3 = [11 x i8] c"wednesday\0A\00"
@.str.4 = [10 x i8] c"thursday\0A\00"
@.str.5 = [8 x i8] c"friday\0A\00"
@.str.6 = [10 x i8] c"saturday\0A\00"
@.str.7 = [8 x i8] c"sunday\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %7
7: ; preds = %56, %0
%8 = load i32, i32* %2
%9 = add nsw i32 %8, -1
store i32 %9, i32* %2
%10 = icmp ne i32 %8, 0
br i1 %10, label %11, label %57
11: ; preds = %7
store i32 0, i32* %4
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
store i32 1900, i32* %5
br label %13
13: ; preds = %33, %11
%14 = load i32, i32* %5
%15 = load i32, i32* %3
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %36
17: ; preds = %13
%18 = load i32, i32* %5
%19 = srem i32 %18, 4
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i32, i32* %5
%23 = srem i32 %22, 100
%24 = icmp ne i32 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %21, %17
%26 = load i32, i32* %5
%27 = srem i32 %26, 400
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25, %21
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %32
32: ; preds = %29, %25
br label %33
33: ; preds = %32
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %13
36: ; preds = %13
%37 = load i32, i32* %3
%38 = load i32, i32* %4
%39 = add nsw i32 %37, %38
%40 = sub nsw i32 %39, 1900
%41 = srem i32 %40, 7
switch i32 %41, label %56 [
i32 0, label %42
i32 1, label %44
i32 2, label %46
i32 3, label %48
i32 4, label %50
i32 5, label %52
i32 6, label %54
]
42: ; preds = %36
%43 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %56
44: ; preds = %36
%45 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %56
46: ; preds = %36
%47 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %56
48: ; preds = %36
%49 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %56
50: ; preds = %36
%51 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %56
52: ; preds = %36
%53 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %56
54: ; preds = %36
%55 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %56
56: ; preds = %36, %54, %52, %50, %48, %46, %44, %42
br label %7
57: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@str = [7 x i8] c"sunday\00"
@str.8 = [9 x i8] c"saturday\00"
@str.9 = [7 x i8] c"friday\00"
@str.10 = [9 x i8] c"thursday\00"
@str.11 = [10 x i8] c"wednesday\00"
@str.12 = [8 x i8] c"tuesday\00"
@str.13 = [7 x i8] c"monday\00"
@reltable.main = [7 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @str.13 to i64), i64 ptrtoint ([7 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @str.12 to i64), i64 ptrtoint ([7 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @str.11 to i64), i64 ptrtoint ([7 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @str.10 to i64), i64 ptrtoint ([7 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @str.9 to i64), i64 ptrtoint ([7 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @str.8 to i64), i64 ptrtoint ([7 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @str to i64), i64 ptrtoint ([7 x i32]* @reltable.main to i64)) to i32)]
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = add nsw i32 %6, -1
store i32 %7, i32* %1
%8 = icmp eq i32 %6, 0
br i1 %8, label %85, label %9
9: ; preds = %0, %81
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
%12 = icmp sgt i32 %11, 1900
br i1 %12, label %13, label %70
13: ; preds = %9
%14 = add i32 %11, -1900
%15 = icmp ult i32 %14, 8
br i1 %15, label %52, label %16
16: ; preds = %13
%17 = and i32 %14, -8
%18 = add i32 %17, 1900
br label %19
19: ; preds = %19, %16
%20 = phi i32 [ 0, %16 ], [ %45, %19 ]
%21 = phi <4 x i32> [ <i32 1900, i32 1901, i32 1902, i32 1903>, %16 ], [ %46, %19 ]
%22 = phi <4 x i32> [ zeroinitializer, %16 ], [ %43, %19 ]
%23 = phi <4 x i32> [ zeroinitializer, %16 ], [ %44, %19 ]
%24 = add <4 x i32> %21, <i32 4, i32 4, i32 4, i32 4>
%25 = and <4 x i32> %21, <i32 3, i32 3, i32 3, i32 3>
%26 = and <4 x i32> %21, <i32 3, i32 3, i32 3, i32 3>
%27 = icmp eq <4 x i32> %25, zeroinitializer
%28 = icmp eq <4 x i32> %26, zeroinitializer
%29 = urem <4 x i32> %21, <i32 100, i32 100, i32 100, i32 100>
%30 = urem <4 x i32> %24, <i32 100, i32 100, i32 100, i32 100>
%31 = icmp ne <4 x i32> %29, zeroinitializer
%32 = icmp ne <4 x i32> %30, zeroinitializer
%33 = and <4 x i1> %27, %31
%34 = and <4 x i1> %28, %32
%35 = urem <4 x i32> %21, <i32 400, i32 400, i32 400, i32 400>
%36 = urem <4 x i32> %24, <i32 400, i32 400, i32 400, i32 400>
%37 = icmp eq <4 x i32> %35, zeroinitializer
%38 = icmp eq <4 x i32> %36, zeroinitializer
%39 = select <4 x i1> %33, <4 x i1> <i1 true, i1 true, i1 true, i1 true>, <4 x i1> %37
%40 = select <4 x i1> %34, <4 x i1> <i1 true, i1 true, i1 true, i1 true>, <4 x i1> %38
%41 = zext <4 x i1> %39 to <4 x i32>
%42 = zext <4 x i1> %40 to <4 x i32>
%43 = add <4 x i32> %22, %41
%44 = add <4 x i32> %23, %42
%45 = add nuw i32 %20, 8
%46 = add <4 x i32> %21, <i32 8, i32 8, i32 8, i32 8>
%47 = icmp eq i32 %45, %17
br i1 %47, label %48, label %19
48: ; preds = %19
%49 = add <4 x i32> %44, %43
%50 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %49)
%51 = icmp eq i32 %14, %17
br i1 %51, label %70, label %52
52: ; preds = %13, %48
%53 = phi i32 [ 1900, %13 ], [ %18, %48 ]
%54 = phi i32 [ 0, %13 ], [ %50, %48 ]
br label %55
55: ; preds = %52, %55
%56 = phi i32 [ %68, %55 ], [ %53, %52 ]
%57 = phi i32 [ %67, %55 ], [ %54, %52 ]
%58 = and i32 %56, 3
%59 = icmp eq i32 %58, 0
%60 = urem i32 %56, 100
%61 = icmp ne i32 %60, 0
%62 = and i1 %59, %61
%63 = urem i32 %56, 400
%64 = icmp eq i32 %63, 0
%65 = select i1 %62, i1 true, i1 %64
%66 = zext i1 %65 to i32
%67 = add nuw nsw i32 %57, %66
%68 = add nuw nsw i32 %56, 1
%69 = icmp eq i32 %68, %11
br i1 %69, label %70, label %55
70: ; preds = %55, %48, %9
%71 = phi i32 [ 0, %9 ], [ %50, %48 ], [ %67, %55 ]
%72 = add i32 %71, -1900
%73 = add i32 %72, %11
%74 = srem i32 %73, 7
%75 = icmp ult i32 %74, 7
br i1 %75, label %76, label %81
76: ; preds = %70
%77 = sext i32 %74 to i64
%78 = shl i64 %77, 2
%79 = call i8* @llvm.load.relative.i64(i8* bitcast ([7 x i32]* @reltable.main to i8*), i64 %78)
%80 = call i32 @puts(i8* dereferenceable(1) %79)
br label %81
81: ; preds = %70, %76
%82 = load i32, i32* %1
%83 = add nsw i32 %82, -1
store i32 %83, i32* %1
%84 = icmp eq i32 %82, 0
br i1 %84, label %85, label %9
85: ; preds = %81, %0
ret i32 0
}