#pragma GCC optimize("Ofast") #pragma GCC target("avx2") #define rd_init() char*rp=({char*mmap();mmap(0l,1l<<25,1,2,0,0ll);}) #define rd() ({int _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;}) #define rd_signed() ({int _s=*rp=='-'&&++rp,_v=rd();_s?-_v:_v;}) #define rep(v,e) for(typeof(e) v=0;v=a?v:a) char wbuf[1<<25]; int a[10000]; int main(){ char*wp=wbuf; rd_init(); int t=rd(); while(t--){ int n=rd(); int k=rd(); long h; { long p11=rd_signed(),p12=rd_signed(),p13=rd_signed(); long p21=rd_signed(),p22=rd_signed(),p23=rd_signed(); long p31=rd_signed(),p32=rd_signed(),p33=rd_signed(); h=p11*(p22*p33-p23*p32)+p12*(p23*p31-p21*p33)+p13*(p21*p32-p22*p31); if(h<0) h=-h; } rep(i,n){ a[i]=rd(); } char*s=rp+n; rp=s+1; if(h){ h%=606; int z; if(n==1){ int b=h*(a[0]+1)%606; z= s[-1]=='K'? h%6==0&&h>=k*6?1: b%6==0&&b>=k*6?1: h%6?0:-1 : h%6==0&&h=k?1:-1; d[j*6+1]=0; d[j*6+2]=0; d[j*6+3]=0; d[j*6+4]=0; d[j*6+5]=0; } rrep(i,n){ char e[606]; rep(j,606){ e[j]=d[j]; } int b=a[i]+1; if(*--s=='K'){ int c=b; reps(j,1,606){ chmax(d[j],e[c]); c+=b; c-=c<606?0:606; } }else{ int c=b; reps(j,1,606){ chmin(d[j],e[c]); c+=b; c-=c<606?0:606; } } } z=d[h]; } *wp++=z<0?'P':z==0?'D':'K'; }else{ *wp++='D'; } *wp++='\n'; } write(1,wbuf,wp-wbuf); _exit(0); }