#include <bits/stdc++.h>
using namespace std;
long long N, E, Q, R;
long long BBFS(unordered_set<long long> adj[], bitset<50001> nK, int start) {
  queue<long long> thebfs;
  bitset<50001> vsted;
  long long temp = 1;
  thebfs.push(start);
  vsted[start] = 1;
  while (!thebfs.empty()) {
    long long curr = thebfs.front();
    thebfs.pop();
    for (auto i : adj[curr]) {
      if (!vsted[i] && (nK[i])) {
        vsted[i] = 1;
        temp++;
        thebfs.push(i);
      }
    }
  }
  return temp;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    cin >> N >> E >> Q >> R;
    unordered_set<long long> adjList[50001];
    bitset<50001> nodeKhusus;
    vector<long long> nK;
    vector<pair<long long, long long>> edgeL;
    for (long long i = 1; i <= E; i++) {
      long long Ai, Bi;
      cin >> Ai >> Bi;
      adjList[Ai].insert(Bi);
      adjList[Bi].insert(Ai);
      edgeL.push_back(make_pair(Ai, Bi));
    }
    for (long long i = 1; i <= Q; i++) {
      long long NK;
      cin >> NK;
      nK.push_back(NK);
      nodeKhusus[NK] = 1;
    }
    for (long long i = 1; i <= R; i++) {
      long long noEdge;
      cin >> noEdge;
      adjList[edgeL[noEdge - 1].first].erase(edgeL[noEdge - 1].second);
      adjList[edgeL[noEdge - 1].second].erase(edgeL[noEdge - 1].first);
    }
    long long result = 0;
    if (Q <= 1)
      result = 0;
    else {
      for (long long i = 1; (i <= 50000) && (!nK.empty()); i++) {
        if (nodeKhusus[i]) {
          long long hsl = BBFS(adjList, nodeKhusus, i);
          for (long long j = 1; j <= hsl; j++) {
            nodeKhusus[nK[0]] = 0;
            nK.erase(nK.begin());
          }
          result += nK.size() * hsl;
        }
      }
    }
    cout << result << '\n';
  }
}
