S-Nim

No attempts yetTime limit1sMemory limit128 MB

Problem

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 who cannot make a move loses.

Arthur and Caroll enjoyed this simple game until they discovered an easy way to always find the best move:

  • XOR the number of beads in every heap of the current position. (For example, with heaps $2, 4, 7$ the XOR-sum is $2 \oplus 4 \oplus 7 = 1$.)
  • If the XOR-sum is $0$, too bad, you will lose.
  • Otherwise, move so that the XOR-sum becomes $0$. This is always possible.

It is easy to convince yourself that this works, using these facts:

  • The player who takes the last bead wins.
  • After the winning player's last move the XOR-sum is $0$.
  • The XOR-sum changes after every move.

So if you make sure the XOR-sum is always $0$ after your move, your opponent can never win, and therefore you win.

Once both players know how to play perfectly, the game is no longer fun. Fortunately, Arthur and Caroll soon invented a similar game, S-Nim, that seemed to fix this. Each player may now only remove a number of beads that belongs to some predefined set $S$; for example, if $S = {2, 5}$ then each player may only remove $2$ or $5$ beads at a time. Now it is not always possible to make the XOR-sum $0$, so the strategy above is useless. Or is it?

Your job is to write a program that decides whether a given S-Nim position is a losing or a winning position. A position is a winning position if there is at least one move to a losing position. A position is a losing position if there is no move to a losing position. In particular, a position with no legal moves is a losing position.

Input

The input consists of a number of test cases.

Each test case is given as follows. The first line contains an integer $k$ ($0 < k \le 100$), the size of $S$, followed by $k$ integers $s_i$ ($0 < s_i \le 10000$) that make up $S$. The second line contains an integer $m$ ($0 < m \le 100$), the number of positions to evaluate. Each of the next $m$ lines contains an integer $l$ ($0 < l \le 100$), the number of heaps, followed by $l$ integers $h_i$ ($0 \le h_i \le 10000$), the number of beads in each heap.

The last test case is followed by a line containing a single $0$.

Output

For each position, output the following.

  • Print W if the position is a winning position, or L if it is a losing position.
  • After all positions of a test case have been processed, print a newline.

In other words, the results for the positions of one test case are concatenated on a single line, and a line break is printed at the end of each test case.