program expr;

var
 reg: array[1..10] of integer;
 assigned: array[1..10] of boolean;

function tonum(s:string):integer;
var
 i, num:integer;
begin
 num:=0;
 for i:=1 to length(s) do begin
  num:=num*10;
  num:=num+ord(s[i])-ord('0');
 end;
 tonum:=num;
end;


function toroman(num:integer):string;
var
 count, i:integer;
 roman: string;

begin
 roman:= '';

 count := num div 1000;
 num := num mod 1000; 
 for i:=1 to count do
  roman:=roman+'M';

 count := num div 900;
 num := num mod 900; 
 for i:=1 to count do
  roman:=roman+'CM';

 count := num div 500;
 num := num mod 500; 
 for i:=1 to count do
  roman:=roman+'D';

 count := num div 400;
 num := num mod 400; 
 for i:=1 to count do
  roman:=roman+'CD';

 count := num div 100;
 num := num mod 100; 
 for i:=1 to count do
  roman:=roman+'C';
 
 count := num div 90;
 num := num mod 90; 
 for i:=1 to count do
  roman:=roman+'XC';

 count := num div 50;
 num := num mod 50; 
 for i:=1 to count do
  roman:=roman+'L';

 count := num div 40;
 num := num mod 40; 
 for i:=1 to count do
  roman:=roman+'XL';

 count := num div 10;
 num := num mod 10; 
 for i:=1 to count do
  roman:=roman+'X';

 count := num div 9;
 num := num mod 9; 
 for i:=1 to count do
  roman:=roman+'IX';

 count := num div 5;
 num := num mod 5; 
 for i:=1 to count do
  roman:=roman+'V';

 count := num div 4;
 num := num mod 4; 
 for i:=1 to count do
  roman:=roman+'IV';

 count := num;
 for i:=1 to count do
  roman:=roman+'I';

 if(length(roman)=0) then
  roman:='O';
 toroman:=roman;
end;

function toarab(roman:string):integer;
var
 num:integer;
begin
 num:=0;

 while(length(roman)>0) do begin
  if(roman[1]='M') then begin
   num:=num + 1000;
  roman:=copy(roman, 2, length(roman)-1);
  end;
 end;

 if(length(roman)>1) then begin
  if((roman[1]='C') and (roman[2]='M')) then begin
   num:=num + 900;
  roman:=copy(roman, 2, length(roman)-1);
  end;
 end;

 while(length(roman)>0) do begin
  if(roman[1]='D') then begin
   num:=num + 500;
  roman:=copy(roman, 2, length(roman)-1);
  end;
 end;

 if(length(roman)>1) then begin
  if((roman[1]='C') and (roman[2]='D')) then begin
   num:=num + 400;
  roman:=copy(roman, 2, length(roman)-1);
  end;
 end;

 while(length(roman)>0) do begin
  if(roman[1]='C') then begin
   num:=num + 100;
  roman:=copy(roman, 2, length(roman)-1);
  end;
 end;

 if(length(roman)>1) then begin
  if((roman[1]='X') and (roman[2]='C')) then begin
   num:=num + 90;
  roman:=copy(roman, 2, length(roman)-1);
  end;
 end;

 while(length(roman)>0) do begin
  if(roman[1]='L') then begin
   num:=num + 50;
  roman:=copy(roman, 2, length(roman)-1);
  end;
 end;

 if(length(roman)>1) then begin
  if((roman[1]='X') and (roman[2]='L')) then begin
   num:=num + 40;
  roman:=copy(roman, 2, length(roman)-1);
  end;
 end;

 while(length(roman)>0) do begin
  if(roman[1]='X') then begin
   num:=num + 10;
  roman:=copy(roman, 2, length(roman)-1);
  end;
 end;

 if(length(roman)>1) then begin
  if((roman[1]='I') and (roman[2]='X')) then begin
   num:=num + 9;
  roman:=copy(roman, 2, length(roman)-1);
  end;
 end;

 while(length(roman)>0) do begin
  if(roman[1]='V') then begin
   num:=num + 5;
  roman:=copy(roman, 2, length(roman)-1);
  end;
 end;

 if(length(roman)>1) then begin
  if((roman[1]='I') and (roman[2]='V')) then begin
   num:=num + 4;
  roman:=copy(roman, 2, length(roman)-1);
  end;
 end;

  while(length(roman)>0) do begin
  if(roman[1]='I') then begin
   num:=num + 1000;
  roman:=copy(roman, 2, length(roman)-1);
  end;
 end;

 toarab:=num;
end;

procedure res;
var
 i:integer;
begin
 for i:=1 to 10 do begin
  reg[i]:=0;
  assigned[i]:=false;
 end;
end;



var
 cls:boolean;
 str, substr:string;
 assind, posi, valind, val, val1, val2, i, j, k:integer;
 c, opc:char;
begin
 cls:=false;
 str:='';
 while(not cls) do begin
  repeat
   read(c);
   str:=str+c;
  until(c='=')or(c='T');

  if(pos('QUIT', str) = 1) then begin
   cls:=true;
   writeln('Bye');
   break;
  end;


  if(pos('RESET', str) = 1) then begin
   res;
   writeln('Ready');
   continue;
  end;

  //posi:=pos('=', str);
  assind:=tonum(str);
 
  repeat
   read(c);
   str:=str + c;
  until(c='+')or(c='-')or(ord(c)=13)or(ord(c)=10);
  opc:=c;

  
  if(str[1] in ['0'..'9']) then begin
   valind:=tonum(str);

   if(assigned[valind]) then
    val1:=reg[valind]
   else begin
    writeln('Error');
    continue;
   end;
  end
  else begin
   val1:=toarab(str);    
  end;
  
  repeat

  repeat
   read(c);
   str:=str + c;
  until(c='+')or(c='-')or(ord(c)=13)or(ord(c)=10);

  if(str[1] in ['0'..'9']) then begin   
   valind:=tonum(copy(str, 1, posi-1));

   if(assigned[valind]) then
    val2:=reg[valind]
   else begin
    writeln('Error');
    continue;
   end;
  end
  else if(str[1] in ['A'..'Z']) then begin
   val2:=toarab(str);    
  end
  else begin
   val2:=-1;
  end;

  if(val2>=0) then begin
   if(opc='+') then
    val:=val1 + val2
   else
    val:=val1 - val2;
  end;

  opc:=c;
  until (val2<0);  
  
  if((val<0)or(val>10000))then begin
    writeln('Error');
    continue;
  end;
  
  reg[assind]:=val;
  assigned[assind]:=true;
  
  write(assind);
  write('=');
  writeln(toroman(val));
 end;
   
end.
