#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=5e4+100,B=16;
mt19937 rnd(time(0));
#define gc getchar()
#define rd read()
inline int read(){
int x=0,f=0; char c=gc;
for(;c<'0'||c>'9';c=gc) f|=(c=='-');
for(;c>='0'&&c<='9';c=gc) x=(x<<1)+(x<<3)+(c^48);
return f?-x:x;
}
int n,s,t,id[N];
vector<int> G[N];
int dep[N],dfn[N],d_c=0,st[N][B+5];
inline int get(int x,int y){ return dfn[x]<dfn[y]?x:y; }
void dfs0(int u,int fu){
st[dfn[u]=++d_c][0]=fu,dep[u]=dep[fu]+1;
for(int v:G[u]) if(v!=fu) dfs0(v,u);
}
inline void init(){ for(int k=1;k<=B;++k) for(int i=1;i+(1<<k)-1<=n;++i) st[i][k]=get(st[i][k-1],st[i+(1<<(k-1))][k-1]); }
inline int flca(int x,int y){ if((x=dfn[x])==(y=dfn[y])) return x; if(x>y) swap(x,y); int k=__lg(y-(++x)+1); return get(st[x][k],st[y+1-(1<<k)][k]); }
inline int fdis(int x,int y){ return dep[x]+dep[y]-2*dep[flca(x,y)]; }
void solve(){
n=rd,s=rd,t=rd;
for(int i=1,x,y;i<n;++i) x=rd,y=rd,G[x].pb(y),G[y].pb(x);
dfs0(1,0),init();
for(int i=1;i<=n;++i) id[i]=i;
shuffle(id+1,id+n+1,rnd);
for(int i=2;i<=n;++i) if(id[i]==s) swap(id[1],id[i]);
for(int i=1;i<n;++i) if(id[i]==t) swap(id[n],id[i]);
int cur=0; for(int i=1;i<n;++i) cur^=fdis(id[i],id[i+1]);
if(n>3){
for(int i=1;cur>1&&i<=200*n;++i){
int x=rnd()%n+1,y=rnd()%n+1;
while(x==1||x==n) x=rnd()%n+1;
while(y==1||y==n||y==x) y=rnd()%n+1;
cur^=fdis(id[x],id[x-1])^fdis(id[y],id[x-1]);
cur^=fdis(id[x],id[x+1])^fdis(id[y],id[x+1]);
cur^=fdis(id[y],id[y-1])^fdis(id[x],id[y-1]);
cur^=fdis(id[y],id[y+1])^fdis(id[x],id[y+1]);
swap(id[x],id[y]);
}
if(cur>1){
for(int i=1;cur>3&&i<=200*n;++i){
int x=rnd()%n+1,y=rnd()%n+1
while(x==1||x==n) x=rnd()%n+1;
while(y==1||y==n||y==x) y=rnd()%n+1;
cur^=fdis(id[x],id[x-1])^fdis(id[y],id[x-1]);
cur^=fdis(id[x],id[x+1])^fdis(id[y],id[x+1]);
cur^=fdis(id[y],id[y-1])^fdis(id[x],id[y-1]);
cur^=fdis(id[y],id[y+1])^fdis(id[x],id[y+1]);
swap(id[x],id[y]);
}
}
}
for(int i=1;i<=n;++i) printf("%d ", id[i]); puts("");
for(int i=1;i<=n;++i) G[i]={}; d_c=0;
}
int main(){
int T=rd;
while(T--) solve();
return 0;
}