#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  for (long long tt = 0; tt < t; tt++) {
    long long N;
    long long B;
    long long a, b, c;
    cin >> N >> B >> a >> b >> c;
    vector<long long> p(B, 0);
    for (long long i = 0; i < B; i++) cin >> p.at(i);
    vector<vector<long long>> bridge(B, vector<long long>(2));
    for (long long i = 0; i < B; i++) {
      for (long long j = 0; j < 2; j++) {
        cin >> bridge.at(i).at(j);
      }
    }
    struct Node {
      vector<long long> to_node;
      bool fix;
    };
    vector<Node> node(N + 1);
    for (long long i = 0; i < B; i++) {
      long long F = bridge.at(i).at(0);
      long long T = bridge.at(i).at(1);
      node.at(F).to_node.push_back(T);
      node.at(T).to_node.push_back(F);
    }
    for (long long i = 0; i < node.size(); i++) {
      node.at(i).fix = false;
    }
    vector<long long> cost(N + 1, (1 << 30));
    long long StartNode = a;
    cost.at(StartNode) = 0;
    priority_queue<vector<long long>, vector<vector<long long>>,
                   greater<vector<long long>>>
        q;
    q.push({cost.at(StartNode), StartNode});
    while (!q.empty()) {
      long long c = q.top().at(0);
      long long ii = q.top().at(1);
      q.pop();
      if (node.at(ii).fix) continue;
      node.at(ii).fix = true;
      for (long long i = 0; i < node.at(ii).to_node.size(); i++) {
        long long o_node = node.at(ii).to_node.at(i);
        long long o_cost = c + 1;
        if (o_cost >= cost.at(o_node)) continue;
        cost.at(o_node) = o_cost;
        q.push({o_cost, o_node});
      }
    }
    vector<long long> costA(N + 1, (1 << 30));
    swap(cost, costA);
    for (long long i = 0; i < node.size(); i++) {
      node.at(i).fix = false;
    }
    StartNode = b;
    cost.at(StartNode) = 0;
    while (!q.empty()) q.pop();
    q.push({cost.at(StartNode), StartNode});
    while (!q.empty()) {
      long long c = q.top().at(0);
      long long ii = q.top().at(1);
      q.pop();
      if (node.at(ii).fix) continue;
      node.at(ii).fix = true;
      for (long long i = 0; i < node.at(ii).to_node.size(); i++) {
        long long o_node = node.at(ii).to_node.at(i);
        long long o_cost = c + 1;
        if (o_cost >= cost.at(o_node)) continue;
        cost.at(o_node) = o_cost;
        q.push({o_cost, o_node});
      }
    }
    vector<long long> costB(N + 1, (1 << 30));
    swap(cost, costB);
    for (long long i = 0; i < node.size(); i++) {
      node.at(i).fix = false;
    }
    StartNode = c;
    cost.at(StartNode) = 0;
    while (!q.empty()) q.pop();
    q.push({cost.at(StartNode), StartNode});
    while (!q.empty()) {
      long long c = q.top().at(0);
      long long ii = q.top().at(1);
      q.pop();
      if (node.at(ii).fix) continue;
      node.at(ii).fix = true;
      for (long long i = 0; i < node.at(ii).to_node.size(); i++) {
        long long o_node = node.at(ii).to_node.at(i);
        long long o_cost = c + 1;
        if (o_cost >= cost.at(o_node)) continue;
        cost.at(o_node) = o_cost;
        q.push({o_cost, o_node});
      }
    }
    vector<long long> costC(N + 1, (1 << 30));
    swap(cost, costC);
    sort(p.begin(), p.end());
    vector<long long> pp(B + 1, 0);
    for (long long i = 1; i <= B; i++) pp.at(i) = pp.at(i - 1) + p.at(i - 1);
    long long S = pp.back() * 2;
    for (long long i = 1; i <= N; i++) {
      long long BB = costA.at(i) + costB.at(i) + costC.at(i);
      if (BB > B) continue;
      long long SS = pp.at(BB);
      SS += pp.at(costB.at(i));
      S = min(S, SS);
    }
    cout << S << endl;
  }
  return 0;
}
