#include <bits/stdc++.h>
using namespace std;
int val(char c) {
  if (c >= 'A') return 10 + c - 'A';
  return c - '0';
}
void rep(char c, int v) {
  for (int i = 0; i < (v); i++) printf("%c", c);
}
void foo(char a, char b, char c, int x, int m) {
  if (x >= 9 * m)
    rep(a, 1), rep(c, 1);
  else if (x >= 5 * m)
    rep(b, 1), rep(a, x / m - 5);
  else if (x >= 4 * m)
    printf("%c%c", a, b);
  else if (x >= m)
    rep(a, x / m);
}
char ival(int x) {
  if (x >= 10) return 'A' + (x - 10);
  return x + '0';
}
int main() {
  int a, b;
  char bs[100], cs[5000];
  while (scanf("%d %s", &a, bs) == 2) {
    scanf(" %s", cs);
    long long x = 0;
    for (int i = 0; cs[i]; i++) x = x * a + val(cs[i]);
    if (bs[0] == 'R') {
      rep('M', x / 1000);
      x %= 1000;
      foo('C', 'D', 'M', x, 100);
      x %= 100;
      foo('X', 'L', 'C', x, 10);
      x %= 10;
      foo('I', 'V', 'X', x, 1);
    } else {
      sscanf(bs, "%d", &b);
      string sr;
      while (x > 0) {
        sr += ival(x % b);
        x /= b;
      }
      reverse(sr.begin(), sr.end());
      if (sr.empty())
        printf("0");
      else
        printf("%s", sr.c_str());
    }
    printf("\n");
  }
  return 0;
}
