ll@t; rep(t){ ll@n,@k; ll@p11,@p12,@p13; ll@p21,@p22,@p23; ll@p31,@p32,@p33; ll@a[n]; string@s; char d[606]; rep(j,606){ d[j]=j%6?'D':j>=k*6?'K':'P'; } rrep(i,n){ char e[606]; rep(j,606){ e[j]=d[j]; } int b=a[i]+1; if(s[i]=='K'){ rep(j,1,606){ if(e[j*b%606]=='K'){ d[j]='K'; } if(e[j*b%606]=='D'&&d[j]!='K'){ d[j]='D'; } } }else{ rep(j,1,606){ if(e[j*b%606]=='P'){ d[j]='P'; } if(e[j*b%606]=='D'&&d[j]!='P'){ d[j]='D'; } } } } ll h=abs(p11*(p22*p33-p23*p32)+p12*(p23*p31-p21*p33)+p13*(p21*p32-p22*p31)); wt(h==0?'D':d[h%606]); }