#include using namespace std; using ll=long long; using pll=pair; using tll=tuple; using ld=long double; const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define all(v) v.begin(),v.end() template inline bool chmin(T &a,T b){ if(a>b){ a=b; return true; } return false; } template inline bool chmax(T &a,T b){ if(a a; vector> g; void dfs(ll x,ll p){ if(d%2==1) ans^=a[x]%(k+1); for(auto i:g[x]){ if(i==p) continue; d++; dfs(i,x); d--; } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll t; cin >> t; while(t--){ cin >> n >> k; g.assign(n,{}); rep(i,n-1){ ll x,y; cin >> x >> y; x--; y--; g[x].push_back(y); g[y].push_back(x); } a.assign(n,0); rep(i,n) cin >> a[i]; d=0; ans=0; dfs(0,-1); if(ans==0) cout << "P\n"; else cout << "K\n"; } }