#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() {
  int date;
  scanf("%d", &date);
  int n;
  scanf("%d", &n);
  int i;
  int day = date / 100000;
  int month = (date / 10000) % 100;
  int year = date % 10000;
  for (i = 0; i < n; ++i) {
    int d;
    scanf("%d", &d);
    int dd = d / 100000;
    int mm = (d / 10000) % 100;
    int yy = d % 10000;
    int years = year - yy;
    if (years < 18) {
      printf("NE\n");
    } else if (years == 18) {
      if (mm < month) {
        printf("DA\n");
      } else if (mm == month) {
        if (dd <= day) {
          printf("DA\n");
        } else {
          printf("NE\n");
        }
      } else {
        printf("NE\n");
      }
    } else if (years > 18) {
      printf("DA\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xeba(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    $0x186a0,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12a4 <main+0x184>
lea    0xe65(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x20(%rbp),%eax
mov    $0x186a0,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,-0x28(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
mov    %edx,-0x2c(%rbp)
mov    -0x1c(%rbp),%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x12,-0x30(%rbp)
jge    11fa <main+0xda>
lea    0xe13(%rip),%rdi
call   1030 <printf@plt>
jmp    1291 <main+0x171>
cmpl   $0x12,-0x30(%rbp)
jne    1271 <main+0x151>
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1221 <main+0x101>
lea    0xdf0(%rip),%rdi
call   1030 <printf@plt>
jmp    126c <main+0x14c>
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    125b <main+0x13b>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     124a <main+0x12a>
lea    0xdc7(%rip),%rdi
call   1030 <printf@plt>
jmp    1256 <main+0x136>
lea    0xdb2(%rip),%rdi
call   1030 <printf@plt>
jmp    1267 <main+0x147>
lea    0xda1(%rip),%rdi
call   1030 <printf@plt>
jmp    126c <main+0x14c>
jmp    128c <main+0x16c>
cmpl   $0x12,-0x30(%rbp)
jle    1287 <main+0x167>
lea    0xd85(%rip),%rdi
call   1030 <printf@plt>
jmp    128c <main+0x16c>
jmp    1291 <main+0x171>
jmp    1296 <main+0x176>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1188 <main+0x68>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xecb(%rip),%rbx
lea    0x14(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <scanf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1284 <main+0x164>
movslq 0x14(%rsp),%r13
imul   $0x14f8b589,%r13,%rcx
mov    %rcx,%rax
shr    $0x3f,%rax
sar    $0x2d,%rcx
add    %eax,%ecx
mov    %rcx,0x18(%rsp)
imul   $0x68db8bad,%r13,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x2c,%rax
add    %ecx,%eax
movslq %eax,%rdx
imul   $0x51eb851f,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
imul   $0x2710,%edx,%ecx
sub    %eax,%edx
mov    %rdx,0x20(%rsp)
sub    %ecx,%r13d
xor    %ebp,%ebp
lea    0xe41(%rip),%r14
lea    0x10(%rsp),%r15
lea    0xe3b(%rip),%r12
jmp    11e2 <main+0xc2>
nopl   (%rax)
call   1030 <puts@plt>
add    $0x1,%ebp
cmp    0xc(%rsp),%ebp
jge    1284 <main+0x164>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
movslq 0x10(%rsp),%rcx
imul   $0x14f8b589,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x2d,%rax
add    %edx,%eax
imul   $0x68db8bad,%rcx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x2c,%rdx
add    %esi,%edx
movslq %edx,%rdx
imul   $0x51eb851f,%rdx,%rsi
mov    %rsi,%rdi
shr    $0x3f,%rdi
sar    $0x25,%rsi
add    %edi,%esi
imul   $0x64,%esi,%esi
imul   $0x2710,%edx,%ebx
sub    %esi,%edx
sub    %ecx,%ebx
add    %r13d,%ebx
mov    %r12,%rdi
cmp    $0x12,%ebx
jl     11d0 <main+0xb0>
lea    0xdb3(%rip),%rdi
jne    11d0 <main+0xb0>
lea    0xda6(%rip),%rdi
cmp    0x20(%rsp),%edx
jl     11d0 <main+0xb0>
mov    %r12,%rdi
jne    11d0 <main+0xb0>
cmp    0x18(%rsp),%eax
lea    0xd88(%rip),%rdi
cmovg  %r12,%rdi
jmp    11d0 <main+0xb0>
xor    %eax,%eax
add    $0x28,%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"NE\0A\00"
@.str.2 = [4 x i8] c"DA\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 i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %1
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%15 = load i32, i32* %2
%16 = sdiv i32 %15, 100000
store i32 %16, i32* %5
%17 = load i32, i32* %2
%18 = sdiv i32 %17, 10000
%19 = srem i32 %18, 100
store i32 %19, i32* %6
%20 = load i32, i32* %2
%21 = srem i32 %20, 10000
store i32 %21, i32* %7
store i32 0, i32* %4
br label %22
22: ; preds = %76, %0
%23 = load i32, i32* %4
%24 = load i32, i32* %3
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %79
26: ; preds = %22
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%28 = load i32, i32* %8
%29 = sdiv i32 %28, 100000
store i32 %29, i32* %9
%30 = load i32, i32* %8
%31 = sdiv i32 %30, 10000
%32 = srem i32 %31, 100
store i32 %32, i32* %10
%33 = load i32, i32* %8
%34 = srem i32 %33, 10000
store i32 %34, i32* %11
%35 = load i32, i32* %7
%36 = load i32, i32* %11
%37 = sub nsw i32 %35, %36
store i32 %37, i32* %12
%38 = load i32, i32* %12
%39 = icmp slt i32 %38, 18
br i1 %39, label %40, label %42
40: ; preds = %26
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %75
42: ; preds = %26
%43 = load i32, i32* %12
%44 = icmp eq i32 %43, 18
br i1 %44, label %45, label %68
45: ; preds = %42
%46 = load i32, i32* %10
%47 = load i32, i32* %6
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %67
51: ; preds = %45
%52 = load i32, i32* %10
%53 = load i32, i32* %6
%54 = icmp eq i32 %52, %53
br i1 %54, label %55, label %64
55: ; preds = %51
%56 = load i32, i32* %9
%57 = load i32, i32* %5
%58 = icmp sle i32 %56, %57
br i1 %58, label %59, label %61
59: ; preds = %55
%60 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %63
61: ; preds = %55
%62 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %63
63: ; preds = %61, %59
br label %66
64: ; preds = %51
%65 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %66
66: ; preds = %64, %63
br label %67
67: ; preds = %66, %49
br label %74
68: ; preds = %42
%69 = load i32, i32* %12
%70 = icmp sgt i32 %69, 18
br i1 %70, label %71, label %73
71: ; preds = %68
%72 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %73
73: ; preds = %71, %68
br label %74
74: ; preds = %73, %67
br label %75
75: ; preds = %74, %40
br label %76
76: ; preds = %75
%77 = load i32, i32* %4
%78 = add nsw i32 %77, 1
store i32 %78, i32* %4
br label %22
79: ; preds = %22
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@str.6 = [3 x i8] c"DA\00"
@str.7 = [3 x i8] c"NE\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = bitcast i32* %2 to i8*
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %1
%9 = sdiv i32 %8, 100000
%10 = sdiv i32 %8, 10000
%11 = srem i32 %10, 100
%12 = srem i32 %8, 10000
%13 = load i32, i32* %2
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %42
15: ; preds = %0
%16 = bitcast i32* %3 to i8*
br label %17
17: ; preds = %15, %36
%18 = phi i32 [ 0, %15 ], [ %39, %36 ]
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%20 = load i32, i32* %3
%21 = sdiv i32 %20, 100000
%22 = sdiv i32 %20, 10000
%23 = srem i32 %22, 100
%24 = srem i32 %20, 10000
%25 = sub nsw i32 %12, %24
%26 = icmp slt i32 %25, 18
br i1 %26, label %36, label %27
27: ; preds = %17
%28 = icmp eq i32 %25, 18
br i1 %28, label %29, label %36
29: ; preds = %27
%30 = icmp slt i32 %23, %11
br i1 %30, label %36, label %31
31: ; preds = %29
%32 = icmp eq i32 %23, %11
br i1 %32, label %33, label %36
33: ; preds = %31
%34 = icmp sgt i32 %21, %9
%35 = select i1 %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @str.7, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @str.6, i64 0, i64 0)
br label %36
36: ; preds = %27, %31, %33, %29, %17
%37 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @str.7, i64 0, i64 0), %17 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @str.6, i64 0, i64 0), %29 ], [ %35, %33 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @str.7, i64 0, i64 0), %31 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @str.6, i64 0, i64 0), %27 ]
%38 = call i32 @puts(i8* dereferenceable(1) %37)
%39 = add nuw nsw i32 %18, 1
%40 = load i32, i32* %2
%41 = icmp slt i32 %39, %40
br i1 %41, label %17, label %42
42: ; preds = %36, %0
ret i32 0
}