#include <bits/stdc++.h>
using namespace std;
int t;
int n, m, a, b, c;
int p[200001];
vector<vector<int> > adj;
int adist[200001], bdist[200001], cdist[200001];
void dobfs(int start, int *dist) {
  dist[start] = 0;
  queue<int> bfs;
  bfs.push(start);
  while (!bfs.empty()) {
    int cur = bfs.front();
    bfs.pop();
    for (int i = 0; i < adj[cur].size(); ++i) {
      int next = adj[cur][i];
      if (dist[next] == -1) {
        dist[next] = dist[cur] + 1;
        bfs.push(next);
      }
    }
  }
}
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> m >> a >> b >> c;
    adj = vector<vector<int> >(n);
    memset(adist, -1, sizeof(adist));
    memset(bdist, -1, sizeof(bdist));
    memset(cdist, -1, sizeof(cdist));
    --a;
    --b;
    --c;
    for (int i = 0; i < m; ++i) {
      cin >> p[i];
    }
    for (int i = 0; i < m; ++i) {
      int u, v;
      cin >> u >> v;
      --u;
      --v;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    sort(p, p + m);
    vector<long long> psum(m + 1, 0);
    for (int i = 1; i <= m; ++i) {
      psum[i] = p[i - 1] + psum[i - 1];
    }
    dobfs(a, adist);
    dobfs(b, bdist);
    dobfs(c, cdist);
    long long ans = 1e18;
    for (int i = 0; i < n; ++i) {
      if (adist[i] + bdist[i] + cdist[i] <= m) {
        long long curdist =
            psum[adist[i] + bdist[i] + cdist[i]] + psum[bdist[i]];
        ans = min(ans, curdist);
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
