while true
    line = gets.chomp
    break if line == "#"
    g, y, m, d = line.split.map(&:to_i)
    if y <= 30 || (y == 31 && m <= 4)
        g = "HEISEI"
    else
        g = "?"
        y -= 30
    end
    puts "#{g} #{y} #{m} #{d}"
end
