program roman_expresions;

var input,znak,output,znaky:string[20];
    l,i,j,cislo,plus:integer;
    c1,c2,c1c:char;

procedure premena(znakyf:string; var cislof:integer);
var x,y,lf,jf:integer;
    vyz:string[3];
    

begin
lf:=length(znakyf);
vyz:=copy(znakyf,1,1);
cislof:=0;

if vyz = 'M' then x:=1000;
if vyz = 'D' then x:=500;
if vyz = 'C' then x:=100;
if vyz = 'L' then x:=50;
if vyz = 'X' then x:=10;
if vyz = 'V' then x:=5;
if vyz = 'I' then x:=1;
if vyz = 'O' then x:=0;

for jf:=2 to lf do
		begin
		vyz:=copy(znakyf,jf,1);
		if vyz = 'M' then y:=1000;
		if vyz = 'D' then y:=500;
		if vyz = 'C' then y:=100;
		if vyz = 'L' then y:=50;
		if vyz = 'X' then y:=10;
		if vyz = 'V' then y:=5;
		if vyz = 'I' then y:=1;
		if vyz = 'O' then y:=0;
				
		if x<y then cislof:=cislof+(y-x)
		       else
			   begin 
			   cislof:=x;
	       		   x:=y;
			   if jf=lf then cislof:=cislof+y;
			   end;		
		end;  

end;


				 
				   




    
begin
j:=0;
repeat	
	begin
	read(c1);
	read(c2);
	if (c1<>'1') or (c2<>'=') then output:='bye'
	else
		begin  
		output:='1=';
		znaky:='';
		readln(input);
		l:=length(input);
		input:=concat(input,' '); 		
		for i:=1 to l+1 do 
				begin
				znak:=copy(input,i,1);
				
				if ((znak<>'+') and (znak<>'-') and (znak <> ' ')) then
								     	      begin
								              znaky:=concat(znaky,znak);
	  							              writeln(znaky);
									      
									      end
				else 
					begin
					premena(znaky,cislo);					
					writeln(cislo);
					j:=j+1;					
					if j=1 then
					       plus:=cislo	
					       else						
						begin
						if (c1c='+') then plus:=plus+cislo;
						if (c1c='-') then plus:=plus-cislo;
					        end;
					c1c:=znak;
					znaky:='';					
					end;
				end;
		end;
	
	writeln(plus);
		
	
	writeln(output);
	end;
until ((c1 = 'Q') and (c2 = 'U') and (input = 'IT'));

end.
