#include<bits/stdc++.h>
using namespace std;
const int N=500004;
struct edge {
int to,next,num;
}e[N*2],q[N*2];
int head[N],cnt,tot,qhead[N];
void add(int u,int v) {
e[++cnt].next=head[u];
e[cnt].to=v;
head[u]=cnt;
}
void qadd(int u,int v,int index) {
q[++tot].next=qhead[u];
q[tot].to=v;
q[tot].num=index;
qhead[u]=tot;
}
int f[N],ans[N];
bool vis[N];
int find(int u) {
if(f[u]!=u) return f[u]=find(f[u]);
}
void tarjan(int u,int fa) {
for(int i=head[u];i;i=e[i].next) {
int v=e[i].to;
if(v!=fa) {
tarjan(v,u);
f[v]=u;
}
}
vis[u]=1;
for(int i=qhead[u];i;i=q[i].next) {
int v=q[i].to;
if(vis[v]) {
ans[q[i].num]=find(v);
}
}
}
int main() {
int n,m,s;
scanf("%d%d%d",&n,&m,&s);
for(int i=1,u,v;i<=n-1;i++) {
f[i]=i;
scanf("%d%d",&u,&v);
add(u,v);
add(v,u);
}
f[n]=n;
for(int i=1,u,v;i<=m;i++) {
scanf("%d%d",&u,&v);
qadd(u,v,i);
qadd(v,u,i);
}
tarjan(s,0);
for(int i=1;i<=m;i++) {
printf("%d\n",ans[i]);
}
return 0;
}