#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ull long long
#define PII pair<int ,int>
const int INF = 0x3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
int fp(int a, int x, int mod) {
int ans = 1;
while (x) {
if (x & 1)ans *= a;
ans %= mod;
a *= a;
a %= mod;
x >>= 1;
}
return ans;
}
struct ff
{
int w, i, nxt;
bool operator<(const ff a) {
if (w != a.w)return w < a.w;
else return nxt < a.nxt;
}
};
priority_queue<ff>q;
bool fr[N];
int cnt[N];
int cntt[N];
map<PII,int>po;
int id[N];
vector<int>no_f;
bool cmp(int a, int b) {
if (cnt[a] != cnt[b])return cnt[a] > cnt[b];
else return fr[a] < fr[b];
}
void solve() {
int n, m, k;
cin >> n >> m >> k;
int now=0;
for (int i = 1; i <= k+5; i++) {
id[i] = i;
cnt[i] = 0;
cntt[i] = 0;
fr[i] = 0;
}
po.clear();
no_f.clear();
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
fr[a] = 1;
}
for (int i = 1; i <= k; i++) {
if (!fr[i])no_f.push_back(i);
}
for (int i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;
po[{ a,b }]++;
po[{ b,a }]++;
if (fr[a] && fr[b])now++;
else if (fr[a]) {
cnt[b]++;
cntt[b]++;
}
else if (fr[b]) {
cnt[b]++;
cntt[a]++;
}
else if (a == b) {
cnt[a]++;
cntt[a]++;
}
else {
cnt[a]++;
cnt[b]++;
}
}
sort(no_f.begin(), no_f.end(), cmp);
int pp = k - n;
if (pp == 0||now==m) {
cout << now << endl;
return;
}
int ans = 0;
if (pp == 1) {
cout << now + cntt[no_f[0]] << endl;
return;
}
for (int i = 0; i < min(int(no_f.size()),100000LL); i++) {
int it = no_f[i];
for (int j = i+1; j < min(int(no_f.size()), 100000LL); j++) {
int jt = no_f[j];
int res = cntt[it] + cntt[jt];
if (po.count({ it,jt }))res += po[{it, jt}];
ans = max(res, ans);
}
}
cout << ans + now << endl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
/*
5
4 12 7
5 7 3 6
3 6
2 2
1 4
2 4
1 3
7 6
4 1
5 4
1 1
1 1
2 1
3 7
2 7 6
2 4
1 2
3 2
2 5
5 4
2 6
4 6
2 6
1 1 2
1
1 2
2 1 2
1 2
1 2
2 1 100
24 11
11 24
*/