#include<bits/stdc++.h>
using namespace std;

const int maxn=1e5 + 3;
int n, qu;
vector<int> children[maxn];
int ans[maxn];
int parent[maxn];
int root=-1;
bool vis[maxn];

void dfs(int x){
    vis[x]=true;
    for(int i=0; i<children[x].size(); i++){
        int next_node=children[x][i];
        if(!vis[next_node]){
            dfs(next_node);
        }
        //cerr<<"kum "<<x<<" pribavqm i decata na "<<next_node<<" koito sa "<<ans[next_node]<<endl;
        ans[x]+=1+ans[next_node];
    }
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

cin>>n;

for(int i=1; i<=n-1; i++){
    int u, v;
    cin>>u>>v;
    children[u].push_back(v);
    parent[v]=u;
}

for(int i=1; i<=n; i++){
    if(children[i].size()==0){
        ans[i]=0;
    }
    if(parent[i]==0 and root==-1){
        root=i;
    }
}

dfs(root);

cin>>qu;
while(qu--){
    int x;
    cin>>x;
    cout<<ans[x]<<endl;
}

return 0;
}

