#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char word[100][2][100];
int stop=0;
int length=-1;
for(int i=0;i<100;i++){
if(stop==1){
break;
}
for(int j=0;j<2;j++){
scanf("%s",word[i][j]);
for(int k=0;k<10;k++){
if(word[i][j][k]=='#'){
stop=1;
break;
}
}
if(stop==1){
break;
}
}
length++;
}
int number[100][2][100];
for(int i=0;i<length;i++){
for(int j=0;j<2;j++){
for(int k=0;k<strlen(word[i][j]);k++){
if(word[i][j][k]=='I'){
number[i][j][k]=1;
}
if(word[i][j][k]=='V'){
number[i][j][k]=5;
}
if(word[i][j][k]=='X'){
number[i][j][k]=10;
}
if(word[i][j][k]=='L'){
number[i][j][k]=50;
}
if(word[i][j][k]=='C'){
number[i][j][k]=100;
}
if(word[i][j][k]=='D'){
number[i][j][k]=500;
}
if(word[i][j][k]=='M'){
number[i][j][k]=1000;
}
}
}
}
int output[100];
for(int i=0;i<length;i++){
int temp[2];
temp[0]=temp[1]=0;
for(int j=0;j<2;j++){
for(int k=0;k<strlen(word[i][j]);k++){
if(number[i][j][k]>=number[i][j][k+1]&&k<strlen(word[i][j])-1){
temp[j]=temp[j]+number[i][j][k];
}
if(number[i][j][k]<number[i][j][k+1]&&k<strlen(word[i][j])-1){
temp[j]=temp[j]-number[i][j][k];
}
if(k==strlen(word[i][j])-1){
temp[j]=temp[j]+number[i][j][k];
}
}
}
if(temp[1]>temp[0]){
int temp2;
temp2=temp[0];
temp[0]=temp[1];
temp[1]=temp2;
}
output[i]=temp[0]-temp[1];
}
char a[100][100];
int temp2;
int output2[100];
for(int i=0;i<length;i++){
output2[i]=output[i];
}
for(int i=0;i<length;i++){
temp2=0;
while(output[i]>=1000){
a[i][temp2]='M';
output[i]=output[i]-1000;
temp2++;
}
while(output[i]>=500){
a[i][temp2]='D';
output[i]=output[i]-500;
temp2++;
}
while(output[i]>=100){
a[i][temp2]='C';
output[i]=output[i]-100;
temp2++;
}
while(output[i]>=50){
a[i][temp2]='L';
output[i]=output[i]-50;
temp2++;
}
while(output[i]>=10){
a[i][temp2]='X';
output[i]=output[i]-10;
temp2++;
}
while(output[i]>=5){
a[i][temp2]='V';
output[i]=output[i]-5;
temp2++;
}
while(output[i]>=1){
a[i][temp2]='I';
output[i]--;
temp2++;
}
}
int I,X,C;
I=X=C=0;
char temp[100];
int k=0;
for(int i=0;i<length;i++){
temp[0]='\0';
if(output2[i]==0){
printf("ZERO\n");
}
else{
for(int j=0;j<strlen(a[i]);j++){
if(a[i][j]=='I'){
I++;
}
if(a[i][j]=='X'){
X++;
}
if(a[i][j]=='C'){
C++;
}
}
k=0;
if(I==4||X==4||C==4){
for(int j=0;j<strlen(a[i]);j++){
temp[k]=a[i][j];
if(C==4&&a[i][j]=='C'){
k++;
temp[k]='D';
if(temp[k-2]=='D'){
temp[k-2]='C';
temp[k-1]='M';
temp[k]='\0';
k--;
}
j=j+3;
}
if(X==4&&a[i][j]=='X'){
k++;
temp[k]='L';
if(temp[k-2]=='L'){
temp[k-2]='X';
temp[k-1]='C';
temp[k]=='\0';
k--;
}
j=j+3;
}
if(I==4&&a[i][j]=='I'){
k++;
temp[k]='X';
if(temp[k-2]=='X'){
temp[k-2]='I';
temp[k-1]='X';
temp[k]=='\0';
k--;
}
j=j+3;
}
k++;
}
printf("%s\n",temp);
}
else{
printf("%s\n",a[i]);
}
}
}
return 0;
}