#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std;
/*
I=1
IV=4
V=5
IX=9
X=10
XL=40
L=50
XC=90
C=100
CD=400
D=500
CM=900
M=1000
*/
int csn(char);
int crl(char,char);
string sic(int);
int main()
{
string test,num[2];
while(getline(cin,test)){
int lon=0,lon1[2]={0},i=0,j=0,k=0,num1[2]={0},che[2][1000]={0};
if(test=="#"){
break;
}else{
lon=test.length();
lon--;
for(i=0;i<=lon;i++){
if(test[i]==' '){
j=1;
}
if(test[i]!=' '){
num[j]+=test[i];
}
}
if(num[0]!=""&&num[1]!=""){
for(i=0;i<=1;i++){
lon1[i]=(num[i].length()-1);
for(j=lon1[i];j>=0;j--){
if(j!=lon1[i]){
if(crl(num[i][j],num[i][j+1])==0){
che[i][j]=csn(num[i][j]);
num1[i]+=che[i][j];
}else if(crl(num[i][j],num[i][j+1])==1){
che[i][j]=csn(num[i][j]);
num1[i]-=che[i][j];
}
}else{
che[i][j]=csn(num[i][j]);
num1[i]+=che[i][j];
}
}
}
}
k=num1[0]-num1[1];
k=abs(k);
if(k==0){
cout<<"ZERO"<<endl;
}else{
cout<<sic(k)<<endl;
}
}
}
}
int csn(char a){
switch(a){
case 'I':
return 1;
break;
case 'V':
return 5;
break;
case 'X':
return 10;
break;
case 'L':
return 50;
break;
case 'C':
return 100;
break;
case 'D':
return 500;
break;
case 'M':
return 1000;
break;
}
}
int crl(char a,char b){
if(a=='I'){
if(b=='V'||b=='X'){
return 1;
}else{
return 0;
}
}else if(a=='X'){
if(b=='L'||b=='C'){
return 1;
}else{
return 0;
}
}else if(a=='C'){
if(b=='D'||b=='M'){
return 1;
}else{
return 0;
}
}else{
return 0;
}
}
string sic(int k){
string M[4]={"","M","MM","MMM"};
string C[10]={"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
string X[10]={"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
string I[10]={"","I","II","III","IV","V","VI","VII","VIII","IX"};
return M[k/1000]+C[(k%1000)/100]+X[(k%100)/10]+I[k%10];
}