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

int n,br[100003],shef[100003],vruh;
bool sega[1000003];

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

    cin>> n;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>> a >> b;
        shef[b]=a;
        sega[a]=true;
        //cout<< "a=" << a << endl;
        b++;
    }
    for(int i=0;i<n;i++){
        if(shef[i+1]==0) vruh=i+1;
    }
    //cout<< "vruh=" << vruh << endl;
    bool flag=true;
    while(flag){
        flag=false;
        for(int i=1;i<=n;i++){
            //cout<< "i=" << i << " "
            if(!sega[i]){
                //cout<< i << " :: ";
                sega[i]=true;
                sega[shef[i]]=false;
                if(shef[i]!=vruh) flag=true;
                br[shef[i]]+=br[i]+1;
                //cout<< shef[i] << " " << br[shef[i]] << endl;
            }
        }
        //cout<< endl;
    }
    int q;
    cin>> q;
    for(int i=0;i<q;i++){
        int t;
        cin>> t;
        cout<< br[t] << endl;
    }





    return 0;
}