package javaapplication35;
import java.util.ArrayList;
import java.util.Scanner;
public class zerojudge091 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String a[] = {"I", "V", "X", "L", "C", "D", "M"};
int b[] = {1, 5, 10, 50, 100, 500, 1000};
String a1, a2, t,array="";
while (input.hasNext()) {
ArrayList<String> myList = new ArrayList<String>();
int c = 0, sum = 0, g = 0, d = 0, sum2 = 0, tax = 0;
a1 = input.next();
if (a1.equals("#")) {
break;
}
a2 = input.next();
for (int i = 0; i < a1.length(); i++) {
for (int k = 0; k < a.length; k++) {
if (String.valueOf(a1.charAt(i)).equals(a[k])) {
if (d < b[k]) {
sum = sum - d;
} else {
sum = sum + d;
}
d = b[k];
break;
}
}
}
sum = sum + d;
d=0;
for (int i = 0; i < a2.length(); i++) {
for (int k = 0; k < a.length; k++) {
if (String.valueOf(a2.charAt(i)).equals(a[k])) {
if (d < b[k]) {
sum2 = sum2 - d;
} else {
sum2 = sum2 + d;
}
d = b[k];
break;
}
}
}
sum2 = sum2 + d;
int k = Math.abs(sum2 - sum);
d = 1;
if (k == 0) {
System.out.println("ZERO");
} else {
while (k != 0) {
c = k % 10 * d;
d = d * 10;
tax = k % 10;
k = k / 10;
array = "";
if (tax != 4 && tax != 9) {
while (c != 0) {
for (int i = 0; i < b.length; i++) {
if (b[i] == c) {
c = c - b[i];
array = array + a[i];
break;
} else if (b[i] > c) {
c = c - b[i - 1];
array = array + a[i - 1];
break;
}
}
}
} else {
while (c != 0) {
for (int i = 0; i < b.length; i++) {
if (b[i] == c) {
c = c - b[i];
array = a[i] + array;
break;
} else if (b[i] > c) {
c = b[i] - c;
array = a[i];
break;
}
}
}
}
myList.add(array);
}
for (int i = myList.size() - 1; i >= 0; i--) {
System.out.print(myList.get(i));
}
System.out.println();
}
}
}
}