import java.util.*;
import java.lang.*;
import java.math.*;
class JAVA {
static Map<Character,Integer> number_table=new HashMap<Character,Integer>();
public static void main(String args[]) {
Scanner inp=new Scanner(System.in);
number_table.put('I',1);
number_table.put('V',5);
number_table.put('X',10);
number_table.put('L',50);
number_table.put('C',100);
number_table.put('D',500);
number_table.put('M',1000);
while(true) {
String a=inp.next();
if (a.equals("#")) {break;}
String b=inp.next();
int ans=Subtration(a,b);
Calc(ans);
System.out.println();
}
}
static int Subtration(String a,String b) {
int x=0,y=0,i=0,length;
length=a.length()-1;
for (i=0;i<=length;i++){
if(i+1<=length) {
if(number_table.get(a.charAt(i))<number_table.get(a.charAt(i+1))) {
x+=number_table.get(a.charAt(i+1))-number_table.get(a.charAt(i));
i++;
} else {
x+=number_table.get(a.charAt(i));
}
} else if(i==length) {
x+=number_table.get(a.charAt(i));
}
}
length=b.length()-1;
for (i=0;i<=length;i++){
if(i+1<=length) {
if(number_table.get(b.charAt(i))<number_table.get(b.charAt(i+1))) {
y+=number_table.get(b.charAt(i+1))-number_table.get(b.charAt(i));
i++;
} else {
y+=number_table.get(b.charAt(i));
}
} else if(i==length) {
y+=number_table.get(b.charAt(i));
}
}
return Math.abs(x-y);
}
static void Calc(int inp){
if(inp==0){
System.out.print("ZERO");
}
int t=inp;
while(t!=0){
t=inp;
if(t / 1000>0) {
inp%=1000;
for (int i=1;i<=t / 1000;i++){
System.out.print("M");
}
} else if(t / 100 >0) {
inp%=100;
if(t / 100==4) {
System.out.print("CD");
} else if(t / 100==9) {
System.out.print("CM");
} else if(t>=500){
System.out.print("D");
t-=500;
for (int i=1;i<=t / 100;i++){
System.out.print("C");
}
} else {
for (int i=1;i<=t / 100;i++) {
System.out.print("C");
}
}
}else if(t / 10 >0) {
inp%=10;
if(t / 10 ==4) {
System.out.print("XL");
} else if(t / 10 ==9) {
System.out.print("XC");
} else if (t>=50) {
System.out.print("L");
t-=50;
for (int i=1;i<=t / 10 ;i++){
System.out.print("X");
}
}else {
for (int i=1;i<=t / 10 ;i++){
System.out.print("X");
}
}
} else {
inp=0;
if(t==4) {
System.out.print("IV");
} else if(t==9) {
System.out.print("IX");
} else if(t>=5){
System.out.print("V");
t-=5;
for (int i=1;i<=t;i++) {
System.out.print("I");
}
} else {
for (int i=1;i<=t;i++) {
System.out.print("I");
}
}
}
}
}
}