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


void go_one_down(int curr){
    for(int i=1;i<=n;i++){
        if(podchinen[curr][i]){
            go_one_down(i);
            br_podchineni[curr]+=br_podchineni[i]+1;
        }
    }
}

int main(){
    cin>>n;
    int higher;
    int lower;
    for(int i=1;i<=n-1;i++){
        cin>>higher>>lower;
        podchinen[higher][lower]=true;
        //br_podchineni[higher]++;
        br_e_podchinen[lower]++;
    }
    for(int i=0;i<n;i++){
        if(br_e_podchinen[i]==0){
            go_one_down(i);
        }
    }
    //for(int i=1;i<=n;i++){
        //cout<<i<<" "<<br_podchineni[i]<<endl;
    //}
    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

*/
