#include <iostream>
int main(int argc, char** argv) {
char a[17],b[17];
int i,t,t2,t3;
while(scanf("%s",&a))
{
t=0;
if(a[0]=='#')
break;
for(i=0;i<17;i++)
{
if(a[i] == 'M')
{
t+=1000;
if(a[i-1]=='C')
t-=200;
}
if(a[i]=='D')
{
t+=500;
if(a[i-1]=='C')
t-=200;
}
if(a[i]=='C')
{
t+=100;
if(a[i-1]=='X')
t-=20;
}
if(a[i]=='L')
{
t+=50;
if(a[i-1]=='X')
t-=20;
}
if(a[i]=='X')
{
t+=10;
if(a[i-1]=='I')
t-=2;
}
if(a[i]=='V')
{
t+=5;
if(a[i-1]=='I')
t-=2;
}
if(a[i]=='I')
t+=1;
}
t2=0;
scanf("%s",&b);
if(b[0] == '#')
break;
for(i=0;i<17;i++)
{
if(b[i] == 'M')
{
t2+=1000;
if(b[i-1]=='C')
t2-=200;
}
if(b[i]=='D')
{
t2+=500;
if(b[i-1]=='C')
t2-=200;
}
if(b[i]=='C')
{
t2+=100;
if(b[i-1]=='X')
t2-=20;
}
if(b[i]=='L')
{
t2+=50;
if(b[i-1]=='X')
t2-=20;
}
if(b[i]=='X')
{
t2+=10;
if(b[i-1]=='I')
t2-=2;
}
if(b[i]=='V')
{
t2+=5;
if(b[i-1]=='I')
t2-=2;
}
if(b[i]=='I')
t2+=1;
}
if(t==t2)
{
t3=0;
printf("ZERO");
}
else if(t>t2)
t3=t-t2;
else
t3=t2-t;
while(t3>0)
{
if(t3>=1000)
{
t3-=1000;
printf("M");
}
else if(t3>=900)
{
t3-=900;
printf("CM");
}
else if(t3>=500)
{
t3-=500;
printf("D");
}
else if(t3>=400)
{
t3-=400;
printf("CD");
}
else if(t3>=100)
{
t3-=100;
printf("C");
}
else if(t3>=90)
{
t3-=90;
printf("XC");
}
else if(t3>=50)
{
t3-=50;
printf("L");
}
else if(t3>=40)
{
t3-=40;
printf("XL");
}
else if(t3>=10)
{
t3-=10;
printf("X");
}
else if(t3>=9)
{
t3-=9;
printf("IX");
}
else if(t3>=5)
{
t3-=5;
printf("V");
}
else if(t3>=4)
{
t3-=4;
printf("IV");
}
else
{
t3-=1;
printf("I");
}
}
printf("\n");
}
return 0;
}