#include<iostream>
using namespace std;
int podchinen[100000];
int br_podchineni[100000];
//int br_e_podchinen[40000];
int n;


void go_one_down(int curr){
    for(int i=1;i<=n;i++){
        if(curr==0){return;}
        if(podchinen[i]==curr){
            go_one_down(i);
            br_podchineni[curr]+=br_podchineni[i]+1;
            //cout<<"Podchinen: "<<i<<" na "<<curr<<" i ima "<<br_podchineni[i]<<endl;
        }
    }
}

void go_one_up(int curr){
    int boss=podchinen[curr];
    if(boss!=0){
        br_podchineni[boss]++;
        go_one_up(boss);
    }
    return;
}
int main(){
    cin>>n;
    int higher;
    int lower;
    for(int i=1;i<=n-1;i++){
        cin>>higher>>lower;
        podchinen[lower]=higher;
        //br_e_podchinen[lower]++;
    }
    for(int i=1;i<=n;i++){
        go_one_up(i);
      /*if(br_e_podchinen[i]==0){
            go_one_down(i);
    }*/

    }
    int temp;
    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>temp;
        cout<<br_podchineni[temp]<<"\n";
    }

}



/*

4
1 3
2 1
2 4
3
1
2
4

*/
