S-Nim#1015

S-Nim

2 seconds
64 megabytes
Very easy

Arthur and his sister Caroll have been playing a game called Nim for some time now. Nim is played as follows:

- The starting position has a number of heaps, all containing some, not necessarily equal, number of beads. - The players take turns choosing a heap and removing a positive number of beads from it. - The first player unable to make a move loses.

Arthur and Caroll really enjoyed playing this simple game, until they recently learned an easy way to always find the best move:

- Xor the number of beads in the heaps in the current position (for example, if the heaps have , , and beads, the xor-sum is 2 \mathbin{\mathrm{xor}} 4 \mathbin{\mathrm{xor}} 7 = 1). - If the xor-sum is , then you will lose. - Otherwise, make a move so that the xor-sum becomes . This is always possible.

It is quite easy to convince yourself that this works. Consider these facts:

- The player who takes the last bead wins. - After the winning player's last move, the xor-sum is . - The xor-sum changes with every move.

So, if you ensure the xor-sum is after your move, your opponent will never be able to win, and thus, you will win. Understandably, the game is no fun when both players know how to play perfectly. Fortunately, Arthur and Caroll soon came up with a similar game, S-Nim. In this game, each player is only allowed to remove a number of beads that is present in the set . For example, if S = \{2, 5\}, each player is only allowed to remove either or beads from any heap. Now it is not always possible to make the xor-sum with your move, so the previous strategy does not always work.

Your job is to determine whether a given position in S-Nim is a winning or losing position. A position is called winning if there is at least one move to a losing position. A position is losing if there are no moves to a losing position. If no moves are possible from a position, it is considered losing.

Input

Input consists of a number of test cases. For each test case, the first line contains a number (0 < k \leq 100) and then numbers s_i (0 < s_i \leq 10000) describing the set . The second line contains a number (0 < m \leq 100), which is the number of positions to evaluate. Each of the next lines contains a number (0 < l \leq 100) describing the number of heaps, followed by numbers h_i (0 < h_i \leq 10000) describing the number of beads in the heaps. The last test case is followed by a on a line by itself.

Output

For each position, print W if the position is winning, or L if it is losing. Print a new line after the data for each test case.

Examples

Example 1

Loading
Loading