#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<cmath>
#define maxn 500000
using namespace std;
int dp[1001000][20];
int to[maxn*2],be[maxn*2],ne[2*maxn],e;
int deep[maxn*2],first[2*maxn],cnt,n;
bool p[maxn];
void add(int x,int y){
to[++e]=y;
ne[e]=be[x];
be[x]=e;
}
void dfs(int v,int deepth){
p[v]=1,dp[++cnt][0]=v,first[v]=cnt;
for(int i=be[v];i;i=ne[i]){
if(!p[to[i]]){
deep[to[i]]=deepth;
dfs(to[i],deepth+1);
dp[++cnt][0]=v;
}
}
}
void st(int n){
int len=log2(n)+1;
for(int i=1;i<=len;i++){
for(int j=1;j<=n;j++){
if(j+(1<<(i-1))>n)continue;
if(deep[dp[j][i-1]]<deep[dp[j+(1<<(i-1))][i-1]])
dp[j][i]=dp[j][i-1];
else dp[j][i]=dp[j+(1<<(i-1))][i-1];
}
}
}
int rmq(int a,int b){
if(a>b)swap(a,b);
int k1=log2(b-a+1);
int x,y;
x=dp[a][k1];
y=dp[b-(1<<k1)+1][k1];
if(deep[x]>deep[y])return y;
else return x;
}
int main(){
int i,j,k,m;
scanf("%d%d%d",&n,&m,&k);
for(i=1;i<=n-1;i++){
int x,y;
scanf("%d%d",&x,&y);
add(x,y);
add(y,x);
}
dfs(k,1);
st(cnt);
for(i=1;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
printf("%d\n",rmq(first[x],first[y]));
}
return 0;
}