#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#define N 20005
using namespace std;
int head[N],flag[N],father[N],fa[N];
int totre,headre[N],a,b,tot,ancestor[N];
struct edge
{
int vet,next;
}edge[N],require[N];
void add(int u,int v)
{
edge[++tot].vet=v;
edge[tot].next=head[u];
head[u]=tot;
}
int getfather(int x)
{
if(x==father[x])return x;
return father[x]=getfather(father[x]);
}
void merge(int x,int y)
{
x=getfather(x);
y=getfather(y);
if(x!=y)father[x]=y;
}
void tarjan(int u)
{
for(int i=head[u];i!=-1;i=edge[i].next)
{
int v=edge[i].vet;
tarjan(v);
merge(u,v);
ancestor[getfather(u)]=u;
}
flag[u]=true;
for(int i=headre[u];i!=-1;i=require[i].next)
{
int v=require[i].vet;
if(flag[v])
printf("%d\n",ancestor[getfather(v)]);
}
}
void addre(int u,int v)
{
require[++totre].vet=v;
require[totre].next=headre[u];
headre[u]=totre;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(head,-1,sizeof(head));
memset(headre,-1,sizeof(headre));
tot=0,totre=0;int n;
scanf("%d",&n);
memset(fa,0,sizeof(fa));
for(int i=1;i<n;i++)
{
int u,v;
scanf("%d%d",&u,&v);
add(u,v);
fa[v]++;
}
int root;
memset(flag,false,sizeof(flag));
for(int i=1;i<=n;i++)
if(fa[i]==0)root=i;
scanf("%d%d",&a,&b);
addre(a,b);addre(b,a);
for(int i=1;i<=n;i++)
father[i]=i;
tarjan(root);
}
return 0;
}