#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
//using namespace __gnu_pbds;
//typedef tree< pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
//ordered_set;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
#define X first
#define Y second
#define int long long int
const int N = (int)2e5 + 10;
const int MOD = 1000000007;
int n, m, x;
vector<vector<int>> g;
vector<int> inf;
int rem; int in;
vector<bool> vis;
void dfs(int u){
in++;
vis[u] = true;
for(auto & x: g[u]){
if(x == rem) continue;
if(!vis[x])
dfs(x);
}
}
void solve(){
cin >> n >> m >> x;
g = vector<vector<int>>(n + 1, vector<int>());
inf = vector<int>(x);
for(int i = 0; i < x; ++i)
cin >> inf[i];
for(int i = 0, x, y; i < m; ++i){
cin >> x >> y;
g[x].emplace_back(y);
g[y].emplace_back(x);
}
//start by removing every node
sort(inf.begin(), inf.end());
int mx = 0;
int id = 0;
vis = vector<bool>(n + 1, false);
for(int i = 0; i < x; ++i){
in = 1;
rem = inf[i];
fill(vis.begin(), vis.end(), false);
for(int j = 0; j < x; ++j){
if(j == i) continue;
if(!vis[inf[j]]){
dfs(inf[j]);
}
}
int ans = n - in;
if( ans > mx){
mx = ans;
id = inf[i];
}
}
cout << mx << " " << id << '\n';
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int t; cin >> t;
while(t--)
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Ci8vI2luY2x1ZGUgPGV4dC9wYl9kcy9hc3NvY19jb250YWluZXIuaHBwPiAvLyBDb21tb24gZmlsZQovLyNpbmNsdWRlIDxleHQvcGJfZHMvdHJlZV9wb2xpY3kuaHBwPiAvLyBJbmNsdWRpbmcgdHJlZV9vcmRlcl9zdGF0aXN0aWNzX25vZGVfdXBkYXRlCgp1c2luZyBuY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0uZW1wbGFjZV9iYWNrKHkpOwogICAgICAgIGdbeV0uZW1wbGFjZV9iYWNrKHgpOwogICAgfQogICAgLy9zdGFydCBieSByZW1vdmluZyBldmVyeSBub2RlCiAgICBzb3J0KGluZi5iZWdpbigpLCBpbmYuZW5kKCkpOwogICAgaW50IG14ID0gMDsKICAgIGludCBpZCA9IDA7CiAgICB2aXMgPSB2ZWN0b3I8Ym9vbD4obiArIDEsIGZhbHNlKTsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCB4OyArK2kpewogICAgICAgIGluID0gMTsKICAgICAgICByZW0gPSBpbmZbaV07CiAgICAgICAgZmlsbCh2aXMuYmVnaW4oKSwgdmlzLmVuZCgpLCBmYWxzZSk7CiAgICAgICAgZm9yKGludCBqID0gMDsgaiA8IHg7ICsrail7CiAgICAgICAgICAgIGlmKGogPT0gaSkgY29udGludWU7CiAgICAgICAgICAgIGlmKCF2aXNbaW5mW2pdXSl7CiAgICAgICAgICAgICAgICBkZnMoaW5mW2pdKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpbnQgYW5zID0gbiAtIGluOwogICAgICAgIGlmKCBhbnMgPiBteCl7CiAgICAgICAgICAgIG14ID0gYW5zOwogICAgICAgICAgICBpZCA9IGluZltpXTsKICAgICAgICB9CiAgICB9CiAgICBjb3V0IDw8IG14IDw8ICIgIiA8PCBpZCA8PCAnXG4nOwogICAgCn0gICAKCmludDMyX3QgbWFpbigpewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7Y2luLnRpZShudWxscHRyKTtjb3V0LnRpZShudWxscHRyKTsgCiAgICBpbnQgdDsgY2luID4+IHQ7CiAgICB3aGlsZSh0LS0pCiAgICAgICAgc29sdmUoKTsKICAgIHJldHVybiAwOwp9