#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(!"https://envs.sh/LW");
    cin.tie(0);

    int n;
    cin >> n;
    int p[100'001], d[100'001]{0};
    for (int i=0; i<n-1; ++i){
        int u, v;
        cin >> u >> v;
        p[v] = u;
        for (int w=v; w; w=p[w]){
            ++d[w];
        }
    }

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

    return 0;
}
