#include<iostream>
#include<vector>
#include<queue>
using namespace std;

int brVurhove, brRebra, q;
vector<int> decaNa[100000];
queue<int> susediZaObhojdane;
int ans[100000];
int brVlizashti [100000];

void bfs(int startVruh){
    susediZaObhojdane.push(startVruh);

    while(!susediZaObhojdane.empty()){
        int tekVruh = susediZaObhojdane.front();
        susediZaObhojdane.pop();
        //cout << "Ans: " << ans [tekVruh] << endl ;
        for(int i = 0 ; i < decaNa[tekVruh].size() ; i++){
            ans [tekVruh] += ans [decaNa[tekVruh][i]];
            //cout << "Ans za tekushto dete na " << tekVruh << " : " << ans [decaNa[tekVruh][i]] << endl ;
            susediZaObhojdane.push(decaNa[tekVruh][i]);
        }
    }
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> brVurhove;
    brRebra = brVurhove - 1;

    int a, b ;
    for(int i = 0 ; i < brRebra ; i ++){
        cin >> a >> b;
        decaNa[a].push_back(b);
        brVlizashti[b] ++ ;
    }

    for(int i = 0 ; i < brVurhove ; i ++){
        ans [i] = decaNa[i].size();
    }

    for(int i = 1 ; i <= brVurhove ; i ++){
        if(brVlizashti[i] == 0){
            //cout << "StartVruh: " << i << endl ;
            bfs(i);
            break;
        }
    }

    cin >> q;
    int zaqvki [100000];
    for(int i = 0 ; i < q ; i ++){
        cin >> zaqvki [i] ;
    }

    for(int i = 0 ; i < q ; i ++){
        cout << ans [zaqvki [i]] << endl ;
    }

    return 0;
}
