#include <bits/stdc++.h>
using namespace std;
#define V vector
#define all0(x) (x).begin(),(x).end()
#define all1(x) (x).begin()+1,(x).end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#ifdef LOCAL
#define cin std::cin
#define cout std::cout
#endif
typedef long long LL;
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const int MN = 5e5 + 20;
const int INF = 2e9+1000;
const LL INFLL = 8e18+1000;
V<int> e[MN];
int gro[MN][25];
int dep[MN];
void dfs1(int x,int p){
gro[x][0]=p;
for(auto y: e[x]){
if(y==p) continue;
dep[y]=dep[x]+1;
dfs1(y,x);
}
}
void solve() {
int n,q,root;cin>>n>>q>>root;
for(int i=1;i<n;i++){
int a,b;cin>>a>>b;
e[a].pb(b);
e[b].pb(a);
}
dfs1(root,0);
for(int i=1;i<=n;i++){
for(int j=1;j<=24;j++){
gro[i][j]=gro[gro[i][j-1]][j-1];
}
}
for(int i=1;i<=q;i++){
int a,b;cin>>a>>b;
if(a==b) {
cout<<b<<"\n";
return;
}
if(dep[a]<dep[b]) swap(a,b);
int dis=dep[a]-dep[b];
for(int i=0;i<=30;i++) {
if((1<<i)&dis) a=gro[a][i];
}
if(a==b) {
cout<<b<<"\n";
continue;
}
for(int i=24 ;i>=0;i--){
if(gro[a][i]!=gro[b][i]) a=gro[a][i],b=gro[b][i];
}
cout<<gro[a][0]<<"\n";
}
}
int main() {
#ifndef LOCAL
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#endif
#ifdef LOCAL
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif
int tt=1;
while (tt--)
solve();
}