#include "iostream"
#include "algorithm"
#include "queue"
#include "string.h"
using namespace std;
typedef long long int ll;
vector<int> vg[2000005];
bool used[2000005];
ll dp[2000005];
ll myFunction(int root , int parent){
used[root] = true;
ll max1 = 0, max2 = 0;
for( int i= 0; i < vg[root].size(); i++) {
if(parent == vg[root][i]) continue;
ll x = myFunction(vg[root][i],root) + 1;
if(x >= max1 ) {
max2 = max1;
max1 = x;
}
else max2 = max(x,max2);
}
dp[root] = max1 + max2;
return max1;
}
int main(){
ios::sync_with_stdio(0);
int n ,m,u,v,query,root;
cin >> n ;
for(int i=1 ; i <= n-1 ; i++) {
cin >> u >> v ;
vg[v].push_back(u);
vg[u].push_back(v);
}
memset(used, false,sizeof(used));
memset(dp,0,sizeof(dp));
cin >> root >> query;
myFunction(root,-1);
while(query --) {
cin >> u;
cout << dp[u] <<"\n";
}
return 0;
}
CiNpbmNsdWRlICJpb3N0cmVhbSIKI2luY2x1ZGUgImFsZ29yaXRobSIKI2luY2x1ZGUgInF1ZXVlIgojaW5jbHVkZSAic3RyaW5nLmgiCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIGxvbmcgbG9uZyBpbnQgbGw7CnZlY3RvcjxpbnQ+IHZnWzIwMDAwMDVdOwpib29sIHVzZWRbMjAwMDAwNV07CmxsIGRwWzIwMDAwMDVdOwoKbGwgbXlGdW5jdGlvbihpbnQgcm9vdCAsIGludCBwYXJlbnQpewogICB1c2VkW3Jvb3RdID0gdHJ1ZTsKICAgbGwgbWF4MSA9IDAsIG1heDIgPSAwOwogICBmb3IoIGludCBpPSAwOyBpIDwgdmdbcm9vdF0uc2l6ZSgpOyBpKyspIHsKICAgICAgaWYocGFyZW50ID09IHZnW3Jvb3RdW2ldKSBjb250aW51ZTsKICAgICAgICAgbGwgeCA9ICBteUZ1bmN0aW9uKHZnW3Jvb3RdW2ldLHJvb3QpICsgMTsKICAgICAgICAgaWYoeCA+PSBtYXgxICkgewogICAgICAgICAgICBtYXgyID0gbWF4MT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