Reversi
Time limit1sMemory limit512 MB
For each N by M board, decide whether the second player with 1x1 stones wins, loses, or draws against a first player placing 2x1 dominoes under optimal play.
- Level
Hard8 of 10
- Topics
- Game theory, Combinatorics, Brute force
- Solved
- No attempts yet
Problem
Dongho lost his house and everything he owned after underestimating the number of rivers and scallops, and now he is deep in debt! To repay the debt, Dongho plans to enter Shii, a strong player, in the "World Reversi Tournament" and win part of her prize money.
Reversi is a game also called Othello. Black and white take turns placing stones, and when the game ends, the side with more stones wins. This problem has little to do with the standard rules, so the full explanation is omitted here.
The Reversi played in this tournament differs from the usual game. Stones cannot be flipped!
Flipping stones is the core of the game, so a game without flips would be very dull. The tournament uses the following rules instead.
- The board is a grid with rows and columns.
- The first player uses stones, and the second player uses stones. A stone can be placed as is or rotated by 90 degrees.
- The first player and the second player alternate placing one of their own stones on the board. A cell can hold at most one stone.
- If one player can no longer place a stone, the other player fills as many of the remaining empty cells with their own stones as possible, and then the game ends.
- After the game ends, the player whose stones cover more of the board wins. If the covered areas are equal, the game is a draw.
Every competitor in the tournament, Shii included, is extremely skilled, so each one always plays the best move to win. Shii always takes the second player's role, since Shii never wins a coin toss.
Will Shii do well enough in the tournament for Dongho to repay all of his debt?
Input
The first line contains the number of test cases . Each of the next lines contains two integers and , separated by a space.
Output
For each test case, print W if Shii wins, L if Shii loses, and D if the game is a draw. Print the results without spaces or newlines between them.