#include <stdio.h>
#include <stdbool.h>

void leap_year (void)
{
    while (true) {
        int year1, year2;
        scanf("%d %d", &year1, &year2);
        if (year1 == 0 && year2 == 0) {
            break;
        }
        int i;
        for (i = year1; i <= year2; ++i) {
            if (i % 4 == 0) {
                if (i % 400 == 0) {
                    printf("%d\n", i);
                } else if (i % 100 != 0) {
                    printf("%d\n", i);
                }
            } 
        }
    }
}

int main(void)
{
    leap_year();
    return 0;
}