#include <bits/stdc++.h>
using namespace std;
vector<int> side[500010];
int father[500010][22],depth[500010];
int lg[500010];
int n,m,s;
void dfs(int now,int fa){
int i;
depth[now] = depth[fa]+1;
father[now][0] = fa;
for(i=1;i<=lg[depth[i]];i++)father[now][i] = father[father[now][i-1]][i-1];
for(i=0;i<side[now].size();i++)if(side[now][i]!=fa)dfs(side[now][i],now);
return;
}
int lca(int x,int y){
if(depth[x]<depth[y])swap(x,y);
while(depth[x]>depth[y])x = father[x][lg[depth[x]-depth[y]]-1];
if(x==y)return x;
for(int i=lg[depth[x]]-1;i>=0;i--){
if(father[x][i] != father[y][i]){
x = father[x][i];
y = father[y][i];
}
}
return father[x][0];
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int i,j;
int x,y;
cin>>n>>m>>s;
for(i=1;i<n;i++){
cin>>x>>y;
side[x].push_back(y);
side[y].push_back(x);
}
for(i=1;i<=n;i++)lg[i] = lg[i-1]/2;
dfs(s,0);
for(i=0;i<m;i++){
cin>>x>>y;
cout<<lca(x,y)<<endl;
}
return 0;
}