#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];
bool used[maxn];

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

cin>>n;

for(int i=1; i<=n; i++){
    parent[i]=-1;
}

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

queue<int> q;

for(int i=1; i<=n; i++){
    if(children[i].size()==0){
        if(!used[parent[i]]){
            q.push(parent[i]);
            used[parent[i]]=true;
        }
        ans[i]=0;
    }
}

while(!q.empty()){
    int curr=q.front();
    q.pop();

    if(curr!=-1){

        for(int i=0; i<children[curr].size(); i++){
            //cerr<<"kum "<<curr<<" dobavih i decata na "<<children[curr][i]<<endl;
            ans[curr]+=ans[children[curr][i]]+1;
        }
        if(parent[curr]!=-1 and !used[parent[curr]]){
            used[parent[curr]]=true;
            q.push(parent[curr]);
        }
    }

}

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

return 0;
}

