#include <bits/stdc++.h>
using namespace std;
const int MAXN=500005;
vector<int> adj[MAXN];
int fa[MAXN];
int depth[MAXN];
void bfs(int root){
queue<int> q;
q.push(root);
fa[root]=0;
depth[root]=1;
while(!q.empty()){
int u=q.front();
q.pop();
for(int v:adj[u]){
if(v!=fa[u]){
fa[v]=u;
depth[v]=depth[u]+1;
q.push(v);
}
}
}
}
int lca(int u,int v){
while(depth[u]>depth[v]){
u=fa[u];
}
while(depth[u]<depth[v]){
v=fa[v];
}
while(u!=v){
v=fa[v];
u=fa[u];
}
return u;
}
int main() {
int N,M,R;
cin>>N>>M>>R;
for(int i=0;i<N-1;i++){
int x,y;
cin>>x>>y;
adj[x].push_back(y);
adj[y].push_back(x);
}
bfs(R);
while(M--){
int a,b;
cin>>a>>b;
cout<<lca(a,b)<<endl;
}
}
// 64 位输出请用 printf("%lld")