Q=int(input()) for _ in range(Q): N,K=map(int,input().split()) G=[[] for i in range(N)] for i in range(N-1): a,b=map(int,input().split()) G[a-1].append(b-1) G[b-1].append(a-1) dist=[-1]*N dist[0]=0 from collections import deque S=deque() S.append(0) while S: x=S.pop() for y in G[x]: if dist[y]>=0: continue dist[y]=dist[x]+1 S.append(y) ans=0 A=list(map(int,input().split())) for i in range(1,N): if dist[i]%2==1: ans^=A[i]%(K+1) if ans!=0: print('K') else: print('P')