#include<iostream>
#include<cmath>
using namespace std;
int n,m,s,f[500005][19],deep[500005],h[1000005],u[500005];
struct tu{
int t;
int n;
}b[1000005];
void in(int i,int x,int y){
b[i].t=y,b[i].n=h[x],h[x]=i;
}
void go(int c,int d){
u[c]=1,deep[c]=d;
for(int e=h[c];e;e=b[e].n) if(!u[b[e].t]){
f[b[e].t][0]=c;
go(b[e].t,d+1);
}
return;
}
void build(){
for(int i=1;i<=n;i++)
for(int j=1;j<=log2(deep[i]-1);j++)
f[i][j]=f[f[i][j-1]][j-1];
}
int LCA(int x,int y){
if(deep[x]<deep[y]) swap(x,y);
int c=deep[x]-deep[y];
while(c>0){
int j=(int)(log2(c));
x=f[x][j],c-=pow(2,j);
}
if(x==y) return x;
int j=(int)(log2(deep[x]-1));
while(f[x][j]!=f[y][j]){
x=f[x][j],y=f[y][j];
if(x==s) return x;
j=(int)(log2(deep[x]-1));
}
while(x!=y) x=f[x][0],y=f[y][0];
return x;
}
int main(){
cin>>n>>m>>s;
for(int i=1;i<n;i++){
int x,y;
cin>>x>>y;
in(i*2-1,x,y);
in(i*2,y,x);
}
go(s,1);
build();
for(int i=1;i<=m;i++){
int x,y;
cin>>x>>y;
cout<<LCA(x,y)<<endl;
}
return 0;
}
记录