#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 solve(guy, sum);
    }
    return;
}

void print_office(map <int, vector <int>> office) {
    for (auto couple:office) {
        cout << couple.first << " - ";
        for (auto worker:couple.second) {
            cout << worker << ' ';
        }
    }
}

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