#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int N = 100000 + 5;
int tc, n, casee = 1, q, tm = 0, idx = 1, a[N], revIdx[N], start[N], finish[N], cnt[N], val[N];
vector<int> adj[N];
void dfs(int u, int par) {
start[u] = ++tm;
revIdx[++idx] = u;
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);
}
tm = idx = 0;
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 originalValue = a[i];
int cntSum = cnt[revIdx[i]];
if (cntSum % 2 == 0) {
cout << originalValue << " ";
} else {
cout << !originalValue << " ";
}
}
cout << endl;
for (int i = 1; i <= n; i++) {
adj[i].clear();
start[i] = finish[i] = cnt[i] = 0;
}
}
return 0;
}