#include <bits/stdc++.h>
using namespace std;
 
 
/*
------------------------Input Checker----------------------------------
*/
 
long long readInt(long long l,long long r,char endd){
    long long x=0;
    int cnt=0;
    int fi=-1;
    bool is_neg=false;
    while(true){
        char g=getchar();
        if(g=='-'){
            assert(fi==-1);
            is_neg=true;
            continue;
        }
        if('0'<=g && g<='9'){
            x*=10;
            x+=g-'0';
            if(cnt==0){
                fi=g-'0';
            }
            cnt++;
            assert(fi!=0 || cnt==1);
            assert(fi!=0 || is_neg==false);
 
            assert(!(cnt>19 || ( cnt==19 && fi>1) ));
        } else if(g==endd){
            if(is_neg){
                x= -x;
            }
 
            if(!(l <= x && x <= r))
            {
                cerr << l << ' ' << r << ' ' << x << '\n';
                assert(1 == 0);
            }
 
            return x;
        } else {
            assert(false);
        }
    }
}
string readString(int l,int r,char endd){
    string ret="";
    int cnt=0;
    while(true){
        char g=getchar();
        assert(g!=-1);
        if(g==endd){
            break;
        }
        cnt++;
        ret+=g;
    }
    assert(l<=cnt && cnt<=r);
    return ret;
}
long long readIntSp(long long l,long long r){
    return readInt(l,r,' ');
}
long long readIntLn(long long l,long long r){
    return readInt(l,r,'\n');
}
string readStringLn(int l,int r){
    return readString(l,r,'\n');
}
string readStringSp(int l,int r){
    return readString(l,r,' ');
}
 
 
/*
------------------------Main code starts here----------------------------------
*/
 
const int MAX_T = 1e5;
const int MAX_N = 1e5;
const int MAX_SUM_LEN = 1e5;
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define mp make_pair
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
 
int sum_n = 0, sum_m = 0;
int max_n = 0, max_m = 0;
int yess = 0;
int nos = 0;
int total_ops = 0;
ll mod = 1000000007;

using ii = pair<ll,ll>;

vector<int> isat;
vector<vector<int> > g;
vector<ll> mx, sum, cnt;
int istree;
ll ans;
int k, id;

void dfs1(int c, int p){
    istree++;
    if(isat[c]){
        cnt[c]=1;
        mx[c]=0;
    }
    for(auto h:g[c]){
        if(h!=p){
            dfs1(h,c);
            cnt[c]+=cnt[h];
            sum[c]+=(sum[h]+cnt[h]);
            if(mx[h]>-1) mx[c] = max(mx[c], 1+mx[h]);
        }
    }
}

void dfs2(int c, int p, ll mx1, ll ss){
    ll mx2=-1, mx3=-1;
    

    for(auto h:g[c]){
        if(h==p) continue;
        if(mx[h]>mx2){
            mx3=mx2;
            mx2=mx[h];
        }
        else if(mx[h]>mx3) mx3=mx[h];
    }

    if(mx1>-1) mx1++;
    if(mx2>-1) mx2++;
    if(mx3>-1) mx3++;

    ss += k-2*cnt[c];

    if(ans>ss-max(mx[c], mx1)){
        ans = ss-max(mx[c], mx1);
        id = c;
    }
    else if(ans==ss-max(mx[c], mx1)) id = max(id, c);

    for(auto h:g[c]){
        if(h==p) continue;
        if(mx[h]!=-1 && mx[h]+1==mx2) dfs2(h,c,max(mx1,mx3), ss);
        else dfs2(h,c,max(mx1,mx2), ss);
    }
}

void solve(){
    int n;
    n = readIntSp(1,1e5);
    k = readIntLn(1, n);

    isat.assign(n+1, 0);
    g.assign(n+1, vector<int>());

    int x,y;
    rep(i,k){
        if(i<k-1) x = readIntSp(1,n);
        else x = readIntLn(1,n);
        assert(isat[x]==0);
        isat[x]=1;
    }

    rep(i,n-1){
        x = readIntSp(1,n);
        y = readIntLn(1,n);
        assert(x!=y);
        g[x].pb(y);
        g[y].pb(x);
    }

    mx.assign(n+1,-1);
    sum.assign(n+1,0);
    cnt.assign(n+1,0);

    istree = 0;
    dfs1(1,0);

    assert(istree==n);


    if(k==1){
        cout<<n<<'\n';
        return;
    }

    ans = 1e12;
    id = -1;

    dfs2(1, 0, -1, sum[1]+k);

    cout<<id<<'\n';
}


 
signed main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
    fast;
    
    int t = 1;
    
    t = readIntLn(1,10);
    
    for(int i=1;i<=t;i++)
    {    
       solve();
    }
   
    assert(getchar() == -1);
    //assert(sum_n<=2e5);
 
    cerr<<"SUCCESS\n";
    cerr<<"Tests : " << t << '\n';
    cerr<<"Sum of lengths : " << sum_n <<" "<<sum_m<<'\n';
    // cerr<<"Maximum length : " << max_n <<'\n';
    // // cerr<<"Total operations : " << total_ops << '\n';
    // cerr<<"Answered yes : " << yess << '\n';
    // cerr<<"Answered no : " << nos << '\n';

    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}