1 /*
2 POJ2960 S-Nim
3 http://poj.org/problem?id=2960
4 博弈论 SG函数
5 *
6 */
7
8 #include <cstdio>
9 #include <algorithm>
10 #include <cstring>
11 using namespace std;
12 const int Nmax=10005;
13 //s[]:可以取走的石子个数
14 //sg[]:0~n的SG函数值
15 //hhash[]:mex{}
16 //#define test
17 int s[105],sg[Nmax],hhash[Nmax];
18 void getSG(int n)//n为s[]的长度,即可取的种数
19 {
20 int i,j;
21 sg[0]=0;
22 //memset(sg,0,sizeof(sg));
23 for(i=1;i<Nmax;i++)//Nmax为求解范围
24 {
25 memset(hhash,0,sizeof(hhash));
26 for(j=1;j<=n;j++)
27 if(i>=s[j])
28 hhash[sg[i-s[j]]]=1;
29 for(j=0;j<Nmax;j++) //求mes{}中未出现的最小的非负整数
30 {
31 if(hhash[j]==0)
32 {
33 sg[i]=j;
34 break;
35 }
36 }
37 }
38 }
39
40 int main()
41 {
42 int n;
43 #ifdef test
44 freopen("2960.in","r",stdin);
45 #endif
46 while(scanf("%d",&n) && n)
47 {
48 //memset(s,0,sizeof(s));
49 for(int i=1;i<=n;i++)
50 scanf("%d",&s[i]);
51 getSG(n);
52 int t,a;
53 scanf("%d",&t);
54 while(t--)
55 {
56 int ans=0;
57 int k;
58 scanf("%d",&k);
59 while(k--)
60 {
61 scanf("%d",&a);
62 ans^=sg[a];
63 }
64 if(!ans)
65 printf("L");
66 else
67 printf("W");
68 }
69 printf("\n");
70 }
71 return 0;
72 }