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

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

int bfs(int startVruh){
    int ans = 0 ;
    susediZaObhojdane.push(startVruh);

    while(!susediZaObhojdane.empty()){
        int tekVruh = susediZaObhojdane.front();
        susediZaObhojdane.pop();
        for(int i = 0 ; i < decaNa[tekVruh].size() ; i++){
            ans ++ ;
            susediZaObhojdane.push(decaNa[tekVruh][i]);
        }
    }

    return ans ;
}

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);
    }

    cin >> q;
    int tekVruh ;
    for(int i = 0 ; i < q ; i ++){
        cin >> tekVruh ;
        cout << bfs(tekVruh) << endl ;
    }

    return 0;
}
