Arthur and his sister Caroll have been playing a game called Nim for some time now. Nim is played as follows:
Arthur and Caroll enjoyed this simple game until they discovered an easy way to always find the best move:
It is easy to convince yourself that this works, using these facts:
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.
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$.
For each position, output the following.
W if the position is a winning position, or L if it is a losing position.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.