#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

vector<int> a = {1867,1911,1925,1988};
vector<char> c = {'M','T','S','H'};

int main(){
  int E,Y;
  cin >> E >> Y;
  if(E == 0){
    for(int i = 3;i >= 0;i--){
      if(Y > a[i]){
        cout << c[i] << Y - a[i] << endl;
        return 0;
      }
    }
  }
  else{
    cout << Y + a[E - 1] << endl;
  }

}

