#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
#define int long long
#define pb push_back
#define endl '\n'
struct node {
int x, id;
bool operator <(const node &a) const {
return x < a.x;
}
};
void solve() {
int n, m, k;
cin >> n >> m >> k;
map<int, int>mp;
for(int i = 1; i <= n; i++) {
int x;
cin >> x;
mp[x]++;
}
vector<node>sum(k + 1);
for(int i = 1; i <= k; i++) {
sum[i].id = i;
}
int ans = 0;
vector<vector<int>> e(k + 1);
vector<int> uu(m + 1), vv(m + 1);
map<PII, int>mpp;
for(int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
uu[i] = u;
vv[i] = v;
if(mp[u] && mp[v]) ans++;
else if(mp[u]) {
sum[v].x++;
}
else if(mp[v]) {
sum[u].x++;
}
else {
mpp[{u, v}]++;
mpp[{v, u}]++;
e[u].push_back(v);
e[v].push_back(u);
}
}
int sum1 = 0;
for(int i = 1; i <= m; i++) {
int u = uu[i], v = vv[i];
if(mp[u] && mp[v])continue;
if(u == v)continue;
/*else if(mp[u])
{
if(k!=v)
sum1 = max(sum1,sum[v].x+sum[k].x);
else
sum1 = max(sum1,sum[v].x+sum[k-1].x);
}
else if(mp[v])
{
if(k!=u)
sum1 = max(sum1,sum[u].x+sum[k].x);
else
sum1 = max(sum1,sum[u].x+sum[k-1].x);
}
else*/
sum1 = max(sum1, sum[u].x + sum[v].x + mpp[{u, v}]);
}
sort(sum.begin() + 1, sum.end());
sum1 = max(sum1, sum[k].x + sum[k - 1].x + mpp[{sum[k].id, sum[k - 1].id}]);
cout << min(m, ans + sum1) <<endl;
}
#undef int
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
cin >> t;
while(t--) {
solve();
}
return 0;
}