#include#include #include #include #include #include using namespace std;typedef long long ll;typedef pair P;int n, m, s;struct edge{ int to, nxt;}e[1000005];int h[100005], cnt;void addedge(int x, int y){ cnt++; e[cnt].to = y; e[cnt].nxt = h[x]; h[x] = cnt; cnt++; e[cnt].to = x; e[cnt].nxt = h[y]; h[y] = cnt;}int vis[500005], fa[500005], ans[500005];vector v[500005];int find(int x){ return fa[x] == x ? x : fa[x] = find(fa[x]);}void merge(int x, int y){ int xx = find(x), yy = find(y); fa[yy] = xx;}void Tarjan(int x, int f){ vis[x] = 1; for(int i = h[x]; i; i = e[i].nxt){ if(e[i].to == f) continue; Tarjan(e[i].to, x); merge(x, e[i].to); } for(int i = 0; i < v[x].size(); i ++){ if(vis[v[x][i].first]){ ans[v[x][i].second] = find(v[x][i].first); } }}int main(){ scanf("%d%d%d", &n, &m, &s); for(int i = 1; i < n; i ++){ int x, y; scanf("%d%d", &x, &y); addedge(x, y); } for(int i = 1; i <= m; i ++){ int x, y; scanf("%d%d", &x, &y); v[x].push_back(make_pair(y, i)); v[y].push_back(make_pair(x, i)); } for(int i = 1; i <= n; i ++) fa[i] = i; Tarjan(s, 0); for(int i = 1; i <= m; i ++){ printf("%d ", ans[i]); } return 0;}