#include <bits/stdc++.h>
using namespace std;
const int N = 5e5+5;
int n, m, s,f [N][22], sh[N];
vector<int> e[N];
void dfs(int x,int fa){
sh[x] = sh[fa] + 1;
f[x][0] = fa;
for(int i = 1;(1 << i) <= sh[x];i++){
f[x][i] = f[f[x][i - 1]][i - 1];
}
for(int i = 0;i < e[x].size();i++){
int v = e[x][i];
if(v != fa){
dfs(v, x);
}
}
}
int lca(int x, int y){
if(sh[y] > sh[x]) swap(x,y);
for(int k = 19;k >= 0;k--) if(sh[f[x][k]]>=sh[y]) x = f[x][k];
if(x==y) return x;
for(int k = 19;k >= 0;k--) if(f[x][k] != f[y][k]) x = f[x][k],y = f[y][k];
return f[x][0];
}
int main()
{
cin>>n>>m>>s;
for(int i = 1;i <= n - 1;i++){
int x, y;
cin>>x>>y;
e[x].push_back(y);
e[y].push_back(x);
}
dfs(s,0);
for(int i = 1;i <= m;i++){
int a, b;
cin>>a>>b;
cout<<lca(a,b)<<endl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5+10;
int n, m, s, f[N][22], sh[N];
vector<int> e[N];
void dfs(int x, int fa){
f[x][0] = fa;
sh[x] = sh[fa] + 1;
for(int i = 1;(1 << i )<= sh[x];i++){
f[x][i] = f[f[x][i - 1]][i - 1];
}
for(int i = 0;i < e[x].size();i++){
int v = e[x][i];
if(v != fa){
dfs(v,x);
}
}
}
int lca(int x, int y){
if(sh[x] < sh[y]) swap(x, y);
for(int i = 19;i >= 0;i--){
if(sh[y] <= sh[f[x][i]]){
x = f[x][i];
}
}
if(x == y) return x;
for(int i = 19;i >= 0;i--){
if(f[y][i] != f[x][i]){
x = f[x][i],y = f[y][i];
}
}
return f[x][0];
}
int main()
{
cin>>n>>m>>s;
for(int i = 1;i <= n - 1;i++){
int x, y;
cin>>x>>y;
e[x].push_back(y);
e[y].push_back(x);
}
dfs(s,0);
int a, b;
for(int i = 1;i <= m;i++){
cin>>a>>b;
cout<<lca(a,b)<<endl;
}
return 0;
}