while 1:
a=list(input().split())
if a[0]!='#': #如果是#就break
A=[0,0]
def Roman(x):#羅馬數字互轉
if x=="I":
return 1
elif x==1:
return "I"
elif x=="V":
return 5
elif x==5:
return "V"
elif x=="X":
return 10
elif x==10:
return "X"
elif x=="L":
return 50
elif x==50:
return "L"
elif x=="C":
return 100
elif x==100:
return "C"
elif x=="D":
return 500
elif x==500:
return "D"
elif x=="M":
return 1000
elif x==1000:
return "M"
for l in range(0,len(a)):#把羅馬字丟進b並轉換
b=list(a[l])
for i in range(0,len(b)):
if b[i]=='I':
b[i]=Roman(b[i])
elif b[i]=='V':
b[i]=Roman(b[i])
elif b[i]=='X':
b[i]=Roman(b[i])
elif b[i]=='L':
b[i]=Roman(b[i])
elif b[i]=='C':
b[i]=Roman(b[i])
elif b[i]=='D':
b[i]=Roman(b[i])
elif b[i]=='M':
b[i]=Roman(b[i])
A[l]+=b[i]#A裡面存前面值跟後面值的相加
c=abs(A[0]-A[1])#相減取絕對值給C
q=[]
if c==0:
print("ZERO")
for k in (1000,500,100,50,10,5,1):#把C拆解丟給q
if c!=0:
while 1:
if c>=k:
c=c-k
q.append(k)
else:
break
e=[]
g=[]
for m in range(len(q)):#把q還原羅馬給e
e.append(Roman(q[m]))
for y in range(10):#如果次數有四次判斷前面能不能相加或直接相減
if e.count('C')==4:
if e[e.index('C')-1]=='D':
del e[e.index('C')-1:e.index('C')+2]
e[e.index('C')+1]="M"
else:
del e[e.index('C')+1:e.index('C')+3]
e[e.index('C')+1]="D"
if e.count('L')==4:
if e[e.index('L')-1]=='C':
del e[e.index('L')-1:e.index('L')+2]
e[e.index('L')+1]="D"
else:
del e[e.index('L')+1:e.index('L')+3]
e[e.index('L')+1]="C"
if e.count('X')==4:
if e[e.index('X')-1]=='L':
del e[e.index('X')-1:e.index('X')+2]
e[e.index('X')+1]="C"
else:
del e[e.index('X')+1:e.index('X')+3]
e[e.index('X')+1]="L"
if e.count('V')==4:
if e[e.index('V')-1]=='X':
del e[e.index('V')-1:e.index('V')+2]
e[e.index('V')+1]="L"
else:
del e[e.index('V')+1:e.index('V')+3]
e[e.index('V')+1]="X"
if e.count('I')==4:
if e[e.index('I')-1]=='V':
del e[e.index('I')-1:e.index('I')+2]
e[e.index('I')+1]="X"
else:
del e[e.index('I')+1:e.index('I')+3]
e[e.index('I')+1]="V"
h=""
for t in range(len(e)):
h+=e[t]
print(h)
else:
break