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

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

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  << " " << sega[vruh] << endl;
    bool flag=true;
    while(flag){
        flag=false;
        for(int i=1;i<=n;i++){
            //cout<< "i=" << i << " " << sega[i] << endl;
            if(turnoff[i]){
                turnoff[i]=false;
                continue;
            }
            if(!sega[i] && !minati[i]){
                //cout<< i << " :: ";
                sega[i]=true;
                minati[i]=true;
                sega[shef[i]]=false;
                if(shef[i]>i){
                    turnoff[shef[i]]=true;
                }
                if(shef[i]!=vruh) flag=true;
                predishno[shef[i]]=br[shef[i]];
                br[shef[i]]+=br[i]+1;
                //cout<< shef[i] << " " << br[shef[i]] << endl;
            }else if(!sega[i] && minati[i] && predishno[i]!=br[i]){
                predishno[shef[i]]=br[shef[i]];
                br[shef[i]]+=br[i]-predishno[i];
                //cout<< shef[i] << " aa" << br[i] << " " << predishno[i] << endl;

                sega[i]=true;
                sega[shef[i]]=false;
                if(shef[i]>i){
                    turnoff[shef[i]]=true;
                }
                if(shef[i]!=vruh) flag=true;
            }
        }
        //cout<< endl;
    }
    int q;
    cin>> q;
    for(int i=0;i<q;i++){
        int t;
        cin>> t;
        cout<< br[t] << endl;
    }





    return 0;
}
