#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int N = 100000 + 5;
int tc, n, casee = 1, q, tm = 0, a[N], start[N], finish[N], cnt[N];
vector<int> adj[N];
void dfs(int u, int par) {
start[u] = ++tm;
for (int v : adj[u]) {
if (v == par)
continue;
dfs(v, u);
}
finish[u] = tm;
}
int main() {
cin >> tc;
while (tc--) {
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n - 1; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, 0);
while (q--) {
int node;
cin >> node;
cnt[start[node]]++;
cnt[finish[node] + 1]--;
}
for (int i = 1; i <= n; i++) {
cnt[i] += cnt[i - 1];
}
cout << "Case " << casee++ << ": ";
for (int i = 1; i <= n; i++) {
int val = a[i];
if (cnt[start[i]] % 2 == 0) {
cout << val << " ";
} else {
cout << !val << " ";
}
}
cout << endl;
for (int i = 1; i <= n; i++) {
adj[i].clear();
start[i] = finish[i] = cnt[i] = 0;
}
}
return 0;
}