#include<iostream>
using namespace std;
int main(){
int n,q,isAbove,isBelow,maxLevel=0;
cin>>n;
struct peeps{
int numberOfServants=0;
int whoIsHeServing=0;
int level=0;
};

peeps people[n+1];

for(int i=0;i<n-1;i++){
    cin>>isAbove>>isBelow;
    people[isBelow].whoIsHeServing=isAbove;
    people[isAbove].numberOfServants++;
    people[isBelow].level=-1;
}
//for(int j=1;j<n+1;j++){
for(int i=1;i<n+1;i++){
    if(people[people[i].whoIsHeServing].level!=-1){
        people[i].level=people[people[i].whoIsHeServing].level+1;

        if(people[i].level>maxLevel)maxLevel=people[i].level;
    }
}
//}
for(int i=maxLevel-1;i>=0;i--){
    for(int j=1;j<n+1;j++){
        if(people[j].level==i){
            people[people[j].whoIsHeServing].numberOfServants+=people[j].numberOfServants;
        }
    }
}
cin>>q;
int ask[q];
for(int i=0;i<q;i++){
    cin>>ask[i];
}
for(int i=0;i<q;i++){
    cout<<people[ask[i]].numberOfServants<<endl;
}

return 0;
}
/*
8
1 5
2 1
2 3
3 4
3 6
4 8
4 7
8
1
2
3
4
5
6
7
8
*/

