/*規則
'I'=1,'V'=5,'X'=10,'L'=50,'C'=100,'D'=500,'M'=1000
注意 900='C''M',90 ='X''C',9 ='I''X' 400 ='C''D',40 ='X''L',4 ='I''V'
*/
下為解答
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
string a,b=b+'#',c;
while (cin>>a)
{
if (a.at(0)=='#')
break;
cin>>b;
c.clear();
int sum1=0,sum2=0,A[a.length()],B[b.length()],sum3=0;
for (int i=0; i<a.length(); i++)
if(a.at(i)=='M')
A[i]=1000;
else if(a.at(i)=='D')
A[i]=500;
else if(a.at(i)=='C')
A[i]=100;
else if(a.at(i)=='L')
A[i]=50;
else if(a.at(i)=='X')
A[i]=10;
else if(a.at(i)=='V')
A[i]=5;
else if(a.at(i)=='I')
A[i]=1;
for (int i=0; i<b.length(); i++)
if(b.at(i)=='M')
B[i]=1000;
else if(b.at(i)=='D')
B[i]=500;
else if(b.at(i)=='C')
B[i]=100;
else if(b.at(i)=='L')
B[i]=50;
else if(b.at(i)=='X')
B[i]=10;
else if(b.at(i)=='V')
B[i]=5;
else if(b.at(i)=='I')
B[i]=1;
for (int i=0; i<a.length(); i++)
sum1=sum1+A[i];
for (int i=0; i<b.length(); i++)
sum2=sum2+B[i];
for (int i=0; i<a.length()-1; i++)
if (A[i]<A[i+1])
sum1=sum1-2*A[i];
for (int i=0; i<b.length()-1; i++)
if (B[i]<B[i+1])
sum2=sum2-2*B[i];
sum3=sum1-sum2;
if(sum3<0)
sum3=-sum3;
while (sum3>=1000)
{
c=c+'M';
sum3=sum3-1000;
}
if (sum3>=900)
{
c=c+'C';
c=c+'M';
sum3=sum3-900;
}
if (sum3>=500)
{
c=c+'D';
sum3=sum3-500;
}
if (sum3>=400)
{
c=c+'C';
c=c+'D';
sum3=sum3-400;
}
while (sum3>=100)
{
c=c+'C';
sum3=sum3-100;
}
if (sum3>=90)
{
c=c+'X';
c=c+'C';
sum3=sum3-90;
}
if (sum3>=50)
{
c=c+'L';
sum3=sum3-50;
}
if (sum3>=40)
{
c=c+'X';
c=c+'L';
sum3=sum3-40;
}
while (sum3>=10)
{
c=c+'X';
sum3=sum3-10;
}
if (sum3>=9)
{
c=c+'I';
c=c+'X';
sum3=sum3-9;
}
if (sum3>=5)
{
c=c+'V';
sum3=sum3-5;
}
if (sum3>=4)
{
c=c+'I';
c=c+'V';
sum3=sum3-4;
}
while (sum3>=1)
{
c=c+'I';
sum3=sum3-1;
}
if(c.length()==0)
cout<<"ZERO"<<endl;
else
cout<<c<<endl;
}
}