//https://www.cnblogs.com/hulean/p/11144059.html
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
int n,m,s;
const int N = 2e6+9;
int idx,e[N],ne[N],h[N];
int deep[N],fa[N][30];
void add(int a,int b)
{
    e[idx] = b,ne[idx] = h[a],h[a] = idx++;
}
void dfs(int u,int father)
{
    deep[u] = deep[father] + 1;
    for(int i=1; (1<<i) <= deep[u]; i++)
    {
        fa[u][i] = fa[fa[u][i-1]][i-1];
    }
    for(int i=h[u]; i!=-1; i=ne[i])
    {
        int j = e[i];
        if(j == father) continue;
        fa[j][0] = u;
        dfs(j,u);
    }
}
int LCA(int x,int y)
{
    if(deep[x] < deep[y]) swap(x,y);
    for(int i=20; i>=0; i--)
    {
        if(deep[fa[x][i]] >= deep[y]) x = fa[x][i];
        if(x == y) return x;
    }
    for(int i=20; i>=0; i--)
    {
        if(fa[x][i] != fa[y][i])
        {
            x = fa[x][i];
            y = fa[y][i];
        }
    }
    return fa[x][0];
}
int main()
{
    memset(h,-1,sizeof(h));
    scanf("%d%d%d",&n,&m,&s);
    for(int i=1; i<n; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        add(a,b);
        add(b,a);
    }
    dfs(s,0);
    for(int i=1; i<=m; i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        printf("%d\n",LCA(x,y));
    }
    return 0;
}