#include #define rep(i,n) for(int i=0;i<(n);++i) using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin>>t; while(t--){ int n,k; cin>>n>>k; vector> g(n); rep(i,n-1){ int x,y; cin>>x>>y; x--;y--; g[x].push_back(y); g[y].push_back(x); } vector a(n); rep(i,n)cin>>a[i]; vector h(n,0); auto dfs = [&](auto dfs, int v, int p) -> void { for(int e: g[v]){ if(e==p) continue; h[e] = h[v]+1; dfs(dfs, e, v); } }; dfs(dfs, 0,-1); int x=0; rep(i,n) if(h[i]%2) x ^= a[i]%(k+1); if(x==0) cout << "P" << "\n"; else cout << "K" << "\n"; } }