using namespace std;
typedef long long ll;
const int N = 5e5 + 30;int n, m, s, fa[N][25], dep[N], vis[N];
//点数 询问数,根节点序号
//fa[x][0] x的父亲
//fa[x][y] x向上2^y步到达的点
vector<int>edge[N];
void dfs(int x)//深度表
{vis[x] = 1;for (int i = 0; i < edge[x].size(); i++){int to = edge[x][i];if (!vis[to]){dep[to] = dep[x] + 1;fa[to][0] = x;dfs(to);}}
}
int main()
{cin >> n >> m >> s;for (int i = 1; i <= n - 1; i++){int x, y;cin >> x >> y;//双向边edge[x].push_back(y);edge[y].push_back(x);}dfs(s);for (int j = 1; j < 20; j++){for (int i = 1; i <= n; i++){int y = fa[i][j - 1];//中间点fa[i][j] = fa[y][j - 1];}}for (int i = 1; i <= m; i++){int x, y;cin >> x >> y;if (dep[x] > dep[y]){swap(x, y);}int d = dep[y] - dep[x];//让y与x跳到同一深度for (int i = 19; i >= 0; i--){if ((d >> i) & 1){y = fa[y][i];//往上跳2^i次方步}}int lca;if (x==y){lca = x;}else{//跳到LCA前的一步for (int i = 19; i >= 0; i--){if (fa[x][i] == fa[y][i])continue;else{//不同点x = fa[x][i];y = fa[y][i];}}lca = fa[x][0];}cout << lca << '\n';}return 0;
}