T = int(input()) for _ in range(T): N,K = map(int,input().split()) G = [[] for i in range(N)] for i in range(N-1): u,v = map(int,input().split()) u -= 1 v -= 1 G[u].append(v) G[v].append(u) A = list(map(int,input().split())) parent = [-1 for i in range(N)] todo = [0] dist = [-1 for i in range(N)] dist[0] = 0 visit = [] while len(todo): s = todo.pop() visit.append(s) for t in G[s]: if dist[t] == -1: parent[t] = s dist[t] = dist[s] + 1 todo.append(t) while len(visit): s = visit.pop() if s == 0: break if dist[s] % 2 == 0: continue A[parent[s]] += A[s] g = 0 for s in G[0]: g ^= A[s] % (K + 1) if g: print('K') else: print('P')