#include<stdio.h>
#include<stdlib.h>
char a[2][9999];
int trans(int x)
{
int i,total=0;
for(i=0;a[x][i];i++)
{
if(a[x][i]=='I')total+=1;
else if(a[x][i]=='V')
{
if(a[x][i-1]=='I')total+=3;
else total+=5;
}
else if(a[x][i]=='X')
{
if(a[x][i-1]=='I')total+=8;
else total+=10;
}
else if(a[x][i]=='L')
{
if(a[x][i-1]=='X')total+=30;
else total+=50;
}
else if(a[x][i]=='C')
{
if(a[x][i-1]=='X')total+=80;
else total+=100;
}
else if(a[x][i]=='D')
{
if(a[x][i-1]=='C')total+=300;
else total+=500;
}
else if(a[x][i]=='M')
{
if(a[x][i-1]=='C')total+=800;
else total+=1000;
}
}
return total;
}
void turn(int a)
{
if(a>=1000)
{
a-=1000;
printf("%c",'M');
}
else if(a>=900)
{
a-=900;
printf("%c%c",'C','M');
}
else if(a>=500)
{
a-=500;
printf("%c",'D');
}
else if(a>=400)
{
a-=400;
printf("%c%c",'C','D');
}
else if(a>=100)
{
a-=100;
printf("%c",'C');
}
else if(a>=90)
{
a-=90;
printf("%c%c",'X','C');
}
else if(a>=50)
{
a-=50;
printf("%c",'L');
}
else if(a>=40)
{
a-=40;
printf("%c%c",'X','L');
}
else if(a>=10)
{
a-=10;
printf("%c",'X');
}
else if(a>=9)
{
a-=9;
printf("%c%c",'I','X');
}
else if(a>=5)
{
a-=5;
printf("%c",'V');
}
else if(a>=4)
{
a-=4;
printf("%c%c",'I','V');
}
else if(a>=1)
{
a-=1;
printf("%c",'I');
}
if(a!=0)turn(a);
}
main()
{
while(scanf("%s",&a[0])&&a[0][0]!='#')
{
scanf("%s",&a[1]);
int n;
if(trans(0)-trans(1)<0)n=0-(trans(0)-trans(1));
else n=trans(0)-trans(1);
if(n==0)printf("ZERO");
else turn(n);
printf("\n");
}
}