#include <bits/stdc++.h>
using namespace std;
char f(long long x) {
  string s = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  return s[x];
}
long long of(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  } else {
    return c - 'A' + 10;
  }
}
int main() {
  ios::sync_with_stdio(false);
  long long a;
  string s;
  cin >> a >> s;
  string x;
  cin >> x;
  if (s == "R") {
    vector<long long> st(x.length());
    st[0] = 1;
    for (long long i = 1; i < x.length(); i++) {
      st[i] = st[i - 1] * a;
    }
    long long y = 0;
    for (long long i = 0; i < x.length(); i++) {
      y += of(x[i]) * st[x.length() - i - 1];
    }
    vector<char> res;
    long long t = y / 1000;
    y %= 1000;
    for (long long i = 0; i < t; i++) {
      res.push_back('M');
    }
    t = y / 100;
    y %= 100;
    if (t < 4) {
      for (long long i = 0; i < t; i++) {
        res.push_back('C');
      }
    } else if (t == 4) {
      res.push_back('C');
      res.push_back('D');
    } else if (t == 5) {
      res.push_back('D');
    } else if (t < 9) {
      res.push_back('D');
      t -= 5;
      for (long long i = 0; i < t; i++) {
        res.push_back('C');
      }
    } else {
      res.push_back('C');
      res.push_back('M');
    }
    t = y / 10;
    y %= 10;
    if (t < 4) {
      for (long long i = 0; i < t; i++) {
        res.push_back('X');
      }
    } else if (t == 4) {
      res.push_back('X');
      res.push_back('L');
    } else if (t == 5) {
      res.push_back('L');
    } else if (t < 9) {
      res.push_back('L');
      t -= 5;
      for (long long i = 0; i < t; i++) {
        res.push_back('X');
      }
    } else {
      res.push_back('X');
      res.push_back('C');
    }
    t = y;
    if (t < 4) {
      for (long long i = 0; i < t; i++) {
        res.push_back('I');
      }
    } else if (t == 4) {
      res.push_back('I');
      res.push_back('V');
    } else if (t == 5) {
      res.push_back('V');
    } else if (t < 9) {
      res.push_back('V');
      t -= 5;
      for (long long i = 0; i < t; i++) {
        res.push_back('I');
      }
    } else {
      res.push_back('I');
      res.push_back('X');
    }
    for (long long i = 0; i < res.size(); i++) {
      cout << res[i];
    }
  } else {
    long long b = 0;
    for (long long i = 0; i < s.length(); i++) {
      b *= 10;
      b += s[i] - '0';
    }
    vector<long long> st(x.length());
    st[0] = 1;
    for (long long i = 1; i < x.length(); i++) {
      st[i] = st[i - 1] * a;
    }
    long long y = 0;
    for (long long i = 0; i < x.length(); i++) {
      y += of(x[i]) * st[x.length() - i - 1];
    }
    vector<long long> res;
    while (y) {
      res.push_back(y % b);
      y /= b;
    }
    reverse(res.begin(), res.end());
    if (res.size() == 0) {
      cout << 0;
      return 0;
    }
    for (long long i = 0; i < res.size(); i++) {
      cout << f(res[i]);
    }
  }
  return 0;
}
