#include <bits/stdc++.h>
using namespace std;
// #include "debug.h"
const int N = 1e5 + 10;
int n;
int a[N];
int q;
vector<int> g[N];
vector<int> sub[N];
int sz[N];
int ans[N];
void merge(int u, int v) {
if (sub[v].size() > sub[u].size()) {
sub[v].swap(sub[u]);
}
for (int i : sub[v]) {
sub[u].push_back(i);
}
}
void dfs(int u, int v) {
sub[u].push_back(a[u]);
for (int c : g[u]) {
if (c == v) {
continue;
}
dfs(c, u);
sz[u] += sz[c];
merge(u, c);
}
vector<int> cnt(sz[u] + 1);
for (int i : sub[u]) {
if (i <= sz[u]) {
cnt[i] = 1;
}
}
for (int i = 1; i <= sz[u]; ++i) {
ans[u] += (cnt[i] == 0);
}
}
void solve() {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
g[i].clear();
sub[i].clear();
sz[i] = 1;
ans[i] = 0;
}
for (int i = 0; i < n - 1; ++i) {
int u, v;
cin >> u >> v;
--u, --v;
g[u].push_back(v), g[v].push_back(u);
}
dfs(0, -1);
int q;
cin >> q;
for (int i = 0; i < q; ++i) {
int x;
cin >> x;
cout << ans[x - 1] << '\n';
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int tc = 1;
cin >> tc;
while (tc--) {
solve();
}
}