
fun main(args:Array<String>):Unit {
    val (h, y) = readLine()!!.trim().split(' ').map(String::toInt)
    println(
            if (h == 0) yTow(y)
            else wToy(h, y)
    )
}
fun yTow(year:Int):String {
    return when{
        year <= 1911 -> "M" + "${year - 1867}"
        year <= 1925 -> "T" + "${year - 1911}"
        year <= 1988 -> "S" + "${year - 1925}"
        else -> "H" + "${year - 1988}"
    }
}
fun wToy(h:Int, year:Int):Int {
    return when(h){
        1 -> year + 1867
        2 -> year + 1911
        3 -> year + 1925
        else -> year + 1988
    }
}
