while True:
roman_dict = {
'I': 1, 'V': 5, 'X': 10,
'L': 50, 'C': 100, 'D': 500, 'M': 1000}
line=input().rstrip()
if line=="#":
break
a,b=line.split()
def len_2():
value_a=[]
value_b=[]
for i in a:
value_a.append(i)
ans_a=sum(list(map(roman_dict.get,value_a)))
for i in b:
value_b.append(i)
ans_b=sum(list(map(roman_dict.get,value_b)))
return(abs(ans_a-ans_b))
ans=len_2()
ans_place=[]
roman_number= [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
value_roman= ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
int_roman_dict=dict(zip(roman_number,value_roman))
def int_roman(x):
for i in roman_number:
while x>=i:
ans_place.append(int_roman_dict[i])
x-=i
if x==0:
break
return(ans_place)
int_roman(ans)
if ans_place==[]:
print('ZERO')
else:
print(''.join(ans_place))