Othello

Given the sequence of moves of a valid 6x6 Othello game, replays them and prints the final board plus the winner.

Medium4SimulationImplementationMatrixBrute forceInterviewNo attempts yetTime limit1sMemory limit128 MB

Problem

Othello is a board game where you lay out small black or white discs on a 6×66 \times 6 board. Japan calls it オセロ, and Korea calls it 오델로. The name comes from the play Othello, and the motif is said to be Othello's duality, or the black and white contrast between Othello and Desdemona. Regular tournaments are still held every year in several countries, and Japan is the most active. The main events are the World Othello Championship, the Japan Meijin, the All Japan Championship, the Ouza tournament, and the European Grand Prix. (Source: Namuwiki)

That is part of a report Namgyu handed in for a liberal arts class. The professor who received it got angry and challenged Namgyu to a game of Othello. Namgyu still did not know what Othello was, so he looked the rules up online.

  • The game starts with 4 stones at the center of the board, placed in a square with alternating colors.

  • A stone must be placed where it surrounds the opponent's stones from both sides and flips them.

  • When there is no stone to flip, the turn passes to the opponent automatically.

  • The game ends when neither side can place a stone any more, for one of the reasons below.

    • All 36 stones fill the board (the most common case)
    • One side has flipped every stone of the other color
    • Both sides have to pass on the same turn
  • The player with more stones when the game ends is the winner. If both have the same number of stones, the game is a draw.

(Source: Wikipedia)

A picture explains it as follows.

The game starts from the board above, and black takes the first turn. The blue squares are where black can place a stone, that is, squares that put at least one white stone between two black stones. The red squares are examples of where black cannot place a stone.

If black plays one of the two blue squares in the upper left, the white stone in the third row from the top and the third column from the left is surrounded by black stones and turns black. If black plays one of the two squares in the lower right, the white stone in the third row from the bottom and the third column from the right turns black.

Surrounding the opponent's stones works in all 8 directions, horizontal, vertical and diagonal, and a move does not have to wrap exactly one stone. Here is an example.

If black plays the blue square, every white stone marked O is blocked at both ends by a black stone, so all of them turn black. The two white stones marked X are not blocked directly at both ends, so they do not change.

Play continues this way, black first, one move at a time in alternating turns. The remaining details follow the rules listed above.

Namgyu studied all the rules and played the professor, and he did follow the rules. He lost every game, so he is about to get an F, and the professor announced that he would give Namgyu one more chance in a few days.

Namgyu wants to replay today's record and find out what went wrong. He only remembers where the stones were placed, not what the board looked like. Given every position where a stone was placed during the game, find the final state of the board and the winner.

Input

The first line has the number of game log entries NN. (1N321 \le N \le 32)

Each of the next NN lines has a position RR CC where a stone was placed. It means a stone was placed on row RR, column CC. Rows are numbered 1, 2, 3, ... from the top, and columns are numbered 1, 2, 3, ... from the left. A game in which one of the two players cannot place a stone and has to pass the turn is never given as input.

The game log given as input is always a valid game log.

The board always starts with two white stones at (3, 3) and (4, 4) and two black stones at (3, 4) and (4, 3), and black takes the first turn.

Output

Lines 1 to 6: print the final state of the board as a 6×66 \times 6 grid, 6 characters per line. Print an empty square as '.' (ASCII 46), a black stone as 'B' (ASCII 66), and a white stone as 'W' (ASCII 87).

Line 7: print Black if the player with the black stones won, and White otherwise. Only inputs without a draw are given.

Hint

Real Othello is played on an 8×88 \times 8 board, but this problem uses a 6×66 \times 6 board to keep the explanation simple.