import sys input = sys.stdin.readline MOD = 101 INV2, INV3 = pow(2, MOD - 2, MOD), pow(3, MOD - 2, MOD) def det(A): ret = 0 for i in range(3): ret += A[i][0] * A[(i + 1) % 3][1] * A[(i + 2) % 3][2] ret -= A[i][2] * A[(i + 1) % 3][1] * A[(i + 2) % 3][0] return ret def solve(N, K, P, a, s): d = abs(det(P)) if(d == 0): return 'D' dp = [[[-1] * 4 for _ in [0] * MOD] for _ in [0] * (N + 1)] for j in range(MOD): dp[N][j][3] = int(j >= K) for i in range(N - 1, -1, -1): hands = [1, -1, 0] if(s[i] == 'K') else [0, -1, 1] val = a[i] + 1 val_div2, val_div3 = (val % 2 == 0), (val % 3 == 0) for j in range(MOD): for k in range(4): results = [dp[i + 1][j][k], dp[i + 1][j * val % MOD][k | val_div2 | (val_div3 << 1)]] for x in hands: if(x not in results): continue dp[i][j][k] = x break div2, div3 = (d % 2 == 0), (d % 3 == 0) stat_init = dp[0][d % MOD * INV2 * INV3 % MOD][div2 | (div3 << 1)] if(stat_init == -1): return 'D' return 'K' if(stat_init) else 'P' t = int(input()) for _ in [0] * t: N, K = map(int, input().split()) P = [list(map(int, input().split())) for _ in [0] * 3] a = list(map(int, input().split())) s = input()[:-1] print(solve(N, K, P, a, s))