#include <bits/stdc++.h>

using namespace std;

vector<int> a[100'001]{};
int dp[100'001];

int dfs(int m)
{
    if (dp[m]>0){
        return dp[m];
    }
    int c=0;
    for (int v:a[m]){
        c += 1 + dfs(v);
    }
    return dp[m] = c;
}

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

    int n;
    cin >> n;
    fill(dp, dp+n+1, -1);
    bool r[100'001];
    fill(r, r+n+1, true);
    for (int i=0; i<n-1; ++i){
        int u, v;
        cin >> u >> v;
        a[u].push_back(v);
        r[v] = false;
    }

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

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

    return 0;
}
