#include <stdio.h>
#include <string.h>
int rome_to_math( char num )
{
switch ( num ){
case 'I' : return 1 ;
case 'V' : return 5 ;
case 'X' : return 10 ;
case 'L' : return 50 ;
case 'C' : return 100 ;
case 'D' : return 500 ;
case 'M' : return 1000 ;
}
}
void math_to_rome( int num )
{
char *thousand[] = { "" , "M" , "MM" , "MMM" } ;
char *hundred[] = { "" , "C" , "CC" , "CCC" , "CD" , "D" , "DC" , "DCC" , "DCCC" , "CM" } ;
char *ten[] = { "" , "X" , "XX" , "XXX" , "XL" , "L" , "LX" , "LXX" , "LXXX" , "XC" } ;
char *one[] = { "" , "I" , "II" , "III" , "IV" , "V" , "VI" , "VII" , "VIII" , "IX" } ;
printf( "%s%s%s%s\n" , thousand[ num / 1000 ] , hundred[ ( num / 100 ) % 10 ]
, ten[ ( num / 10 ) % 10 ] , one[ num % 10 ] ) ;
}
int main()
{
char ch_1[ 40 ] = {} , ch_2[ 40 ] = {} ;
while( scanf( "%s" , ch_1 ) != EOF && ch_1[ 0 ] != '#' ){
scanf ( "%s" , ch_2 ) ;
int a = 0 , b = 0 , i , num = 0 ;
for( i = 0 ; i < strlen( ch_1 ) ; i ++ ){
if ( rome_to_math( ch_1[ i ] ) < rome_to_math( ch_1[ i + 1 ] ) ){
a += rome_to_math( ch_1[ i + 1 ] ) - rome_to_math( ch_1[ i ] ) ;
i ++ ;
}
else
a += rome_to_math( ch_1[ i ] ) ;
}
for( i = 0 ; i < strlen( ch_2 ) ; i ++ ){
if ( rome_to_math( ch_2[ i ] ) < rome_to_math( ch_2[ i + 1 ] ) ){
b += rome_to_math( ch_2[ i + 1 ] ) - rome_to_math( ch_2[ i ] ) ;
i ++ ;
}
else
b += rome_to_math( ch_2[ i ] ) ;
}
num = ( a > b ? a - b : b - a ) ;
if ( num > 0 )
math_to_rome ( num ) ;
else
printf ( "ZERO\n" ) ;
}
return 0 ;
}