#include <iostream>
#include <vector>
#include <string>
using namespace std;
int StringToInteger(string);
string IntegerToString(int);
int main(){
string s1, s2;
int n1, n2;
while (cin >> s1 >> s2) {
if (s1 == "#" || s2 == "#") {
break;
}
n1 = StringToInteger(s1);
n2 = StringToInteger(s2);
if (n1 - n2 == 0) {
cout << "ZERO\n";
}
else
cout << IntegerToString(n1 - n2) << endl;
}
}
int StringToInteger(string s){
vector <int> integer;
int n;
for (int i = 0; i < s.length(); i++) {
switch (s[i]) {
case 'I':
integer.push_back(1);
break;
case 'V':
integer.push_back(5);
break;
case 'X':
integer.push_back(10);
break;
case 'L':
integer.push_back(50);
break;
case 'C':
integer.push_back(100);
break;
case 'D':
integer.push_back(500);
break;
case 'M':
integer.push_back(1000);
break;
default:
break;
}
}
n = integer.back();
for (size_t i = integer.size() - 1; i > 0; i--) {
if (integer[i-1] < integer[i]) {
n-= integer[i-1];
}
else
n+= integer[i-1];
}
return n;
}
string IntegerToString(int n){
string s = to_string(n);
string s2;
for (int i = 0; i < s.length(); i++) {
switch (s[i]) {
case '1':
if (i == 0)
s2 += 'M';
else if (i == 1)
s2 += 'C';
else if (i == 2)
s2 += 'X';
else
s2 += 'I';
break;
case '2':
if (i == 0)
s2 += "MM";
else if (i == 1)
s2 += "CC";
else if (i == 2)
s2 += "XX";
else
s2 += "II";
break;
case '3':
if (i == 0)
s2 += "MMM";
else if (i == 1)
s2 += "CCC";
else if (i == 2)
s2 += "XXX";
else
s2 += "III";
break;
case '4':
if (i == 0)
s2 += "MMMM";
else if (i == 1)
s2 += "CD";
else if (i == 2)
s2 += "XL";
else
s2 += "IV";
break;
case '5':
if (i == 1)
s2 += "D";
else if (i == 2)
s2 += "L";
else
s2 += "V";
break;
case '6':
if (i == 1)
s2 += "DC";
else if (i == 2)
s2 += "LX";
else
s2 += "VI";
break;
case '7':
if (i == 1)
s2 += "DCC";
else if (i == 2)
s2 += "LXX";
else
s2 += "VII";
break;
case '8':
if (i == 1)
s2 += "DCCC";
else if (i == 2)
s2 += "LXXX";
else
s2 += "VIII";
break;
case '9':
if (i == 1)
s2 += "CM";
else if (i == 2)
s2 += "XC";
else
s2 += "IX";
break;
default:
break;
}
}
return s2;
}
/code_1916470.cpp: In function ‘std::string IntegerToString(int)’: /code_1916470.cpp:79:27: error: ‘to_string’ was not declared in this scope