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

int n;
vector<int> tree[100005];
int ans[100005];

void obhojdane(vector<int> obh, int curr){
    for(auto i : obh) ans[i]++;
    obh.push_back(curr);
    if(tree[curr].size() == 0) return;
    for(auto i : tree[curr]){
        obhojdane(obh, 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;
        ans[c] = 1;
        tree[p].push_back(c);
    }

    int root = 0;
    for(int i = 1; i <=n; i++){
        if(ans[i] == 0){
            root = i;
            ans[i] = 1;
        }
    }

    vector<int> obh;
    obhojdane(obh, root);

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

    return 0;
}
