#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define endl '\n'
#define test printf("\ntest\n")
const int N = 5e5+10;
int lg[N];
struct node {
int to,near;
}e[500010<<1];
int head[N],cnt;
void add(int x,int y)
{
e[++cnt].to=y;
e[cnt].near=head[x];
head[x]=cnt;
}
int depth[N],fa[N][22];
void dfs(int now,int fath){
depth[now]=depth[fath]+1;
fa[now][0]=fath;
for(int i=1;i<=lg[depth[now]];i++)
{
fa[now][i]=fa[fa[now][i-1]][i-1];
}
for(int i=head[now];i;i=e[i].near)
{
if(e[i].to!=fath)
dfs(e[i].to,now);
}
}
inline int LCA(int ma,int mi){
if(depth[ma]<depth[mi])
swap(ma,mi);
while(depth[ma]>depth[mi]){
ma=fa[ma][depth[ma]-depth[mi]-1];
}
if(ma==mi)
return ma;
for(int k=lg[depth[ma]]-1;k>=0;k--)
{
if(fa[ma][k]!=fa[mi][k])
{
ma=fa[ma][k],mi=fa[mi][k];
}
}
return fa[ma][0];
}
void solve()
{
int n,m,s;
scanf("%d %d %d",&n,&m,&s);
for(int i=1;i<=n-1;i++){
int x,y;
scanf("%d %d",&x,&y);
add(x,y);add(y,x);
}
lg[1]=0;
for(int i=2;i<=n;i++)
lg[i]=lg[i>>1]+1;
dfs(s,0);
for(int i=1;i<=m;i++){
int p,q;
scanf("%d %d",&p,&q);
printf("%d\n",LCA(p,q));
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int t = 1;
while(t--) solve();
return 0;
}