#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int N = 100001;
int a[N];
vector<int>G[N];
int sum[N];
int dfs(int cur,int par){
int x = G[cur].size();
sum[cur] = a[cur];
for(int i = 0;i < x; i++){
int v = G[cur][i];
if(v!=par){
sum[cur] += dfs(v,cur);
}
}
return sum[cur];
}
void dfs1(int cur,int par){
int x = G[cur].size();
sum[cur] = a[cur];
for(int i = 0;i < x; i++){
int v = G[cur][i];
if(v!=par){
dfs1(v,cur);
sum[cur] += sum[v];
}
}
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<n;i++){
int u,v;
cin>>u>>v;
G[u].pb(v);
G[v].pb(u);
}
dfs(1,0);
int q;
cin>>q;
while(q--){
int x;
cin>>x;
printf("%d\n",sum[x]);
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgcGIgcHVzaF9iYWNrCmNvbnN0IGludCBOID0gMTAwMDAxOwoKaW50IGFbTl07CnZlY3RvcjxpbnQ+R1tOXTsKaW50IHN1bVtOXTsKCmludCBkZnMoaW50IGN1cixpbnQgcGFyKXsKCglpbnQgeCA9IEdbY3VyXS5zaXplKCk7CgoJc3VtW2N1cl0gPSBhW2N1cl07CgoJZm9yKGludCBpID0gMDtpIDwgeDsgaSsrKXsKCQlpbnQgdiA9IEdbY3VyXVtpXTsKCQlpZih2IT1wYXIpewoJCQlzdW1bY3VyXSArPSBkZnModixjdXIpOwoJCX0KCX0KCglyZXR1cm4gc3VtW2N1cl07Cn0KCnZvaWQgZGZzMShpbnQgY3VyLGludCBwYXIpewoKCWludCB4ID0gR1tjdXJdLnNpemUoKTsKCglzdW1bY3VyXSA9IGFbY3VyXTsKCglmb3IoaW50IGkgPSAwO2kgPCB4OyBpKyspewoJCQoJCWludCB2ID0gR1tjdXJdW2ldOwoJCWlmKHYhPXBhcil7CgkJCWRmczEodixjdXIpOwoJCQlzd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