#include <iostream>
#include <map>
#include <vector>

using namespace std;
map <int, vector <int>> office;
map <int, int> results;

void solve(int a, int &sum) {

    for (auto guy:office[a]) {
        sum++;
        if (results[guy]) {
            sum += results[guy];
        }
        else {
            int previous_sum = sum;
            solve(guy, sum);
            results[guy] = sum - previous_sum;
        }
    }
}

int main() {
    int N, a, b;
    cin >> N;
    for (int i = 1; i < N; i++) {
        cin >> a >> b;
        office[a].push_back(b);
    }
    cin >> N;
    for (int i=0; i < N; i++) {
        cin >> a;
        int s = 0;
        solve(a, s);
        results[a] = s;
        cout << s << endl;
    }
    return 0;
}
