#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 10;
int a, b, n;
char c[MAXN];
int val[MAXN] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
char roman[MAXN][MAXN] = {"M",  "CM", "D",  "CD", "C",  "XC", "L",
                          "XL", "X",  "IX", "V",  "IV", "I"};
int main() {
  char _b[10];
  while (scanf("%d %s %s", &a, _b, c) >= 1) {
    bool rom = false;
    if (_b[0] == 'R') {
      rom = true;
    } else {
      b = atoi(_b);
    }
    n = strlen(c);
    long long p = 0;
    long long pot = 1;
    for (int i = n - 1; i >= 0; i--) {
      int ch = isupper(c[i]) ? c[i] - 'A' + 10 : c[i] - '0';
      p += pot * ch;
      pot *= a;
    }
    char ans[MAXN];
    memset(ans, 0, sizeof ans);
    if (rom) {
      for (int i = (0); i < (int)(13); i++) {
        while (p >= val[i]) {
          p -= val[i];
          strcat(ans, roman[i]);
        }
      }
    } else {
      int it = 0;
      while (p) {
        int t = p % b;
        ans[it] = (t < 10) ? t + '0' : t + 'A' - 10;
        p /= b;
        it++;
      }
      if (it == 0) ans[0] = '0';
      reverse(ans, ans + it);
    }
    printf("%s\n", ans);
  }
  return 0;
}
