#include<bits/stdc++.h>
using namespace std;

vector<int> edges[100005];
bool notFirst[100005];
int ans[100005];

void dfs(int i) {
    if(edges[i].size() == 0) ans[i] = 0;
    for(auto c : edges[i]) {
        dfs(c);
        ans[i] += ans[c] + 1;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n;
    cin>>n;
    for(int i = 0; i < n-1; i++) {
        int u, v;
        cin>>u>>v;
        edges[u].push_back(v);
        notFirst[v] = true;
    }

    for(int i = 1; i <= n; i++) {
        if(!notFirst[i]) {
            dfs(i);
        }
    }

    int m;
    cin>>m;
    for(int i = 0; i < m; i++) {
        int k;
        cin>>k;
        cout<<ans[k]<<endl;
    }


    return 0;
}
