#include<bits/stdc++.h>
using namespace std;
vector<int> edges[100001];
int employes[1000001];
unordered_set<int>top;
int solve(int N)
{
    int sum=0;
    for(auto c:edges[N])
    {
        if(employes[c]==0)
        {
            employes[c]=solve(c);
        }
        sum+=1+employes[c];
    }
    return sum;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int S,n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        top.insert(i);
    }
    for(int i=0;i<n-1;i++)
    {
        int U,V;
        cin>>U>>V;
        top.erase(V);
        edges[U].push_back(V);
    }

    employes[*top.begin()]=solve(*top.begin());
    int Q;
    cin>>Q;
    for(int i=0;i<Q;i++)
    {
        int a;
        cin>>a;
        cout<<employes[a]<<"\n";
    }
    return 0;
}
