#include<bits/stdc++.h>
#define fore(i,STARTNOWX) for(int i=head[STARTNOWX];i;i=e[i].next)
#define toi e[i].to
using namespace std;
int n,m,r,cnt=0,head[500005];
struct EDGE{
int to,next;
}e[500005<<1|1];
inline void addedge(int u,int v){
e[++cnt].to=v;
e[cnt].next=head[u];
head[u]=cnt;
}
int f[500005][20],dp[500005];
void dfs(int now,int fa){
f[now][0]=fa;
dp[now]=dp[fa]+1;
for(int i=1;(1<<i)<=dp[now];i++)
f[now][i]=f[f[now][i-1]][i-1];
fore(i,now)
if(toi!=fa)
dfs(toi,now);
}
int LCA(int x,int y){
if(x==y)
return x;
if(dp[x]<dp[y])
swap(x,y);
for(int i=20;i>=0;i--)
if(dp[y]<=dp[x]-(1<<i))
x=f[x][i];
if(x==y)
return x;
for(int i=20;i>=0;i--)
if(f[x][i]!=f[y][i])
x=f[x][i],y=f[y][i];
return x;
}
signed main(){
cin.tie(0)->sync_with_stdio(false);
cin>>n>>m>>r;
for(int i=1,u,v;i<n;i++)
cin>>u>>v,addedge(u,v),addedge(v,u);
dfs(r,r);
for(int i=1;i<=n;i++){
for(int j=0;j<3;j++)
cerr<<f[i][j]<<" ";
cerr<<'\n';
}cerr<<'\n';
for(int i=1,x,y;i<=m;i++)
cin>>x>>y,cout<<LCA(x,y)<<'\n';
return 0;
}