#include <iostream>
#include <bits/stdc++.h>
// #include <cmath>

using namespace std;


// int max_(int arr[], int l) {
//     //returns the index of the largest value
//     int max_n = 0, max_i = 0;
//     for ( int i = 0; i < l; i ++ ) {
//         if ( max_n < arr[i] ) {
//             max_i = i;
//             max_n = arr[i];
//         }
//     }
//     return max_i;


struct Node {
    queue<int> children;
};

int sumNode(Node n, Node arr[]) {
    int c = n.children.size();
    while (n.children.size()) {
        c += sumNode(arr[n.children.front()], arr);
        n.children.pop();
    }
    return c;
}

int main () {
    int n;
    cin >> n;
    n --;
    int arr[n], children[n];
    for ( int i = 0; i < n; i ++ ) {
        cin >> arr[i] >> children[i];
        // tree[arr[i]].children.push(children[i]);
    }
    // binary tree here
    // max(arr[max_(arr, n)], children[max_(children, n)]) + 1
    Node tree[500];
    for ( int i = 0; i < n; i ++ ) {
        tree[arr[i]].children.push(children[i]);
    }
    int q;
    cin >> q;
    int q_arr[q];
    for ( int i = 0; i < q; i ++ ) {
        cin >> q_arr[i];
        cout << sumNode(tree[q_arr[i]], tree) << endl;
    }
    return 0;
}
