#include #include using namespace std; int main() { cin.tie(nullptr)->sync_with_stdio(false); int T; cin >> T; while (T--) { int N, K; cin >> N >> K; vector> to(N); for (int e = 0; e < N - 1; ++e) { int a, b; cin >> a >> b; --a, --b; to.at(a).push_back(b); to.at(b).push_back(a); } vector A(N); for (auto &a : A) cin >> a; int gru = 0; auto rec = [&](auto &&rec, int v, int p, int depth) -> void { if (depth % 2) gru ^= A.at(v) % (K + 1); for (auto u : to.at(v)) { if (u != p) rec(rec, u, v, depth + 1); } }; rec(rec, 0, -1, 0); cout << (gru ? 'K' : 'P') << '\n'; } }