#include using namespace std; char solve(int n, int k, vector >& edges, vector& a){ vector > graph(n, vector({})); for(auto&[x, y] : edges){ --x; --y; graph[x].push_back(y); graph[y].push_back(x); } vector depth_parity(n, -1); depth_parity[0] = 0; deque que = { 0 }; while(!que.empty()){ int v_now = que.front(); que.pop_front(); int p_next = depth_parity[v_now] ^ 1; for(int& v_next : graph[v_now]){ if(depth_parity[v_next] != -1){ continue; } depth_parity[v_next] = p_next; que.push_back(v_next); } } int grundy = 0; for(int i = 0; i < n; ++i){ if(depth_parity[i] == 0){ continue; } grundy ^= a[i] % (k + 1); } return (grundy != 0) ? 'K' : 'P'; } int main(){ int t; cin >> t; for(int i = 0; i < t; ++i){ int n, k; cin >> n >> k; vector > edges(n - 1, pair({})); for(auto&[x, y] : edges){ cin >> x >> y; } vector a(n); for(auto& x : a){ cin >> x; } cout << solve(n, k, edges, a) << endl; } return 0; }