#include<iostream>
#include<cstdio>
using namespace std;
const int N = 5e6;
struct Edge
{
int to, next;
}e[N << 1];
int cnt = 0;
int head[N << 1];
void add(int from, int to)
{
e[++cnt].to = to;
e[cnt].next = head[from];
head[from] = cnt;
}
int fa[N], dep[N];
int f[N][21];
void dfs(int x)
{
for (int i = head[x]; i; i = e[i].next)
{
int v = e[i].to;
if (v != fa[x])
{
dep[v] = dep[x] + 1;
f[v][0] = fa[v] = x;
dfs(v);
}
}
}
int lca(int x, int y)
{
if (dep[x] > dep[y]) swap(x, y);
for (int i = 20; i >= 0; i--)
if (dep[f[y][i]] >= dep[x])
y = f[y][i];
if (x == y) return x;
for (int i = 20; i >= 0; i--)
{
if (f[y][i] != f[x][i])
{
x = f[x][i];
y = f[y][i];
}
}
return fa[x];
}
int main()
{
int n, m, s;
scanf("%d%d%d", &n, &m, &s);
int u, v;
for (int i = 1; i < n; i++)
{
scanf("%d%d", &u, &v);
add(u, v);
add(v, u);
}
fa[s] = f[s][0] = s;
dfs(s);
for (int x = 1; x <= n; x++)
for (int i = 1; i <= 20; i++)
f[x][i] = f[f[x][i - 1]][i - 1];
for (int i = 1; i <= m; i++)
{
scanf("%d%d", &u, &v);
printf("%d\n", lca(u, v));
}
return 0;
}