#include #define INF 1000000001LL #define LNF 1000000000000000001LL #define MOD 998244353LL #define MAX 200001 #define long long long #define all(x) x.begin(),x.end() using namespace std; void dfs(int x, int par,vector graph[], vector&depth) { for(int y : graph[x]) { if(y == par) continue; depth[y] = depth[x]+1; dfs(y,x,graph,depth); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while(t--) { int n,k; cin >> n >> k; vector graph[n+1]; for(int i = 0; i> a >> b; graph[a].push_back(b); graph[b].push_back(a); } vector depth(n+1); dfs(1,0,graph,depth); int grundy = 0; for(int i = 1; i<=n; i++) { int x; cin >> x; if(depth[i]&1) grundy^=x%(k+1); } if(grundy) cout << "K\n"; else cout << "P\n"; } return 0; }