// Arup Guha
// 9/17/04
// Solution to Roman problem for 9/11/04 Practice

import java.io.*;

public class roman {

  public static void main(String[] args) throws IOException {

    BufferedReader fin=new BufferedReader(new FileReader("roman.in"));

    // Read in all the data.
    while (fin.ready()) {

      // Read in the two roman numerals to add.
      String num1, num2;
      num1 = fin.readLine();
      num2 = fin.readLine();

      // Determine each corresponding integer value.
      int val1 = convertDecimal(num1);
      int val2 = convertDecimal(num2);

      // Print out the roman numeral representation of the sum.
      System.out.println(convertRoman(val1+val2));

    }

  }

  // Converts a roman numeral stored in a String object to an integer and
  // returns this integer.
  public static int convertDecimal(String num) {

    int val = 0;
    int index = 0;

    // Loop through each letter in the roman numeral.
    while (index < num.length()) {
      
      // The last character is always added.
      if (index == num.length()-1) {
        val += convertChar(num.charAt(index));
        break;
      }

      // Case where you use the "subtraction" rule.
      if (convertChar(num.charAt(index)) < convertChar(num.charAt(index+1))) {
      
        val = val - convertChar(num.charAt(index)) + convertChar(num.charAt(index+1));
        index+=2;
      }

      // Add the corresponding value in the typical case.
      else {
        val += convertChar(num.charAt(index));
        index++;
      }
    }

    return val;
  }

  // Given a roman numeral letter, this function returns is numerical
  // value.
  public static int convertChar(char c) {
    if (c == 'M') return 1000;
    if (c == 'D') return 500;
    if (c == 'C') return 100;
    if (c == 'L') return 50;
    if (c == 'X') return 10;
    if (c == 'V') return 5;
    if (c == 'I') return 1;
    return 0;
  }

  public static String convertRoman(int val) {
   
    String ans = new String("");

    // Print out thousands.
    while (val >= 1000) {
      ans = ans + "M";
      val -= 1000;
    }

    // Print out hundreds.

    // 900 case.
    if (val >= 900) {
      ans = ans + "CM";
      val -= 900;
    }

    // 500 to 800 case.
    else if (val >= 500) {
      ans += "D";
      val -= 500;
      while (val >= 100) {
        ans = ans + "C";
        val -= 100;
      }
    }

    // 400 case.
    else if (val >= 400) {
      ans = ans + "CD";
      val -= 400;
    }

    // 000 - 300 case.
    else {
      while (val >= 100) {
        ans = ans + "C";
        val -= 100;
      }
    }



    // Print out tens.

    // 90 case.
    if (val >= 90) {
      ans = ans + "XC";
      val -= 90;
    }

    // 50 to 80 case.
    else if (val >= 50) {
      ans += "L";
      val -= 50;
      while (val >= 10) {
        ans = ans + "X";
        val -= 10;
      }
    }

    // 40 case.
    else if (val >= 40) {
      ans = ans + "XL";
      val -= 40;
    }

    // 00 - 30 case.
    else {
      while (val >= 10) {
        ans = ans + "X";
        val -= 10;
      }
    }


    // Print out units.

    // 9 case.
    if (val >= 9) {
      ans = ans + "IX";
      val -= 9;
    }

    // 5 to 8 case.
    else if (val >= 5) {
      ans += "V";
      val -= 5;
      while (val >= 1) {
        ans = ans + "I";
        val -= 1;
      }
    }

    // 4 case.
    else if (val >= 4) {
      ans = ans + "IV";
      val -= 4;
    }

    // 0 - 3 case.
    else {
      while (val >= 1) {
        ans = ans + "I";
        val -= 1;
      }
    }

    return ans;
  }  
}
