program j;

var x,y:integer;
    arr:Array[1..3000,1..3000] of char;
    command:String(5);
    a,b,c,d:integer;
    i,j:integer;
    text:String(255);
    pom:char;
    
function right_int_value(value,max:integer):integer;
 begin
  right_int_value := value;
  if ( value < 1 ) then right_int_value := 1;
  if ( value > max) then right_int_value := max;
 end;

function abs_value(v:integer):integer;
 begin
  abs_value := v;
  if v < 0 then abs_value := -v;
 end;

function right_line_value(x1,x2,y1,y2:integer):boolean;
 begin
  right_line_value := false;
  if ( (x1 = x2) AND (y1 <> y2) ) then right_line_value := true
  else if ( (x1 <> x2) AND (y1 = y2) ) then right_line_value := true
  else if ( (abs_value(x1-x2)) = (abs_value(y1-y2))) then right_line_value := true;
 end;

function line_print(x1,y1:integer; p:char):char;
var tmp:char;
 begin
  tmp := arr[x1][y1];
  if tmp = ' ' then line_print := p
  else if tmp = p then line_print := p
  else if ((tmp = '\') AND (p = '/')) then line_print := 'x'
  else if ((tmp = '/') AND (p = '\')) then line_print := 'x'
  else if ((tmp = '|') AND (p = '-')) then line_print := '+'
  else if ((tmp = '-') AND (p = '|')) then line_print := '+'
  else line_print := '*';
 end; 
 
procedure draw_line(x1,x2,y1,y2:integer);
var tmp:integer;
    toprint:char;
 begin
  toprint := ' ';
  { first swap the value if not in coret }
  if x1 > x2 then begin
   tmp := x1;
   x1 := x2;
   x2 := tmp;
   tmp := y1;
   y1 := y2;
   y2 := tmp;
  end;
 
 if right_line_value(x1,x2,y1,y2) = false then return;
 { draw }
  if ( (x1 = x2) AND (y1 <> y2)) then
   begin
    for i:=y1 to y2 do begin
     arr[x1][i] := line_print(x1,i,'|');
    end;
   end
   else if ( (x1 <> x2) AND (y1 = y2)) then
    begin
     for i:=x1 to x2 do begin
      arr[i][y1] := line_print(i, y1, '-')
     end;
    end
   else if ( y1 > y2) then
    begin
     for i:=0 to (x2-x1) do begin
      arr[x1+i][y1-i] := line_print(x1 + i, y1 - i, '/');
     end;
    end
   else if ( y2 > y1) then
    begin
     for i:=0 to (x2-x1) do begin
      arr[x1+i][y1+i] := line_print(x1 + i, y1 + i, '\');
     end; 
    end;
 
 end;

procedure print_arr;
 begin
   write('+');
   for i:=1 to x do
    write('-');
   writeln('+');
   
   for i:=1 to y do begin
    write('|');
    for j:=1 to x do begin
     write(arr[j][i]);
    end;
    writeln('|') ;
   end;
   
   write('+');
   for i:=1 to x do
    write('-');
  writeln('+');
  writeln; 
 end;

procedure clear_text(text:String);
 begin
  for i:=1 to 255 do
   text[i] := ' ';
 end;
 
function right_text(text:String):boolean;
 var k:integer;
     ch:char;
 begin
  k:=1;
  right_text := true;
  while ((text[k] <> ' ') AND (k < 255)) do
   begin
    ch := text[k];
    if ord(ch) = 0 then break;
    if ord(ch) < 48 then
     return false
    else if ord(ch) > 90 then
     return false
    else if (((ord(ch) >= 57) AND (ord(ch) <= 65))) then
     return false;
    inc(k);
   end;
   return true;
 end;

procedure draw_text(x1,y1:integer; text:String);
var k,l:integer;

 begin
  if (right_text(text) = false) then return;
  k:= 1;
  l:=length(text);
  while  (((text[k] <> ' ') AND (ord(text[k]) <> 0)) AND ((k - 1 + x1) <= x ) AND (k <= l)) do
   begin
    if (ord(text[k]) = 0) then break;
    if ((arr[x1 + k - 1][y1] = ' ') OR ( arr[x1 + k - 1][y1] = text[k])) then
     begin
      arr[x1 + k - 1][y1] := text[k]
     end 
    else  begin
     arr[x1 + k - 1][y1] := '*';  
    end;
    inc(k);
   end;
 end;

procedure point(x1,y1:integer);
 begin
  if ((arr[x1,y1] = ' ') OR (arr[x1,y1] = 'o')) then
   arr[x1,y1] := 'o'
  else
   arr[x1,y1] := '*';
 end;

procedure clear_arrea(x1,x2,y1,y2:integer);
var tmp:integer;
    o,p:integer;
 begin
  if x1 > x2 then begin
   tmp := x1;
   x1 := x2;
   x2 := tmp;
  end;
  if y1 > y2 then begin
   tmp := y1;
   y1 := y2;
   y2 := tmp;
  end; 
  for o:=x1 to x2 do
   for p:=y1 to y2 do
    arr[o,p] := ' ';
 end;
begin
 
 while ( true ) do
  begin
   read(x);
   readln(y);  { read the size }
   if ((x = 0) AND (y = 0)) then break; { end }
    
   { first clear array }
   for i:=1 to x do begin
    for j:=1 to y do begin
      arr[i][j] := ' ';
     end;
   end;
   while ( true )  do 
    begin { list of parameter }
       { read the command }
       command := '';
       for i:=1 to 5 do begin
	 read(pom);
	 command := command + pom;
       end;
    if command = 'LINE ' then
     begin { read line parameter }
        read(a);
	a := right_int_value(a, x);
	read(b);
	b := right_int_value(b, y);
	read(c);
	c := right_int_value(c, x);
	readln(d);
	d := right_int_value(d, y);
	draw_line(a,c,b,d);
     end
    else if command = 'TEXT ' then
     begin
        read(a);
	read(b);
	readln(text);
	text := substr(text, 2);
	if ((a <= x) AND (b <= y)) then
	 draw_text(a,b,text);
	clear_text(text);
     end
    else if command = "CLEAR" then
     begin
        read(a);
	a:= right_int_value(a,x);
	read(b);
	b:= right_int_value(b,y);
	read(c);
	c:= right_int_value(c,x);
	readln(d);
	d:= right_int_value(d,y);
	clear_arrea(a,c,b,d);
     end 
    else if command = "POINT" then
     begin
       read(a);
       readln(b);
       if ((a <= x) AND (b <= y)) then
        point(a,b);
     end
    else if command = "PRINT" then
     begin
      break;
     end;
   end;
   
   print_arr;
   
  end;
end.