#include <iostream>
using namespace std;
int main()
{
char w[100]={0};
char v[100]={0};
bool z= false;
while (cin>>w)
{
int a=0;
for (int i=0;i<100;i++)
{
if(w[i]=='M')
{
a+=1000;
}
else if(w[i]=='D')
{
a+=500;
}
else if(w[i]=='C')
{
if(w[i+1]=='D'||w[i+1]=='M')
{
a-=100;
}
else
{
a+=100;
}
}
else if(w[i]=='L')
{
a+=50;
}
else if(w[i]=='X')
{
if(w[i+1]=='L'||w[i+1]=='C')
{
a-=10;
}
else
{
a+=10;
}
}
else if(w[i]=='V')
{
a+=5;
}
else if(w[i]=='I')
{
if(w[i+1]=='v'||w[i+1]=='X')
{
a-=1;
}
else
{
a+=1;
}
}
if(w[0]=='#')
{
break;
}
}
if(w[0]=='#')
{
break;
}
cin>>v;
int b=0;
for (int i=0;i<100;i++)
{
if(v[i]=='M')
{
b+=1000;
}
else if(v[i]=='D')
{
b+=500;
}
else if(v[i]=='C')
{
if(v[i+1]=='D'||v[i+1]=='M')
{
b-=100;
}
else
{
b+=100;
}
}
else if(v[i]=='L')
{
b+=50;
}
else if(v[i]=='X')
{
if(v[i+1]=='L'||v[i+1]=='C')
{
b-=10;
}
else
{
b+=10;
}
}
else if(v[i]=='V')
{
b+=5;
}
else if(v[i]=='I')
{
if(v[i+1]=='v'||v[i+1]=='X')
{
b-=1;
}
else
{
b+=1;
}
}
if (v[i]=='#')
{
z=true;
break;
}
}
int c=0;
if(a>b)
{
c=a-b;
}
else if(b>a)
{
c=b-a;
}
else if(z==false)
{
cout<<"ZERO";
}
while (c>0)
{
if (c>=1000)
{
cout<<"M";
c-=1000;
}
else if(c>=900)
{
cout<<"CM";
c-=900;
}
else if(c>=500)
{
cout<<"D";
c-=500;
}
else if(c>=400)
{
cout<<"CD";
c-=400;
}
else if(c>=100)
{
cout<<"C";
c-=100;
}
else if(c>=90)
{
cout<<"XC";
c-=90;
}
else if(c>=50)
{
cout<<"L";
c-=50;
}
else if(c>=40)
{
cout<<"XL";
c-=40;
}
else if(c>=10)
{
cout<<"X";
c-=10;
}
else if(c>=9)
{
cout<<"IX";
c-=9;
}
else if(c>=5)
{
cout<<"V";
c-=5;
}
else if(c>=4)
{
cout<<"IV";
c-=4;
}
else if(c>=1)
{
cout<<"I";
c-=1;
}
}
cout<<endl;
for(int i=0;i<100;i+=1)
{
w[i]=0;
}
for(int i=0;i<100;i+=1)
{
v[i]=0;
}
a=0;
b=0;
}
return 0;
}