#include using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; template using V = vector; template using VV = V>; template using VVV = V>; template using VVVV = VV>; #define rep(i,n) for(ll i=0ll;i void chmin(T& t, const U& u) { if (t > u) t = u; } template void chmax(T& t, const U& u) { if (t < u) t = u; } // cin.tie(nullptr); // ios::sync_with_stdio(false); // cout << fixed << setprecision(20); void solve(){ ll n, k; cin >> n >> k; VV v(3, V(3)); rep(i,3) rep(j,3) cin >> v[i][j]; V a(n); rep(i,n) cin >> a[i]; string s; cin >> s; V dp(606, 0); rep(i, 606){ if(i%6) dp[i] = 0; else{ ll j = i/6; if(j>=k) dp[i] = 1; else dp[i] = -1; } } reverse(be(s)); reverse(be(a)); rep(i, n){ V ndp = dp; rep(j, 606){ if(s[i] == 'K') chmax(ndp[j], dp[(j*(1+a[i]))%606]); else chmin(ndp[j], dp[(j*(1+a[i]))%606]); } swap(ndp, dp); } ll p = v[0][0]*(v[1][1]*v[2][2] - v[1][2]*v[2][1]) + v[0][1] * (v[1][2]*v[2][0] - v[1][0]*v[2][2]) + v[0][2]*(v[1][0]*v[2][1]-v[1][1]*v[2][0]); p = abs(p); if(p== 0) cout << "D" << endl; else{ p %= 606; // cout << p << endl; if(dp[p]==0) cout << "D" << endl; else{ if(dp[p] == 1) cout << "K" << endl; else cout << "P" << endl; } } } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int t=1; cin >> t; rep(i,t) solve(); }