#include<iostream>
using namespace std;
int TC, N, M, H, a[1005][1005], am[1005], v[1005], maxr, maxi;
void dfs(int k, int c) {
v[k] = c;
for(int i = 1; i <= a[k][0]; i++) {
if(v[a[k][i]] == -1) {
dfs(a[k][i], c + 1);
} else {
if(v[a[k][i]] > c + 1) {
dfs(a[k][i], c + 1);
}
}
}
}
int main() {
/*freopen("input.txt", "r", stdin);*/
cin >> TC;
for(int tc = 1; tc <= TC; tc++) {
cin >> N >> M >> H;
for(int i = 0; i < M; i++) cin >> am[i];
for(int i = 0; i < N; i++) a[i][0] = 0;
fill_n(v, N, -1);
for(int i = 0; i < H; i++) {
int x, y;
cin >> x >> y;
a[x][0]++, a[y][0]++;
a[x][a[x][0]] = y, a[y][a[y][0]] = x;
}
for(int i = 0; i < M; i++) {
dfs(am[i], 0);
}
maxr = -1, maxi = -1;
for(int i = 0; i < N; i++) {
if((v[i] != -1 && v[i] > maxr) || v[i] == -1) {
if(v[i] == -1) {
maxi = i;
break;
}
maxr = v[i], maxi = i;
}
}
cout << maxi << endl;
}
return 0;
}