A game of chess
Chess is a board game that blends elements of art, science, and sport, and is considered one of the oldest games in the world. It is played on a board divided into equal square cells, with a standard size of 8×8 cells. The cells are traditionally labeled horizontally with Latin letters from a to h, and vertically with numbers from 1 to 8, giving each cell a unique designation, such as c4. The board's cells are colored alternately in black and white, with the cell a8 being white.
The game involves two players, each with a set of pieces: one king, one queen, two bishops, two knights, two rooks, and eight pawns. One player uses white pieces, while the other uses black. At the start of the game, the pieces are arranged in fixed positions, occupying the first two rows (1 and 2) for white, and the last two rows (7 and 8) for black. The initial arrangement of pieces on rows 1 and 8 from a to h is: rook, knight, bishop, queen, king, bishop, knight, rook. Rows 2 and 7 are filled with pawns.
Players alternate turns, starting with white, each moving one piece according to its movement rules. Chess games are often recorded to allow for later review or analysis. Your task is to reconstruct the board's final position given a record of all the moves made during the game.
In this task, understanding the specific movement rules of each piece is not necessary, but you should be aware of two special situations.
The first situation is castling, a move involving both the king and one of the rooks of the same color along the back rank. During castling, the king moves two squares towards the rook, and the rook jumps over the king to the square the king just crossed. There are two types of castling: short and long.
The second situation occurs when a pawn reaches the opposite back rank. For a white pawn, this is the eighth rank, and for a black pawn, it is the first. Upon reaching this rank, the pawn can be promoted to any piece of the same color, except for a pawn or a king.
Input
The first line of the input file contains a natural number n (n ≥ 1), representing the number of moves in the game record. The following n lines are formatted as Fx_1y_1-x_2y_2.
In this format, F indicates the piece making the move (K for king, Q for queen, R for rook, B for bishop, N for knight, P for pawn). White pieces are denoted by uppercase letters, and black pieces by lowercase. For instance, K represents the white king, and r represents the black rook. The pairs x_1y_1 and x_2y_2 are the coordinates of the piece before and after the move, respectively, with x_1 and x_2 as column letters, and y_1 and y_2 as row numbers.
Short castling is denoted by 0-0, and long castling by 0-0-0, where 0 is zero. The notation does not distinguish between black and white castling. If a pawn reaches the opposite back rank and is promoted, a symbol F' is appended to the move record, indicating the piece the pawn is promoted to.
Examples: Pe2-e4 indicates a white pawn moving from e2 to e4, while pe2-e1q indicates a black pawn moving from e2 to e1 and being promoted to a queen.
Assume all moves follow the rules of chess, and the input will never include a situation where a pawn is captured en passant.
Output
Output eight lines with eight symbols each, representing the ranks of the chessboard from the eighth to the first. The columns represent the files of the chessboard from a to h. Use the same format as the input file for the pieces. For empty squares, output the symbol "." (dot).