#include <iostream>
#include <vector>
#include <unordered_map>
#include <set>
using namespace std;
vector<vector<int>> g;
vector<int> A, sz;
vector<vector<int>> val;
void dfs(int u, int p) {
sz[u] = 1;
val[u].push_back(A[u]);
for (int v : g[u]) {
if (v != p) {
dfs(v, u);
sz[u] += sz[v];
val[u].insert(val[u].end(), val[v].begin(), val[v].end());
}
}
}
int solve(int x) {
int S = sz[x];
unordered_map<int, int> freq;
for (int v : val[x]) {
freq[v]++;
}
int miss = 0;
for (int i = 1; i <= S; ++i) {
if (freq[i] == 0) miss++;
}
return miss;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while (T--) {
int N;
cin >> N;
A.resize(N);
for (int i = 0; i < N; ++i) cin >> A[i];
g.clear();
g.resize(N);
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);
}
sz.clear();
sz.resize(N, 0);
val.clear();
val.resize(N);
dfs(0, -1);
int Q;
cin >> Q;
while (Q--) {
int x;
cin >> x;
x--;
cout << solve(x) << "\n";
}
}
return 0;
}