/** maze game server
 */

import java.io.*;
import java.util.*;

public class MazeGame {
  int xPos, yPos;
  int mazeX, mazeY;
  char[][] maze;

  public final static int MAX_MOVES = Integer.MAX_VALUE;

  public static void main (String[] argv){
    BufferedReader mazeFile=null;
    try {
      mazeFile = new BufferedReader(new FileReader(argv[0]));
    }
    catch (IOException e){
      System.err.println("unable to open "+argv[0]+":"+e);
      System.exit(1);
    }

    MazeGame server = null;
    try {
      server = new MazeGame(mazeFile);
    }
    catch (IOException e){
      System.err.println("i/o exception while loading file:"+e);
      System.exit(1);
    }

    try {
      server.play(new BufferedReader(new InputStreamReader(System.in)), 
		  System.out);
    }
    catch(IOException e){
      System.err.println("i/o exception while playing game:"+e);
      System.exit(1);
    }
          
  }

  public MazeGame(BufferedReader mazeFile)
    throws IOException {
    StringTokenizer tok = new StringTokenizer(mazeFile.readLine());
    mazeX = Integer.parseInt(tok.nextToken());
    mazeY = Integer.parseInt(tok.nextToken());
    xPos = Integer.parseInt(tok.nextToken());
    yPos = Integer.parseInt(tok.nextToken());

    maze = new char[mazeX][mazeY];

    String line;

    for(int row=0;row<mazeY;row++){
      line = mazeFile.readLine();
      for (int col = 0 ; col < mazeX; col++){
	maze[col][row] = line.charAt(col);
	//System.out.println("maze at "+col+" "+row+" is "+maze[col][row]);
      }

    }
  }

  public void play (BufferedReader in, PrintStream out)
    throws IOException{
    int moves = 0;
    while(inBounds(xPos,yPos) && moves < MAX_MOVES){
      printPosition(out);
      movePlayer(in,out);
      moves++;
    }
    if(moves >= MAX_MOVES){
      System.err.println("TOO MANY MOVES!\n");
      System.exit(1);
    }
    System.err.println("you got out!");
    System.exit(0);
  }

  void printPosition(PrintStream out){
    for(int yoff = -1;yoff < 2 ; yoff++){
      for (int xoff=-1;xoff < 2;xoff++){
	if(xoff == 0 && yoff == 0)
	  out.write('+');
	else{
	  int x, y;
	  x = xPos+xoff;
	  y = yPos+yoff;
	  if(inBounds(x,y))
	    out.write(maze[x][y]);
	  else
	    out.write('O');
	}
      }
      out.write('\n');
    }
  }

  void movePlayer(BufferedReader in, PrintStream out)
  throws IOException{
    String moveLine = in.readLine();
    char move = moveLine.charAt(0);
    int x,y;
    x=xPos;
    y=yPos;
    switch(move){
    case 'N':
      y--;
      break;
    case 'S':
      y++;
      break;
    case 'E':
      x++;
      break;
    case 'W':
      x--;
      break;
    default:
      System.err.println("invalid move request: "+move);
      System.exit(1);
      return;
    }

    if(!inBounds(x,y)){
      xPos=x;yPos=y;
      return;
    }

    if(maze[x][y]!=' '){
      System.err.println("invalid move.  cannot move into \""+maze[x][y]+
			 "\" at "+x+","+y);
      System.exit(1);
      return;
    }

    xPos=x;yPos=y;
    return;
  }

  boolean inBounds(int x, int y){
    return (x >= 0 && x < mazeX &&
	    y >= 0 && y < mazeY);
  }
}

