
import std.stdio, std.algorithm, std.array, std.conv, std.string;

bool[3000] leap_table;

void init_leap_table() {
  foreach(i, ref x; leap_table) {
    if (((i % 4) == 0) && (((i % 100) != 0) || ((i % 400) == 0))) x = true;
  }
}

void main() {
  init_leap_table;
  bool first = true;
  while(true) {
    int[] date = readln.chomp.split(" ").map!(to!(int)).array;
    bool ans = false;
    if (date[0] == 0 && date[1] == 0) break;
    if (!first) writeln;
    foreach(d; date[0]..(date[1] + 1))
      if (leap_table[d]) {writeln(d); ans = true;}
    if (!ans) writeln("NA");
    first = false;
  }
}