#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <queue>
#define endl "\n"
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define int long long
#define ULL unsigned long long
#define ls(k) k << 1
#define rs(k) k << 1 | 1
#define mid(a, b) (a + b) >> 1
const int N = 500010;
using namespace std;
inline int read(){
int num = 0;
char c;
bool flag = false;
while((c = getchar()) == ' ' || c == '\n' || c == '\r');
if(c == '-') flag = true;
else num = c - '0';
while(isdigit(c = getchar())) num = num * 10 + c - '0';
return (flag ? -1 : 1) * num;
}
int n, m, root;
int h[N * 2], nx[N * 2], to[N * 2], idx;
int f[N][21], dep[N];
//f[x][k] 表示 x 的 2 ^ k 辈祖先
//f[x][0] 就是 x 的父节点
void add(int u, int v)
{
to[idx] = v, nx[idx] = h[u], h[u] = idx ++;
to[idx] = u, nx[idx] = h[v], h[v] = idx ++;
}
void init(int now, int fa)
{
dep[now] = dep[fa] + 1;
for (int i = 0; i <= 19; i ++ ) f[now][i + 1] = f[f[now][i]][i];
for (int i = h[now]; i != -1; i = nx[i])
{
int j = to[i];
if (j == fa) continue;
f[j][0] = now;
init(j, now);
}
}
int LCA(int u, int v)
{
if (dep[u] < dep[v]) swap(u, v);
for (int i = 20; i >= 0; i -- )
{
if (dep[f[u][i]] >= dep[v]) u = f[u][i];//先跳到同一层
if (u == v) return u;
}
for (int i = 20; i >= 0; i -- )
if (f[u][i] != f[v][i]) u = f[u][i], v = f[v][i];
return f[u][0];
}
signed main()
{
IOS;
memset(h, -1, sizeof h);
n = read(), m = read(), root = read();
for (int i = 1; i < n; i ++ ) add(read(), read());
init(root, 0);
while (m -- ) cout << LCA(read(), read()) << endl;
}