#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
vector<vector<int>> g;
vector<int> A, sz, in, out;
vector<int> euler_tour;
int timer = 0;
void dfs(int u, int p) {
in[u] = timer++;
euler_tour.push_back(A[u]);
sz[u] = 1;
for (int v : g[u]) {
if (v != p) {
dfs(v, u);
sz[u] += sz[v];
}
}
out[u] = timer - 1;
}
int solve(int x) {
int S = sz[x];
unordered_map<int, int> freq;
for (int i = in[x]; i <= out[x]; ++i) {
freq[euler_tour[i]]++;
}
int missing = 0;
for (int i = 1; i <= S; ++i) {
if (freq[i] == 0) missing++;
}
return missing;
}
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);
in.clear();
out.clear();
in.resize(N, -1);
out.resize(N, -1);
euler_tour.clear();
timer = 0;
dfs(0, -1);
int Q;
cin >> Q;
while (Q--) {
int x;
cin >> x;
x--;
cout << solve(x) << "\n";
}
}
return 0;
}