#include #include using namespace std; using namespace atcoder; typedef int64_t ll; using mint=modint998244353; typedef long double ld; const ll MOD=1000000007; const ll MODA=998244353; ll vx[4]={0,1,0,-1}; ll vy[4]={1,0,-1,0}; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) long long gcd(long long a,long long b){ a=abs(a); b=abs(b); ll gcdmax=max(a,b); ll gcdmin=min(a,b); if(gcdmin==0)return gcdmax; while(true){ if(gcdmax%gcdmin==0)break; else gcdmax%=gcdmin; swap(gcdmin,gcdmax); } return gcdmin; } ll pow(ll N,ll P,ll M){ if(P==0)return 1; else if(P%2==0){ ll t=pow(N,P/2,M); return t*t%M; } else return N*pow(N,P-1,M)%M; } ll pow(ll N,ll P){ if(P==0)return 1; else if(P%2==0){ ll t=pow(N,P/2); return t*t; } else return N*pow(N,P-1); } vector fac; vector finv; vector inv; void COMinit(ll N,ll P){ rep(i,N+1){ if(i==0){ fac.push_back(1); finv.push_back(1); inv.push_back(1); } else if(i==1){ fac.push_back(1); finv.push_back(1); inv.push_back(1); } else{ fac.push_back(fac.at(i-1)*i%P); inv.push_back(P-inv.at(P%i)*(P/i)%P); finv.push_back(finv.at(i-1)*inv.at(i)%P); } } } ll COM(ll n,ll k,ll P){ if(n par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化 for(ll i = 0; i < N; i++) par[i] = i; } ll root(ll x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(ll x, ll y) { // xとyの木を併合 ll rx = root(x); //xの根をrx ll ry = root(y); //yの根をry if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す ll rx = root(x); ll ry = root(y); return rx == ry; } }; int main(){ ll T; cin>>T; rep(t,T){ ll N,K; cin>>N>>K; vector> P(3,vector(3)); rep(i,3)rep(j,3)cin>>P[i][j]; ll det=P[0][0]*(P[1][1]*P[2][2]-P[1][2]*P[2][1])+P[0][1]*(P[1][2]*P[2][0]-P[1][0]*P[2][2])+P[0][2]*(P[1][0]*P[2][1]-P[1][1]*P[2][0]); vector A(N); det=abs(det); rep(i,N)cin>>A[i]; string S; cin>>S; if(det==0){ cout<<"D"<> dp(N+1,vector(606)); rep(i,606){ if(i%6!=0)dp[N][i]=0; else if(i/6>=K)dp[N][i]=1; else dp[N][i]=-1; } rep(i,N){ ll a=1+A[N-1-i]; if(S[N-1-i]=='K'){ rep(j,606){ dp[N-1-i][j]=max(dp[N-i][j],dp[N-i][(j*a)%606]); } } else{ rep(j,606){ dp[N-1-i][j]=min(dp[N-i][j],dp[N-i][(j*a)%606]); } } } if(dp[0][det%606]==1)cout<<"K"<