def leap? y
    leap = false
    leap = true if y % 4 == 0
    leap = false if y % 100 == 0
    leap = true if y % 400 == 0
    leap
end

def countdays y, m, d
    arr = [[31,29,31,30,31,30,31,31,30,31,30,31], [31,28,31,30,31,30,31,31,30,31,30,31]]
    sum = 0
    1.upto(y - 1){|i| sum += (leap?(i)) ? 366 : 365}
    1.upto(m - 1){|i| sum += (leap?(y)) ? arr[0][i - 1] : arr[1][i - 1]}
    1.upto(d){sum += 1}
    sum
end

meiji_firstday = countdays(1868, 9, 8)
taisho_firstday = countdays(1912, 7, 30)
showa_firstday = countdays(1926, 12, 25)
heisei_firstday = countdays(1989, 1, 8)
gengos = {"meiji"=>1867, "taisho"=>1911, "showa"=>1925, "heisei"=>1988}

while line = gets
    y, m, d = line.chomp.split.map(&:to_i)
    days = countdays(y, m, d)
    result, gengo = nil, nil
    if days < meiji_firstday
        result = "pre-meiji"
    elsif days < taisho_firstday
        gengo = "meiji"
    elsif days < showa_firstday
        gengo = "taisho"
    elsif days < heisei_firstday
        gengo = "showa"
    else
        gengo = "heisei"
    end
    y -= gengos[gengo] if gengo
    result = "#{gengo} #{y} #{m} #{d}" if result.nil?
    puts result
end
