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

using namespace std;

int solve(int a, map <int, vector <int>> office, int sum) {
    for (auto guy:office[a]) {
        sum += 1;
        sum = solve(guy, office, sum);
    }
    return sum;
}

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;
    map <int, vector <int>> office;
    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;
        cout << solve(a, office, 0) << endl;
    }
}
