E, Y = gets.split.map &:to_i

DATE = [0, 1868, 1912, 1926, 1989]
PERIOD = [1867, 44, 13, 63, 28]
ERA = %w!AD M T S H!

if E.zero?
  (1..4).each do |i|
    y = Y - DATE[i] + 1
    next unless (1..PERIOD[i]).include? y
    print ERA[i]
    p y
  end
else
  p DATE[E] + Y - 1
end