#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int sum=0,Num[20],Num1=0,Num2=0,Rome[13]= {1000,900,500,400,100,90,50,40,10,9,5,4,1};
void TransfromToRome(int result);
void TransfromToNum(char N1,int i);
int combine(int sum,int i);
int main()
{
char N1,N2;
while(true)
{
int i=0,result;
memset(Num,0,sizeof(Num));
sum=0;
while(N1!='#')
{
i++;
N1=cin.get();
if(N1==' ')
break;
TransfromToNum(N1,i);
}
if(N1=='#')
break;
Num1=combine(sum,i);
i=0;
memset(Num,0,sizeof(Num));
sum=0;
//cout<<Num1;
while(true)
{
i++;
N2=cin.get();
if(N2=='\n')
break;
TransfromToNum(N2,i);
}
Num2=combine(sum,i);
result=abs(Num1-Num2);
if(result==0)
cout<<"ZERO"<<endl;
else
TransfromToRome(result);
}
return 0;
}
void TransfromToNum(char N1,int i)
{
if(N1=='#')
Num[i]=0;
else if(N1=='I')
Num[i]=1;
else if(N1=='V')
Num[i]=5;
else if(N1=='X')
Num[i]=10;
else if(N1=='L')
Num[i]=50;
else if(N1=='C')
Num[i]=100;
else if(N1=='D')
Num[i]=500;
else if(N1=='M')
Num[i]=1000;
}
int combine(int sum,int i)
{
for(int a=2; a<=i; a++)
{
if(Num[a]>Num[a-1])
{
sum+=(Num[a]-Num[a-1]);
a++;
}
else
sum+=Num[a-1];
}
return sum;
}
void TransfromToRome(int result)
{
for(int b=0; b<13; b++)
{
while(result-Rome[b]>=0)
{
result=result-Rome[b];
if(Rome[b]==1000)
cout<<"M";
if(Rome[b]==900)
cout<<"CM";
if(Rome[b]==500)
cout<<"D";
if(Rome[b]==400)
cout<<"CD";
if(Rome[b]==100)
cout<<"C";
if(Rome[b]==90)
cout<<"XC";
if(Rome[b]==50)
cout<<"L";
if(Rome[b]==40)
cout<<"XL";
if(Rome[b]==10)
cout<<"X";
if(Rome[b]==9)
cout<<"IX";
if(Rome[b]==5)
cout<<"V";
if(Rome[b]==4)
cout<<"IV";
if(Rome[b]==1)
cout<<"I";
}
}
cout<<endl;
}