#P2033. Dancing on the Chessboard

    ID: 15315 Type: Default 1000ms 256MiB

Dancing on the Chessboard

Dancing on the Chessboard

A dance can be quite fun on a chessboard. You are given an international chessboard with some pieces placed on it and the dancer's initial position and direction. The dancer can perform four types of operations, and you are required to determine the final board state after executing all operations.

Operations:
move n: Move forward n steps in the current direction. If the next step would take the dancer off the board, the move command stops immediately. If there is a piece in the next cell, push it forward by one cell. If a series of pieces are in line, push the entire chain by one cell (if a piece is pushed off the board, it is removed).
turn left: Turn 90° left.
turn right: Turn 90° right.
turn back: Turn 180° around.

inputFormat

The input consists of the following lines:

  1. Eight lines, each with 8 characters. Each character is either . (an empty cell) or * (a chess piece).
  2. A line with two space-separated integers r and c (1-indexed) representing the dancer's initial row and column.
  3. A line containing a single character from {N, E, S, W} that represents the initial direction (North, East, South, West).
  4. A line with an integer k representing the number of operations.
  5. k lines, each being one of the following commands: move n, turn left, turn right, or turn back.

    Note: The chessboard rows are given from top to bottom.

outputFormat

Output the final state of the chessboard as 8 lines of 8 characters each. Pieces that have been pushed off the board are removed. The dancer is not represented in the final board state.

sample

........
...*....
........
........
........
........
........
........
2 4
N
3
move 2
turn right
move 3
........

...*.... ........ ........ ........ ........ ........ ........

</p>