#include<bits/stdc++.h>
using namespace std;
int n,m,s,root;
int h[514514],e[1014514],ne[1014514],idx;
int f[514514][16];
int d[514514];
int q[514514];
void add(int a,int b)
{
e[idx]=b;
ne[idx]=h[a];
h[a]=idx++;
}
void bfs(int root)
{
memset(d,0x3f,sizeof d);
d[0]=0;d[root]=1;
int hh=0,tt=0;
q[0]=root;
while(hh<=tt)
{
int t=q[hh++];
for(int i=h[t];~i;i=ne[i])
{
int j=e[i];
if(d[j]>d[t]+1)
{
d[j]=d[t]+1;
q[++tt]=j;
f[j][0]=t;
for(int k=1;k<=15;k++)
f[j][k]=f[f[j][k-1]][k-1];
}
}
}
}
int lca(int a,int b)
{
if(d[a]<d[b])
swap(a,b);
for(int k=15;k>=0;k--)
if(d[f[a][k]]>=d[b])
a=f[a][k];
if(a==b)
return a;
for(int k=15;k>=0;k--)
if(f[a][k]!=f[b][k])
{
a=f[a][k];
b=f[b][k];
}
return f[a][0];
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0);
cin>>n>>m>>s;
memset(h,-1,sizeof h);
root=s;
for(int i=1;i<n;i++)
{
int a,b;
cin>>a>>b;
add(a,b),add(b,a);
}
bfs(root);
while(m--)
{
int a,b;
cin>>a>>b;
if(a==b)
cout<<a<<'\n';
else
cout<<lca(a,b)<<'\n';
}
return 0;
}