#include using namespace std; using ll=long long; #define rep(i,n) for(int i=0;i=0;i--) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} void solve(){ int N; ll K; cin>>N>>K; vector>G(N); for(int i=0;i>u>>v; u--; v--; G[u].push_back(v); G[v].push_back(u); } vectorA(N); for(int i=0;i>A[i]; vectord(N); auto dfs=[&](auto dfs,int x,int p)-> void { for(auto i:G[x]){ if(i==p)continue; d[i]=d[x]+1; dfs(dfs,i,x); } }; dfs(dfs,0,-1); ll xr=0; auto dfs2=[&](auto dfs2,int x,int p)-> void { if(d[x]%2==1){ xr^=A[x]%(K+1); } for(auto i:G[x]){ if(i==p)continue; dfs2(dfs2,i,x); } }; dfs2(dfs2,0,-1); if(xr==0)cout<<"P\n"; else cout<<"K\n"; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int T; cin>>T; while(T--){ solve(); } }