#include <stdio.h>
#include <string.h>
char roman[7] = { 'I','V','X','L','C','D','M' };
char *toroman[13] = { "M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I" };
int number[7] = { 1,5,10,50,100,500,1000 };
int tonumber[13] = { 1000,900,500,400,100,90,50,40,10,9,5,4,1 };
int InputRoman(char *pch)
{
int value = 0, c1 = 1001, c2;
for (int i = 0; i < (int)strlen(pch); i++)
{
for (int j = 0; j < 7; j++)
{
if (pch[i] == roman[j])
{
c2 = number[j];
value += number[j];
break;
}
}
if (c2 > c1)
value -= c1 * 2;
c1 = c2;
}
return value;
}
void OutputRoman(int ans)
{
while (ans)
{
for (int i = 0; i < 13; i++)
{
if (ans >= tonumber[i])
{
ans -= tonumber[i];
printf("%s", toroman[i]);
}
}
}
printf("\n");
}
int main()
{
char input[16];
while (strcmp(gets(input),"#") != 0)
{
int num[2],cnt = 0;
char *pch;
pch = strtok(input, " ");
while (pch != NULL)
{
num[cnt] = InputRoman(pch);
cnt++;
pch = strtok(NULL, " ");
}
int ans = num[0] - num[1];
if (ans)
OutputRoman(ans);
else
printf("ZERO\n");
}
return 0;
}