#include<iostream>
#include<queue>
using namespace std;
const int MAX_N = 100000;
int podchineni[MAX_N];
int parent[MAX_N];
bool hasChildren[MAX_N];
int n, q;
vector<int> tr[MAX_N];
queue<int> obh;
bool putInQueue[MAX_N];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        parent[i] = -1;
    }
    for(int i = 0; i < n - 1; i++)
    {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        tr[u].push_back(v);
        parent[v] = u;
        hasChildren[u] = true;
    }
    for(int i = 0; i < n; i++)
    {
        if(!hasChildren[i])
        {
            obh.push(i);
            putInQueue[i] = true;
        }
    }
    while(!obh.empty())
    {
        int currV = obh.front();
        obh.pop();
        /*if(hasChildren[currV])
        {
            for(int i = 0; i < tr[currV].size(); i++)
            {
                int child = tr[currV][i];
                podchineni[currV] += podchineni[child] + 1;
            }
        }*/
        if(parent[currV] == -1)
        {
            break;
        }
        podchineni[parent[currV]] += podchineni[currV] + 1;
        if(!putInQueue[parent[currV]])
        {
            obh.push(parent[currV]);
        }
    }
    cin >> q;
    for(int i = 0; i < q; i++)
    {
        int query;
        cin >> query;
        query--;
        cout << podchineni[query] << endl;
    }
    return 0;
}
