#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5, M=20;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
int head[N],tot;
struct node{
int to,next;
}e[N<<1];
void add(int u,int v){e[tot].to=v;e[tot].next=head[u];head[u]=tot++;}
int p[N][M];
int d[N];
int n,m,root;
void dfs(int u,int fa){
d[u]=d[fa]+1;
p[u][0]=fa;
for(int i=1;i<M;i++) p[u][i]=p[p[u][i-1]][i-1];
for(int i=head[u];~i;i=e[i].next)
if(e[i].to!=fa) dfs(e[i].to,u);
}
int Log[N];
void pre(){
for(int i=2;i<=n;i++) Log[i]=Log[i/2]+1;
}
int LCA(int x,int y){
if(d[x]<d[y]) swap(x,y);
for(int i=M-1;i>=0;i--)
if(d[x]-(1<<i)>=d[y]) x=p[x][i];
if(x==y) return x;
for(int i=M-1;i>=0;i--){
if(p[x][i]!=p[y][i]){
x=p[x][i];
y=p[y][i];
}
}
return p[x][0];
}
int main(){
memset(head,-1,sizeof head);
cin>>n>>m>>root;
for(int i=1;i<=n-1;i++){
int u,v; u=read(); v=read();
add(u,v); add(v,u);
}
dfs(root,0);
pre();
while(m--){
int x,y; x=read(); y=read();
cout<<LCA(x,y)<<endl;
}
return 0;
}