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

int brVurhove, brRebra, q;
vector<int> decaNa[100001];
vector<int> deca[100001];
queue<int> susediZaObhojdane;
int ans[100001];
int zaqvki [100001];
int brVlizashti [100001];
bool imaligo[100001];

void bfs(){
    while(!susediZaObhojdane.empty()){
        int tekVruh = susediZaObhojdane.front();
        susediZaObhojdane.pop();
        for(int i = 0 ; i < decaNa[tekVruh].size() ; i++){
            int tekDete = decaNa[tekVruh][i];
            ans[tekDete] += (ans[tekVruh] + 1);
            if(!imaligo[tekDete]){
                susediZaObhojdane.push(tekDete);
                imaligo[tekDete] = true ;
            }
        }
    }
}

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;
        deca[a].push_back(b);
        decaNa[b].push_back(a);
        brVlizashti[a] ++ ;
    }
    for(int i = 1 ; i <= brVurhove ; i ++){
        if(brVlizashti [i] == 0){
            susediZaObhojdane.push(i);
        }
    }
    bfs();

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

    return 0;
}
/*
15
1 2
1 3
1 4
2 5
2 6
4 7
5 8
6 9
7 10
9 11
10 12
12 13
12 14
12 15

*/
