#include<bits/stdc++.h>
using namespace std;
const long long M=2e5+10,MOD=998244353;
typedef long long ll;
#define debug(x) cout<<x<<endl
vector<int>edge[M];
int in[M];
int out[M];
int cnt=0;
int A[M];
int freq[M]; // freq[x] = how many times value x appears in the current subarray
bool used[M]; // used[x] indicates whether x <= currentK (so we count it if freq[x] > 0)
int distinctCount;
int curL = 0, curR = -1, curK = 0;
vector<int>convert_A;
void dfs(int x,int p){
in[x]=out[x]=cnt++;
convert_A.push_back(x);
for(auto u:edge[x]){
if(u!=p){
dfs(u,x);
}
}
out[x]=cnt;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t=1;
cin>>t;
while(t--){
int n;
cin>>n;
for(int i=0;i<n;i++)cin>>A[i];
for(int i=1;i<n;i++){
int x,y;
cin>>x>>y;
edge[x].push_back(y);
edge[y].push_back(x);
}
cnt=0;
dfs(1,-1);
int q;
cin>>q;
while(q--){
int x;
cin>>x;
int l=in[x];
int r=out[x]-1;
unordered_map<int,int>mp;
int k=r-l+1;
int c=0;
for(int i=l;i<=r;i++){
int cur=A[convert_A[i]-1];
if(cur<=k){
mp[cur]++;
if(mp[cur]==1)c++;
}
}
cout<<k-c<<"\n";
}
for(int i=0;i<=n+1;i++){
edge[i].clear();
in[i]=0;
out[i]=0;
}
convert_A.clear();
cnt=0;
}
return 0;
}