import java.util.Scanner;
public class d013{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
String s1,s2;
int n1,n2,ans;
while(sc.hasNext()){
s1=sc.next();
if(s1.charAt(0)=='#')
return;
s2=sc.next();
if(s1.equals(s2)){
System.out.println("ZERO");
}else{
n1=turntoint(s1);n2=turntoint(s2);
ans=Math.abs(n1-n2);
turntorm(ans);
}
}
}
public static int turntoint(String str){
char x[] = new char[30];
char y[]=str.toCharArray();
int add=0;
for(int i=0;i<y.length;i++){
x[i]=y[i];
}
for(int i=1;i<=x.length;i++){
if(i>y.length) break;
switch(x[i-1]){
case 'M':
add+=1000; break;
case 'D':
add+=500; break;
case 'C':
if(x[i]!='M') add+=100;
else add-=100; break;
case 'L':
add+=50; break;
case 'X':
if(x[i]!='L' || x[i]!='C') add+=10;
else add-=10; break;
case 'V':
add+=5; break;
case 'I':
if(x[i]=='V' || x[i]=='X') add-=1;
else add++; break;
}
}return add;
}
public static void turntorm(int x){
String roma[] = new String[30]; int i=0;
do{
if(x>=1000)
{roma[i]="M"; x-=1000;i++;continue;}
else if(x>=900)
{roma[i]="CM"; x-=900;i++;continue;}
else if(x>=500)
{roma[i]="D"; x-=500;i++;continue;}
else if(x>=400)
{roma[i]="CD"; x-=400;i++;continue;}
else if(x>=100)
{roma[i]="C"; x-=100;i++;continue;}
else if(x>=90)
{roma[i]="XC"; x-=90;i++;continue;}
else if(x>=50)
{roma[i]="L"; x-=50;i++;continue;}
else if(x>=40)
{roma[i]="XL"; x-=40;i++;continue;}
else if(x>=10)
{roma[i]="X"; x-=10;i++;continue;}
else if(x>=9)
{roma[i]="IX"; x-=9;i++;continue;}
else if(x>=5)
{roma[i]="V"; x-=5;i++;continue;}
else if(x>=4)
{roma[i]="IV"; x-=4;i++;continue;}
else
{roma[i]="I"; x--;i++;continue;}
}while(x!=0);
for(int j=0;j<i;j++)
System.out.print(roma[j]);
System.out.println();
}
}
卡在第7個... 可是自己測 沒有問題 一直找不到 錯在哪裡