#include<bits/stdc++.h>
using namespace std;

int n, ans;
vector<int> tree[40000];

void obhojdane(int curr){
    if(tree[curr].size() == 0) return;
    for(auto i : tree[curr]){
        ans++;
        obhojdane(i);
    }
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n;
    for(int i = 0; i < n-1; i++){
        int p, c;
        cin >> p >> c;
        tree[p].push_back(c);
    }

    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        int cq;
        cin >> cq;
        ans = 0;
        obhojdane(cq);
        cout << ans << "\n";
    }

    return 0;
}
