#include <bits/stdc++.h>
using namespace std;
vector <vector <int>> g;
vector <bool> vis;
vector <bool> blockcvor;
void dfs (int node)
{
    vis[node]=true;
    for (auto i: g[node])
    {
        if (!vis[i] && !blockcvor[i])
        {
            dfs(i);
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t; cin>>t;
    while (t--)
    {
        int n, m, s;
        cin>>n>>m>>s;
        blockcvor.assign(n, false);
        for (int i=0; i<s; i++)
        {
            int x; cin>>x;
            x--;
            blockcvor[x]=true;
        }
        g.resize(n);
        while (m--)
        {
            int a, b;
            cin>>a>>b;
            a--; b--;
            g[a].push_back(b);
            g[b].push_back(a);
        }
        vis.resize(n, false);
        dfs(0);
        bool valid=true;
        for (int i=0; i<n; i++)
        {
            if (!blockcvor[i] && !vis[i])
            {
                valid=false;
            }
        }
        if (!valid) cout<<-1<<endl;
        else
        {
            cout<<n-1<<endl;
            
        }
    }
    return 0;
}