#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BOOL int
#define TRUE 1
#define FALSE 0
int main(int argc, const char * argv[]) {
int I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000;
char inputnumber[50];
int i, num1 = 0, num2 = 0, add = 0;
long int stringsize;
while(fgets(inputnumber,sizeof(inputnumber),stdin))
{
if(inputnumber[0] == 35)
break;
stringsize = strlen(inputnumber);
BOOL flag = FALSE;
for(i = 0;i < stringsize;i ++)
switch(inputnumber[i])
{
case 'I':
add += I;
break;
case 'V':
add += V;
break;
case 'X':
add += X;
break;
case 'L':
add += L;
break;
case 'C':
add += C;
break;
case 'D':
add += D;
break;
case 'M':
add += M;
break;
default:
if(flag == TRUE)
{
num2 = add;
num1 = num1 - num2;
add = 0;
}
else
{
num1 = add;
add = 0;
flag = TRUE;
}
break;
}
if(num1 == 0)
{
printf("ZERO");
}
else if(num1 < 0)
{
num1 *= -1;
}
while(num1 != 0)
{
if(num1 >= 1000)
{
num1 -= 1000;
printf("M");
}
else if(num1 >= 900)
{
num1 -= 900;
printf("CM");
}
else if(num1 >= 500)
{
num1 -= 500;
printf("D");
}
else if(num1 >= 400)
{
num1 -= 400;
printf("CD");
}
else if(num1 >= 100)
{
num1 -= 100;
printf("C");
}
else if(num1 >= 90)
{
num1 -= 90;
printf("XC");
}
else if(num1 >= 50)
{
num1 -= 50;
printf("L");
}
else if(num1 >= 40)
{
num1 -= 40;
printf("XL");
}
else if(num1 >= 10)
{
num1 -= 10;
printf("X");
}
else if(num1 >= 9)
{
num1 -= 9;
printf("IX");
}
else if(num1 >= 5)
{
num1 -= 5;
printf("V");
}
else if(num1 >= 4)
{
num1 -= 4;
printf("IV");
}
else if(num1 >= 1)
{
num1 -= 1;
printf("I");
}
}
printf("\n");
}
return 0;
}