#include <bits/stdc++.h>
using namespace std;
int r_n(string s){
map<char, int> m;
m['I'] = 1; m['V'] = 5; m['X'] = 10; m['L'] = 50; m['C'] = 100; m['D'] = 500; m['M'] = 1000;
int num = 0;
if(s.length() == 1) num = m[s[0]];
else if(s == "ZERO") num = 0;
else{
for(int i = 0; i < s.length(); i++){
if(m[s[i+1]]<=m[s[i]] && i+1<s.length()) num+=m[s[i]];
else if(m[s[i]]<m[s[i+1]] && i+1<s.length()){
num+=m[s[i+1]];
num-=m[s[i]];
i++;
}
else if(i == s.length()-1){
if(m[s[i]]<=m[s[i-1]]) num+=m[s[i]];
else if(m[s[i-1]]<m[s[i]]){
num+=m[s[i]];
num-=m[s[i-1]];
}
}
}
}
return num;
}
string n_r(int n){
string s = "";
int cnt = 0;
for(cnt; 0<n; cnt++, n/=10){
int a = n%10;
if(a<=3){
for(int i = 0; i<a; i++){
if(cnt == 0) s+="I";
if(cnt == 1) s+="X";
if(cnt == 2) s+="C";
}
}
if(a == 4){
if(cnt == 0) s+="VI";
if(cnt == 1) s+="LX";
if(cnt == 2) s+="DC";
}
if(5<=a && a < 9){
if(cnt == 0){
for(int i = 0; i<a-5; i++) s+="I";
s+="V";
}
if(cnt == 1){
for(int i = 0; i<a-5; i++) s+="X";
s+="L";
}
if(cnt == 2){
for(int i = 0; i<a-5; i++) s+="C";
s+="D";
}
}
if(a == 9){
if(cnt == 0) s+="XI";
if(cnt == 1) s+="CX";
if(cnt == 2) s+="MC";
}
if(cnt == 3)
for(int i = 0; i<n; i++) s+="M";
}
reverse(s.begin(), s.end());
return s;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
string a = "", b = "";
while(cin >> a && a != "#"){
cin >> b;
int num = abs(r_n(a)-r_n(b));
if(num == 0) cout << "ZERO" << '\n';
else cout << n_r(num) << '\n';
}
return 0;
}