import java.util.*;
import java.io.*;
 
public class field {
    
    public static void main(String[] args) throws FileNotFoundException {
        
        //Declares variables to hold the player's coordinates and the board
        int width = 0;
        int height = 0;
        int player_x = 0;
        int player_y = 0;
        int num_obstructions = 0;
        int[][] board;
        
        //Creates object for input
        Scanner input = new Scanner(new File("field.in"));
        
        int numcases = input.nextInt();
        
        for (int mycase=1; mycase<=numcases; mycase++) {
        	
        	System.out.println("Test case "+mycase+":\n");
        
        
	        //Sets the variables declared above
	        width = input.nextInt();
	        height = input.nextInt();
	        player_x = input.nextInt();
	        player_y = input.nextInt();
	        board = new int[width][height];
	        num_obstructions = input.nextInt();
        
	        //For every obstruction, place a -1 in the board array
	        for (int i = 0; i < num_obstructions; i++)
	        {
	            int obs_x = input.nextInt();
	            int obs_y = input.nextInt();
	            
	            board[obs_x][obs_y] = -1;
	        }
	        
	        //Gets the number of moves, creates an array to hold them, and populates the array
	        int num_moves = input.nextInt();
	        String[] moves = new String[num_moves];
	        for (int i = 0; i < num_moves; i++)
	        {
	            moves[i] = input.next().toLowerCase();
	        }
	
	    	//Prints out the first playing field
	    	System.out.println("Here is the playing field:");
	    	//For every board space
	        for (int y = 0; y < height; y++)
	        {
	            for (int x = 0; x < width; x++)
	            {
	            	//Prints X if there's an obstruction (if the field value was set to 0)
	                if (board[x][y] == -1)
	                {
	                    System.out.print("X");
	                }
	                //Prints P where the player is currently
	                else if (x == player_x && y == player_y)
	                {
	                    System.out.print("P");
	                }
	                //Otherwise the space is open
	                else
	                {
	                   System.out.print("O");
	              }
	                System.out.print(" ");
	            }
	            System.out.println("");
	        }
	        
	        //For every set of moves
	        for (int i = 0; i < num_moves; i++)
	        {
	            String decision = moves[i];
	            
	            //Moves north if north is valid           
	            if (decision.compareTo("north") == 0)
	            {
	                //Checks to see if north is valid
	                if (player_y == 0 || board[player_x][player_y-1] == -1)
	                {
	                	//North isn't valid
	                	System.out.println("");
	                    System.out.println("You can't go north! Try again.");
	                }
	                else
	                {
	                	//North is valid
	                	System.out.println("");
	                    System.out.println("You move north.");
	                    player_y--;
	                }
	            }
	            //Moves east if east is valid
	            else if (decision.compareTo("east") == 0)
	            {
	                // Checks to see if east is valid
	                if (player_x == width-1 || board[player_x+1][player_y] == -1)
	                {
	                	//East isn't valid
	                	System.out.println("");
	                    System.out.println("You can't go east! Try again.");
	                }
	                else
	                {
	                	//East is valid
	                	System.out.println("");
	                    System.out.println("You move east.");
	                    player_x++;
	                }
	            }
	            //Moves west if west is valid
	            else if ( decision.compareTo("west") == 0)
	            {
	            	//Checks to see if west is valid
	                if (player_x == 0 || board[player_x-1][player_y] == -1)
	                {
	                	//West isn't valid
	                	System.out.println("");
	                    System.out.println("You can't go west! Try again.");
	                }
	                else
	                {
	                	//West is valid
	                	System.out.println("");
	                    System.out.println("You move west.");
	                    player_x--;
	                }
	            }
	            //Moves south if south is valid
	            else if ( decision.compareTo("south") == 0)
	            {
	            	//Checks to see if south is valid
	                if (player_y == height-1 || board[player_x][player_y+1] == -1)
	                {
	                	//South isn't valid
	                	System.out.println("");
	                    System.out.println("You can't go south! Try again.");
	                }
	                else
	                {
	                	//South is valid
	                	System.out.println("");
	                    System.out.println("You move south.");
	                    player_y++;
	                }
	            }
	            
	            //Prints out like the first playing field
	        	System.out.println ("Here is the playing field: ");
	            for (int y = 0; y < height; y++)
	            {
	                for (int x = 0; x < width; x++)
	                {
	                    if (board[x][y] == -1)
	                    {
	                        // obstruction!
	                        System.out.print("X");
	                    }
	                    else if (x == player_x && y == player_y)
	                    {
	                        // player is here!
	                        System.out.print("P");
	                    }
	                    else
	                    {
	                        // empty, movable location
	                        System.out.print("O");
	                    }
	                    System.out.print(" ");
	                }
	                System.out.println("");
	            }
	            
	            
	            // System.out.println("");
	        }
	        
	        // Skip two lines in between different test cases.
	        System.out.println("\n");
	        
	        
	    } // end mycases loop
    }
}
