import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); PrintWriter pw = new PrintWriter(System.out); for (int z = 0; z < t; z++) { String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int k = Integer.parseInt(sa[1]); List> list = new ArrayList<>(n); for (int i = 0; i < n; i++) { list.add(new ArrayList<>()); } for (int i = 0; i < n - 1; i++) { sa = br.readLine().split(" "); int a = Integer.parseInt(sa[0]) - 1; int b = Integer.parseInt(sa[1]) - 1; list.get(a).add(b); list.get(b).add(a); } sa = br.readLine().split(" "); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); } Queue que = new ArrayDeque<>(); que.add(0); int[] d = new int[n]; Arrays.fill(d, -1); d[0] = 0; while (!que.isEmpty()) { int cur = que.poll(); for (int next : list.get(cur)) { if (d[next] == -1) { que.add(next); d[next] = d[cur] + 1; } } } int k1 = k + 1; int g = 0; for (int i = 0; i < n; i++) { if (d[i] % 2 == 1) { g ^= a[i] % k1; } } if (g == 0) { pw.println("P"); } else { pw.println("K"); } } pw.flush(); br.close(); } }