#Q249. 「一本通 6.7 练习 4」S-Nim

「一本通 6.7 练习 4」S-Nim

Description

Original problem from: HDU 1536

Two players are playing a game with the following rules: There are nn piles of stones, with a1,a2,,ana_1, a_2, \cdots, a_n stones respectively. In each turn, a player must take some stones from one pile, but the number of stones taken must be one of the predefined values in the set {s1,s2,,sk}\{s_1, s_2, \cdots, s_k\}. The player who cannot make a move loses.

Input Format

Multiple test cases.

For each test case, the first line contains an integer kk, followed by kk integers representing s1,s2,,sks_1, s_2, \cdots, s_k;
The second line contains an integer mm, indicating that mm game states will be provided;
The next mm lines each start with an integer nn, followed by nn integers representing a1,a2,,ana_1, a_2, \cdots, a_n.

If k=0k=0, it signifies the end of input.

Output Format

For each test case, output a string of mm characters, where each character indicates whether the corresponding game state is a winning position (W) or a losing position (L).

Sample 1

2 2 5
3
2 5 12
3 2 4 7
4 2 3 7 12
5 1 2 3 4 5
3
2 5 12
3 2 4 7
4 2 3 7 12
0

LWW
WWL

Data Range and Hint

For all data, 0<n,m,k1000 < n, m, k \le 100, and 0<si,ai1040 < s_i, a_i \le 10^4.