import sys
from math import log
input = lambda: sys.stdin.readline().strip()
n,m,s=map(int,input().split())
tree=[[] for _ in range(n+1)]
f=[[-1]*21 for _ in range(n+1)]
depth=[0]*(n+1)
depth[s]=0
def dfs(v,p):
f[v][0]=p
d=depth[v]+1
for i in range(1,d):
if (1<<i)>=d:
break
f[v][i]=f[f[v][i-1]][i-1]
for u in tree[v]:
if u!=p:
depth[u]=d
dfs(u,v)
def lca(u,v):
if depth[u]<depth[v]:
u,v=v,u
t=depth[u]-depth[v]
for i in range(20,-1,-1):
if t&(1<<i):
u=f[u][i]
if u==v:
return u
for i in range(int(log(depth[u],2)),-1,-1):
if f[u][i]!=f[v][i]:
u,v=f[u][i],f[v][i]
return f[u][0]
for i in range(n-1):
x,y=map(int,input().split())
tree[x].append(y)
tree[y].append(x)
dfs(s,-1)
for i in range(m):
u,v=map(int,input().split())
print(lca(u,v)+1)