#include <iostream>
#define endl '\n'

using namespace std;

int employers[100001];
int cnt[100001];
int questions[100000];

int main() {
    int n, q;
    int u, v;
    int currQ;
    int curr;
    int add;
    cin >> n;

    for (int i = 0; i < n - 1; i++) {
        cin >> u >> v;
        employers[v] = u;
    }

    for (int i = 1; i <= n; i++) {
        curr = i;
        add = cnt[i] + 1;
        while (employers[curr] != 0) {
            cnt[employers[curr]] += add;
            curr = employers[curr];
            cerr << "|| " << employers[curr] << " <- " << curr << " " << cnt[employers[curr]] << endl;
        }
    }

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

    for (int i = 0; i <= n; i++) {
        cerr << "|| " << i << " " << cnt[i] << endl;
    }

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

    return 0;
}
/*
4
1 3
2 1
2 4
3
1
2
4

*/
