require 'date'

ds = [Date.new(1868, 9, 8), Date.new(1912, 7, 30), Date.new(1926, 12, 25), Date.new(1989, 1, 8)]
$<.each_line do |l|
  d = Date.new *l.split.map(&:to_i)
  case
  when d < ds[0]
    puts 'pre-meiji'
  when d < ds[1]
    puts 'meiji %d %d %d' % [d.year - ds[0].year + 1, d.month, d.day]
  when d < ds[2]
    puts 'taisho %d %d %d' % [d.year - ds[1].year + 1, d.month, d.day]
  when d < ds[3]
    puts 'showa %d %d %d' % [d.year - ds[2].year + 1, d.month, d.day]
  else
    puts 'heisei %d %d %d' % [d.year - ds[3].year + 1, d.month, d.day]
  end
end