#include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int N,K; cin >> N >> K; vector> Graph(N); for(int i=0; i> u >> v; u--; v--; Graph.at(u).push_back(v); Graph.at(v).push_back(u); } vector A(N); for(auto &a : A) cin >> a; int Xor = 0; K++; auto dfs = [&](auto dfs,int pos,int back,int d) -> void { Xor ^= d%2 * (A.at(pos)%K); for(auto to : Graph.at(pos)){ if(to == back) continue; dfs(dfs,to,pos,d+1); } }; dfs(dfs,0,-1,0); if(Xor) cout << "K" << endl; else cout << "P" << endl; } }