#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:134217728")
using namespace std;
int a;
char b[4];
char c[1 << 10];
string s[] = {"M",  "CM", "D",  "CD", "C",  "XC", "L",
              "XL", "X",  "IX", "V",  "IV", "I"};
int v[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
int main() {
  scanf("%d", &a);
  scanf("%s", b);
  scanf("%s", c);
  long long val = 0;
  for (int i = 0; c[i]; ++i) {
    val *= a;
    if ('A' <= c[i] && c[i] <= 'Z')
      val += c[i] - 'A' + 10;
    else
      val += c[i] - '0';
  }
  if (b[0] == 'R') {
    for (int i = 0; i < 13; ++i) {
      while (val >= v[i]) {
        val -= v[i];
        printf("%s", s[i].c_str());
      }
    }
    printf("\n");
  } else {
    int d;
    sscanf(b, "%d", &d);
    string res = "";
    while (val) {
      int r = val % d;
      if (r <= 9)
        res += '0' + r;
      else
        res += 'A' + r - 10;
      val /= d;
    }
    reverse(res.begin(), res.end());
    if (res.empty()) res = "0";
    printf("%s\n", res.c_str());
  }
  return 0;
}
