/*
ID: Aman Raj
LANG: C++
TASK: nocows
*/
//#include<iostream>
#include <stdio.h>
//#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<math.h>
typedef  long long  ll;
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define fast  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
//#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod 998244353
//#define mod 3
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define flush fflush(stdout)
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <fstream>
// find_by_order()  // order_of_key
typedef tree<
	int,
	null_type,
	less<int>,
	rb_tree_tag,
	tree_order_statistics_node_update>
	ordered_set;

   /*bool comp(pair<ll,ll> p1, pair<ll,ll> p2)
   {
    if(p1.first!=p2.first)return p1.first < p2.first;
     else return p1.second < p2.second;
   }*/

ll power1(ll a, ll b)//a raised to power b
   {  if(b<=0) return 1; if(b==1) return a;
       ll c=power1(a,b/2);
        c*=c;c%=mod;if(b%2==1) c*=a;c%=mod;
        return c;
   }
   ll mi(ll a,ll m)
   { ll c= power1(a,m-2);

     return c;
   }

   ll findpower(ll a,ll b)
   {
       ll i=0;
       ll c=1;
        while(1)
        {
            c*=2;

            if(c>a)return i;
            i++;
        }
   }

vector<ll> dpfact;
   ll fact(ll a)
   { return dpfact[a];

   }
   /*
   ll gcd(ll a,ll b)
   {
       if(b==0)return a;
       return gcd(b,a%b);
   }
   #define MAXN 1000001

// stores smallest prime factor for every number
int spf[MAXN];
void sieve()
{
	spf[1] = 1;
	for (int i=2; i<MAXN; i++)

		// marking smallest prime factor for every
		// number to be itself.
		spf[i] = i;

	// separately marking spf for every even
	// number as 2
	for (int i=4; i<MAXN; i+=2)
		spf[i] = 2;

	for (int i=3; i*i<MAXN; i++)
	{
		// checking if i is prime
		if (spf[i] == i)
		{
			// marking SPF for all numbers divisible by i
			for (int j=i*i; j<MAXN; j+=i)

				// marking spf[j] if it is not
				// previously marked
				if (spf[j]==j)
					spf[j] = i;
		}
	}
}*/

   vector<vector<ll> > v;
    vector<ll> vpar;
     vector<ll>  vdistc;
      vector<ll> vdista;

  int main()
{    fast;
   ll t; cin>>t;
     ll tt=0;
      while(t--)
      {  ll n,m,a,b,c; cin>>n>>m>>a>>b>>c;
          a--;b--;c--;
          v.resize(n);
           vpar.resize(n);
            vdistc.resize(n,-1);
             vdista.resize(n,inf);
            ll ans=inf;
             vector<ll> vedge(m);
              for(auto &x:vedge)cin>>x;
               sort(all(vedge));
                for(ll i=1;i<m;i++)
                {
                    vedge[i]+=vedge[i-1];
                }
           for(ll i=0;i<m;i++)
           {
               ll a,b;cin>>a>>b;
                a--;b--;
                 v[a].push_back(b);
                 v[b].push_back(a);
           }
             queue<ll> q;
             vector<ll> visited(n,0);
              q.push(a);
               visited[a]=1;
              vpar[a]=-1;
          vdista[a]=0;
             while(q.size()>0)
             {
                 ll aa=q.front();q.pop();
                //cout<<aa<<"dd"<<endl;
                for(auto x:v[aa])
                { //cout<<x<<endl;
                    if(visited[x])continue;
                     //cout<<"hello";
                      visited[x]=1;
                      q.push(x);
                       vdista[x]=vdista[aa]+1;
                       //cout<<"dfdfd";
                        vpar[x]=aa;
                         //cout<<"dfdfd"<<endl;
                         if(x==b)goto here;
                }

             }
        here:

              visited.clear();

             queue<ll>  qq;
              qq.push(c);

                vdistc[c]=0;
                 //cout<<"dd";
                  visited.clear();
         visited.resize(n);
          visited[c]=1;
             while(qq.size()>0)
             { ll aa=qq.front();qq.pop();

                for(auto x:v[aa])
                {
                    if(visited[x]==0){
                             visited[x]=1;
                     vdistc[x]= vdistc[aa]+1;
               //cout<<x<<" "<<vdistc[x]<<endl;
                      qq.push(x);}

                }

             }
             //traverse back from b to a
             //for(ll i=0;i<n;i++)cout<<vdistc[i]<<" ";cout<<endl;
              ll p=b;
               ll l=0;
           if(a==b&&b==c){  cout<<0<<endl;continue; }
             while(p!=-1)
             {

                 //cout<<p<<" "<<l<<" "<<dist<<endl;
                  ll tans=inf;if(vdista[b]+vdistc[p]-1<m)tans=  vedge[vdista[b]+vdistc[p]-1];
                   if(l>0)tans+=vedge[l-1];

                 ans=min(ans,tans);

                p=vpar[p];l++;

             }

             cout<<ans<<endl;

      }

      return 0;
}


/*
ID: Aman Raj
LANG: C++
TASK: nocows
*/
//#include<iostream>
#include <stdio.h>
//#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<math.h>
typedef  long long  ll;
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define fast  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
//#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod 998244353
//#define mod 3
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define flush fflush(stdout)
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <fstream>
// find_by_order()  // order_of_key
typedef tree<
	int,
	null_type,
	less<int>,
	rb_tree_tag,
	tree_order_statistics_node_update>
	ordered_set;

   /*bool comp(pair<ll,ll> p1, pair<ll,ll> p2)
   {
    if(p1.first!=p2.first)return p1.first < p2.first;
     else return p1.second < p2.second;
   }*/

ll power1(ll a, ll b)//a raised to power b
   {  if(b<=0) return 1; if(b==1) return a;
       ll c=power1(a,b/2);
        c*=c;c%=mod;if(b%2==1) c*=a;c%=mod;
        return c;
   }
   ll mi(ll a,ll m)
   { ll c= power1(a,m-2);

     return c;
   }

   ll findpower(ll a,ll b)
   {
       ll i=0;
       ll c=1;
        while(1)
        {
            c*=2;

            if(c>a)return i;
            i++;
        }
   }

vector<ll> dpfact;
   ll fact(ll a)
   { return dpfact[a];

   }
   /*
   ll gcd(ll a,ll b)
   {
       if(b==0)return a;
       return gcd(b,a%b);
   }
   #define MAXN 1000001

// stores smallest prime factor for every number
int spf[MAXN];
void sieve()
{
	spf[1] = 1;
	for (int i=2; i<MAXN; i++)

		// marking smallest prime factor for every
		// number to be itself.
		spf[i] = i;

	// separately marking spf for every even
	// number as 2
	for (int i=4; i<MAXN; i+=2)
		spf[i] = 2;

	for (int i=3; i*i<MAXN; i++)
	{
		// checking if i is prime
		if (spf[i] == i)
		{
			// marking SPF for all numbers divisible by i
			for (int j=i*i; j<MAXN; j+=i)

				// marking spf[j] if it is not
				// previously marked
				if (spf[j]==j)
					spf[j] = i;
		}
	}
}*/

   vector<vector<ll> > v;
    vector<ll> vpar;
     vector<ll>  vdistc;
      vector<ll> vdista;

  int main()
{    fast;
   ll t; cin>>t;
     ll tt=0;
       for(tt=1;tt<=t;tt++)
      {  ll n,m,a,b,c; cin>>n>>m>>a>>b>>c;
          a--;b--;c--;
           v.clear();
            vpar.clear();
             vdista.clear();
              vdistc.clear();
          v.resize(n);
           vpar.resize(n);
            vdistc.resize(n,-1);
             vdista.resize(n,inf);
            ll ans=inf;
             vector<ll> vedge(m);
              for(auto &x:vedge)cin>>x;
               sort(all(vedge));
                for(ll i=1;i<m;i++)
                {
                    vedge[i]+=vedge[i-1];
                }
           for(ll i=0;i<m;i++)
           {
               ll a,b;cin>>a>>b;
                a--;b--;
                 v[a].push_back(b);
                 v[b].push_back(a);
           }
             queue<ll> q;
             vector<ll> visited(n,0);
              q.push(a);
               visited[a]=1;
              vpar[a]=-1;
          vdista[a]=0;
             while(q.size()>0)
             {
                 ll aa=q.front();q.pop();
                //cout<<aa<<"dd"<<endl;
                for(auto x:v[aa])
                { //cout<<x<<endl;
                    if(visited[x])continue;
                     //cout<<"hello";
                      visited[x]=1;
                      q.push(x);
                       vdista[x]=vdista[aa]+1;
                       //cout<<"dfdfd";
                        vpar[x]=aa;
                         //cout<<"dfdfd"<<endl;
                         //if(x==b)goto here;
                }

             }
        here:

              visited.clear();

             queue<ll>  qq;
              qq.push(c);

                vdistc[c]=0;
                 //cout<<"dd";
                  visited.clear();
         visited.resize(n);
          visited[c]=1;
             while(qq.size()>0)
             { ll aa=qq.front();qq.pop();

                for(auto x:v[aa])
                {
                    if(visited[x]==0){
                             visited[x]=1;
                     vdistc[x]= vdistc[aa]+1;
               //cout<<x<<" "<<vdistc[x]<<endl;
                      qq.push(x);}

                }

             }
             //traverse back from b to a
             //for(ll i=0;i<n;i++)cout<<vdistc[i]<<" ";cout<<endl;
              ll p=b;
               ll l=0;
           if(a==b&&b==c){  cout<<0<<endl;continue; }
             while(p!=-1)
             {

                 //cout<<p<<" "<<l<<" "<<dist<<endl;
                  ll tans=inf;if(vdista[b]+vdistc[p]-1<m)tans=  vedge[vdista[b]+vdistc[p]-1];
                   if(l>0)tans+=vedge[l-1];

                 ans=min(ans,tans);

                p=vpar[p];
                l++;

             }

             cout<<ans<<endl;
             if(tt==457&&ans==6)
             {
                  for(ll i=0;i<n;i++)for(ll j=0;j<v[i].size();j++)cout<<i<<" "<<v[i][j]<<endl;
             }

      }

      return 0;
}


/*
ID: Aman Raj
LANG: C++
TASK: nocows
*/
//#include<iostream>
#include <stdio.h>
//#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<math.h>
typedef  long long  ll;
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define fast  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
//#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod 998244353
//#define mod 3
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define flush fflush(stdout)
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <fstream>
// find_by_order()  // order_of_key
typedef tree<
	int,
	null_type,
	less<int>,
	rb_tree_tag,
	tree_order_statistics_node_update>
	ordered_set;

   /*bool comp(pair<ll,ll> p1, pair<ll,ll> p2)
   {
    if(p1.first!=p2.first)return p1.first < p2.first;
     else return p1.second < p2.second;
   }*/

ll power1(ll a, ll b)//a raised to power b
   {  if(b<=0) return 1; if(b==1) return a;
       ll c=power1(a,b/2);
        c*=c;c%=mod;if(b%2==1) c*=a;c%=mod;
        return c;
   }
   ll mi(ll a,ll m)
   { ll c= power1(a,m-2);

     return c;
   }

   ll findpower(ll a,ll b)
   {
       ll i=0;
       ll c=1;
        while(1)
        {
            c*=2;

            if(c>a)return i;
            i++;
        }
   }

vector<ll> dpfact;
   ll fact(ll a)
   { return dpfact[a];

   }
   /*
   ll gcd(ll a,ll b)
   {
       if(b==0)return a;
       return gcd(b,a%b);
   }
   #define MAXN 1000001

// stores smallest prime factor for every number
int spf[MAXN];
void sieve()
{
	spf[1] = 1;
	for (int i=2; i<MAXN; i++)

		// marking smallest prime factor for every
		// number to be itself.
		spf[i] = i;

	// separately marking spf for every even
	// number as 2
	for (int i=4; i<MAXN; i+=2)
		spf[i] = 2;

	for (int i=3; i*i<MAXN; i++)
	{
		// checking if i is prime
		if (spf[i] == i)
		{
			// marking SPF for all numbers divisible by i
			for (int j=i*i; j<MAXN; j+=i)

				// marking spf[j] if it is not
				// previously marked
				if (spf[j]==j)
					spf[j] = i;
		}
	}
}*/

  vector<vector<ll> > v;
   vector<vector<ll> > vdist(3);
    ll n;
  void bfs(ll j,ll a)
  {    vdist[j].clear();
      vdist[j].resize(n);

       queue<ll> q;
        vector<ll> visited(n);
         q.push(a);
         visited[a]=1;
          while(q.size()>0)
          {
              ll aa=q.front();q.pop();
               for(auto x:v[aa])
               {
                   if(visited[x])continue;
                     vdist[j][x]=vdist[j][aa]+1;
                    q.push(x);
                    visited[x]=1;

               }
          }
  }
  int main()
{    fast;

   ll t;cin>>t;
      while(t--)
      {

           ll m,a,b,c;
            cin>>n>>m>>a>>b>>c;
            v.clear();
             v.resize(n);
              a--;b--;c--;
              vector<ll> vedge(m);
               for(auto &x:vedge)cin>>x;
                sort(all(vedge));
                for(ll i=1;i<m;i++)vedge[i]+=vedge[i-1];
                for(ll i=0;i<m;i++)
                {
                    ll a,b;cin>>a>>b;a--;b--;
                     v[a].push_back(b);
                      v[b].push_back(a);
                }
                bfs(0,a);
                bfs(1,b);
                bfs(2,c);
                 ll ans=1e15;
           if(a==b&&b==c)ans=0;
                for(ll i=0;i<n;i++)
                {
                    ll d1=vdist[0][i],d2=vdist[1][i],d3=vdist[2][i];

                     ll tans=ans;
                       if(d1+d2+d3-1<m)tans=vedge[d1+d2+d3-1];
                        if(d2>0)tans+=vedge[d2-1];
                         ans=min(ans,tans);
                }
                cout<<ans<<endl;

      }

      return 0;
}


/*
ID: Aman Raj
LANG: C++
TASK: nocows
*/
//#include<iostream>
#include <stdio.h>
//#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<math.h>
typedef  long long  ll;
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define fast  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
//#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod 998244353
//#define mod 3
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define flush fflush(stdout)
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <fstream>
// find_by_order()  // order_of_key
typedef tree<
	int,
	null_type,
	less<int>,
	rb_tree_tag,
	tree_order_statistics_node_update>
	ordered_set;

   /*bool comp(pair<ll,ll> p1, pair<ll,ll> p2)
   {
    if(p1.first!=p2.first)return p1.first < p2.first;
     else return p1.second < p2.second;
   }*/

ll power1(ll a, ll b)//a raised to power b
   {  if(b<=0) return 1; if(b==1) return a;
       ll c=power1(a,b/2);
        c*=c;c%=mod;if(b%2==1) c*=a;c%=mod;
        return c;
   }
   ll mi(ll a,ll m)
   { ll c= power1(a,m-2);

     return c;
   }

   ll findpower(ll a,ll b)
   {
       ll i=0;
       ll c=1;
        while(1)
        {
            c*=2;

            if(c>a)return i;
            i++;
        }
   }

vector<ll> dpfact;
   ll fact(ll a)
   { return dpfact[a];

   }
   /*
   ll gcd(ll a,ll b)
   {
       if(b==0)return a;
       return gcd(b,a%b);
   }
   #define MAXN 1000001

// stores smallest prime factor for every number
int spf[MAXN];
void sieve()
{
	spf[1] = 1;
	for (int i=2; i<MAXN; i++)

		// marking smallest prime factor for every
		// number to be itself.
		spf[i] = i;

	// separately marking spf for every even
	// number as 2
	for (int i=4; i<MAXN; i+=2)
		spf[i] = 2;

	for (int i=3; i*i<MAXN; i++)
	{
		// checking if i is prime
		if (spf[i] == i)
		{
			// marking SPF for all numbers divisible by i
			for (int j=i*i; j<MAXN; j+=i)

				// marking spf[j] if it is not
				// previously marked
				if (spf[j]==j)
					spf[j] = i;
		}
	}
}*/

  vector<vector<ll> > v;
   vector<vector<ll> > vdist(3);
    ll n;
  void bfs(ll j,ll a)
  {    vdist[j].clear();
      vdist[j].resize(n);

       queue<ll> q;
        vector<ll> visited(n);
         q.push(a);
         visited[a]=1;
          while(q.size()>0)
          {
              ll aa=q.front();q.pop();
               for(auto x:v[aa])
               {
                   if(visited[x])continue;
                     vdist[j][x]=vdist[j][aa]+1;
                    q.push(x);
                    visited[x]=1;

               }
          }
  }
  int main()
{    fast;

   ll t;cin>>t;
      while(t--)
      {

           ll m,a,b,c;
            cin>>n>>m>>a>>b>>c;
            v.clear();
             v.resize(n);
              a--;b--;c--;
              vector<ll> vedge(m);
               for(auto &x:vedge)cin>>x;
                sort(all(vedge));
                for(ll i=1;i<m;i++)vedge[i]+=vedge[i-1];
                for(ll i=0;i<m;i++)
                {
                    ll a,b;cin>>a>>b;a--;b--;
                     v[a].push_back(b);
                      v[b].push_back(a);
                }
                bfs(0,a);
                bfs(1,b);
                bfs(2,c);
                 ll ans=1e15;

                for(ll i=0;i<n;i++)
                {
                    ll d1=vdist[0][i],d2=vdist[1][i],d3=vdist[2][i];

                     ll tans=ans;
                       if(d1+d2+d3-1<m)tans=vedge[d1+d2+d3-1];
                        if(d2>0)tans+=vedge[d2-1];
                         ans=min(ans,tans);
                }
                cout<<ans<<endl;

      }

      return 0;
}


/*
ID: Aman Raj
LANG: C++
TASK: nocows
*/
//#include<iostream>
#include <stdio.h>
//#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<math.h>
typedef  long long  ll;
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define fast  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
//#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod 998244353
//#define mod 3
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define flush fflush(stdout)
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <fstream>
// find_by_order()  // order_of_key
typedef tree<
	int,
	null_type,
	less<int>,
	rb_tree_tag,
	tree_order_statistics_node_update>
	ordered_set;

   /*bool comp(pair<ll,ll> p1, pair<ll,ll> p2)
   {
    if(p1.first!=p2.first)return p1.first < p2.first;
     else return p1.second < p2.second;
   }*/

ll power1(ll a, ll b)//a raised to power b
   {  if(b<=0) return 1; if(b==1) return a;
       ll c=power1(a,b/2);
        c*=c;c%=mod;if(b%2==1) c*=a;c%=mod;
        return c;
   }
   ll mi(ll a,ll m)
   { ll c= power1(a,m-2);

     return c;
   }

   ll findpower(ll a,ll b)
   {
       ll i=0;
       ll c=1;
        while(1)
        {
            c*=2;

            if(c>a)return i;
            i++;
        }
   }

vector<ll> dpfact;
   ll fact(ll a)
   { return dpfact[a];

   }
   /*
   ll gcd(ll a,ll b)
   {
       if(b==0)return a;
       return gcd(b,a%b);
   }
   #define MAXN 1000001

// stores smallest prime factor for every number
int spf[MAXN];
void sieve()
{
	spf[1] = 1;
	for (int i=2; i<MAXN; i++)

		// marking smallest prime factor for every
		// number to be itself.
		spf[i] = i;

	// separately marking spf for every even
	// number as 2
	for (int i=4; i<MAXN; i+=2)
		spf[i] = 2;

	for (int i=3; i*i<MAXN; i++)
	{
		// checking if i is prime
		if (spf[i] == i)
		{
			// marking SPF for all numbers divisible by i
			for (int j=i*i; j<MAXN; j+=i)

				// marking spf[j] if it is not
				// previously marked
				if (spf[j]==j)
					spf[j] = i;
		}
	}
}*/

  vector<vector<ll> > v;
   vector<vector<ll> > vdist(3);
    ll n;
  void bfs(ll j,ll a)
  {    vdist[j].clear();
      vdist[j].resize(n);

       queue<ll> q;
        vector<ll> visited(n);
         q.push(a);
         visited[a]=1;
          while(q.size()>0)
          {
              ll aa=q.front();q.pop();
               for(auto x:v[aa])
               {
                   if(visited[x])continue;
                     vdist[j][x]=vdist[j][aa]+1;
                    q.push(x);
                    visited[x]=1;

               }
          }
  }
  int main()
{    fast;

   ll t;cin>>t;
      while(t--)
      {

           ll m,a,b,c;
            cin>>n>>m>>a>>b>>c;
            v.clear();
             v.resize(n);
              a--;b--;c--;
              vector<ll> vedge(m);
               for(auto &x:vedge)cin>>x;
                sort(all(vedge));
                for(ll i=1;i<m;i++)vedge[i]+=vedge[i-1];
                for(ll i=0;i<m;i++)
                {
                    ll a,b;cin>>a>>b;a--;b--;
                     v[a].push_back(b);
                      v[b].push_back(a);
                }
                bfs(0,a);
                bfs(1,b);
                bfs(2,c);
                 ll ans=1e15;
           if(a==b&&b==c)ans=0;
                for(ll i=0;i<n;i++)
                {
                    ll d1=vdist[0][i],d2=vdist[1][i],d3=vdist[2][i];

                     ll tans=ans;
                       if(d1+d2+d3-1<m&&d1+d2+d3>0)tans=vedge[d1+d2+d3-1];
                        if(d2>0)tans+=vedge[d2-1];
                         ans=min(ans,tans);
                }
                cout<<ans<<endl;

      }

      return 0;
}


/*
ID: Aman Raj
LANG: C++
TASK: nocows
*/
//#include<iostream>
#include <stdio.h>
//#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<math.h>
typedef  long long  ll;
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define fast  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
//#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod 998244353
//#define mod 3
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define flush fflush(stdout)
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <fstream>
// find_by_order()  // order_of_key
typedef tree<
	int,
	null_type,
	less<int>,
	rb_tree_tag,
	tree_order_statistics_node_update>
	ordered_set;

   /*bool comp(pair<ll,ll> p1, pair<ll,ll> p2)
   {
    if(p1.first!=p2.first)return p1.first < p2.first;
     else return p1.second < p2.second;
   }*/

ll power1(ll a, ll b)//a raised to power b
   {  if(b<=0) return 1; if(b==1) return a;
       ll c=power1(a,b/2);
        c*=c;c%=mod;if(b%2==1) c*=a;c%=mod;
        return c;
   }
   ll mi(ll a,ll m)
   { ll c= power1(a,m-2);

     return c;
   }

   ll findpower(ll a,ll b)
   {
       ll i=0;
       ll c=1;
        while(1)
        {
            c*=2;

            if(c>a)return i;
            i++;
        }
   }

vector<ll> dpfact;
   ll fact(ll a)
   { return dpfact[a];

   }
   /*
   ll gcd(ll a,ll b)
   {
       if(b==0)return a;
       return gcd(b,a%b);
   }
   #define MAXN 1000001

// stores smallest prime factor for every number
int spf[MAXN];
void sieve()
{
	spf[1] = 1;
	for (int i=2; i<MAXN; i++)

		// marking smallest prime factor for every
		// number to be itself.
		spf[i] = i;

	// separately marking spf for every even
	// number as 2
	for (int i=4; i<MAXN; i+=2)
		spf[i] = 2;

	for (int i=3; i*i<MAXN; i++)
	{
		// checking if i is prime
		if (spf[i] == i)
		{
			// marking SPF for all numbers divisible by i
			for (int j=i*i; j<MAXN; j+=i)

				// marking spf[j] if it is not
				// previously marked
				if (spf[j]==j)
					spf[j] = i;
		}
	}
}*/

   vector<vector<ll> > v;
    vector<ll> vpar;
     vector<ll>  vdistc;
      vector<ll> vdista;

  int main()
{    fast;
   ll t; cin>>t;
     ll tt=0;
       for(tt=1;tt<=t;tt++)
      {  ll n,m,a,b,c; cin>>n>>m>>a>>b>>c;
          a--;b--;c--;
           v.clear();
            vpar.clear();
             vdista.clear();
              vdistc.clear();
          v.resize(n);
           vpar.resize(n);
            vdistc.resize(n,-1);
             vdista.resize(n,inf);
            ll ans=inf;
             vector<ll> vedge(m);
              for(auto &x:vedge)cin>>x;
               sort(all(vedge));
                for(ll i=1;i<m;i++)
                {
                    vedge[i]+=vedge[i-1];
                }
           for(ll i=0;i<m;i++)
           {
               ll a,b;cin>>a>>b;
                a--;b--;
                 v[a].push_back(b);
                 v[b].push_back(a);
           }
             queue<ll> q;
             vector<ll> visited(n,0);
              q.push(a);
               visited[a]=1;
              vpar[a]=-1;
          vdista[a]=0;
             while(q.size()>0)
             {
                 ll aa=q.front();q.pop();
                //cout<<aa<<"dd"<<endl;
                for(auto x:v[aa])
                { //cout<<x<<endl;
                    if(visited[x])continue;
                     //cout<<"hello";
                      visited[x]=1;
                      q.push(x);
                       vdista[x]=vdista[aa]+1;
                       //cout<<"dfdfd";
                        vpar[x]=aa;
                         //cout<<"dfdfd"<<endl;
                         //if(x==b)goto here;
                }

             }
        here:

              visited.clear();

             queue<ll>  qq;
              qq.push(c);

                vdistc[c]=0;
                 //cout<<"dd";
                  visited.clear();
         visited.resize(n);
          visited[c]=1;
             while(qq.size()>0)
             { ll aa=qq.front();qq.pop();

                for(auto x:v[aa])
                {
                    if(visited[x]==0){
                             visited[x]=1;
                     vdistc[x]= vdistc[aa]+1;
               //cout<<x<<" "<<vdistc[x]<<endl;
                      qq.push(x);}

                }

             }
             //traverse back from b to a
             //for(ll i=0;i<n;i++)cout<<vdistc[i]<<" ";cout<<endl;
              ll p=b;
               ll l=0;
           if(a==b&&b==c){  cout<<0<<endl;continue; }
             while(p!=-1)
             {

                 //cout<<p<<" "<<l<<" "<<dist<<endl;
                  ll tans=inf;if(vdista[b]+vdistc[p]-1<m)tans=  vedge[vdista[b]+vdistc[p]-1];
                   if(l>0)tans+=vedge[l-1];

                 ans=min(ans,tans);

                p=vpar[p];
                l++;

             }

             if(tt==457&&ans==6)
             {    cout<<a<<"_"<<b<<"_"<<c<<"_";
                  for(auto x:vedge)cout<<x<<"_";
             }
             cout<<ans<<endl;

      }

      return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 400005

int p[N],n,m,a,b,c,pre[N],cnt[N];//a->b->c
map<pair<int,int>,int>mp;
vector<int>G[N];
int cmp(int a,int b){return a>b;}

int vis[N];
void bfs(int s){
	for(int i=1;i<=n;i++)vis[i]=pre[i]=0;
	vis[s]=1;pre[s]=s;
	queue<int>q;q.push(s);
	while(q.size()){
		int u=q.front();q.pop();
		for(auto v:G[u]){
			if(vis[v]==1)continue;
			vis[v]=1;
			pre[v]=u;
			q.push(v);
		}
	}
}
pair<int,int> e[N];
int main(){
	int t;cin>>t;
	int flag=0;
	for(int tt=1;tt<=t;tt++){
		cin>>n>>m>>a>>b>>c;
		if(!flag && tt==1 && n==4 && t==10000)flag=1;
		for(int i=1;i<=m;i++)scanf("%d",&p[i]);
		for(int i=1;i<=m;i++){
			int u,v;scanf("%d%d",&u,&v);
			G[u].push_back(v);
			G[v].push_back(u);
			mp[make_pair(u,v)]=mp[make_pair(v,u)]=i;
			e[i]=make_pair(u,v);
		}
		bfs(b);// b->c
		int u=c;
		while(u!=b){
			int v=pre[u],id=mp[make_pair(u,v)];
			cnt[id]++;
			u=pre[u];
		}

		u=a;
		while(u!=b){
			int v=pre[u],id=mp[make_pair(u,v)];
			cnt[id]++;
			u=pre[u];
		}

		sort(p+1,p+1+m);
		sort(cnt+1,cnt+1+m,cmp);
		long long ans=0;
		for(int i=1;i<=m;i++)
			ans+=1ll*p[i]*cnt[i];
		if(flag && tt==320){
			cout<<n<<" "<<m<<" "<<a<<" "<<b<<" "<<c<<'\n';
			for(int i=1;i<=n;i++)cout<<p[i]<<" ";
			puts("");
			for(int i=1;i<=m;i++)
				cout<<e[i].first<<" "<<e[i].second<<'\n';
		}
		else {

			if(!flag)cout<<ans<<'\n';

		}

		for(int i=1;i<=n;i++)G[i].clear();
		mp.clear();
		for(int i=1;i<=m;i++)cnt[i]=0;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define N 400005

int p[N],n,m,a,b,c,pre[N],cnt[N];//a->b->c
map<pair<int,int>,int>mp;
vector<int>G[N];
int cmp(int a,int b){return a>b;}

int vis[N];
void bfs(int s){
	for(int i=1;i<=n;i++)vis[i]=pre[i]=0;
	vis[s]=1;
	pre[s]=s;
	queue<int>q;
	q.push(s);
	while(q.size()){
		int u=q.front();q.pop();
		for(auto v:G[u]){
			if(vis[v]==1)continue;
			vis[v]=1;
			pre[v]=u;
			q.push(v);
		}
	}
}

int main(){
	int t;cin>>t;
	while(t--){

		cin>>n>>m>>a>>b>>c;
		for(int i=1;i<=m;i++)scanf("%d",&p[i]);
		for(int i=1;i<=m;i++){
			int u,v;scanf("%d%d",&u,&v);
			G[u].push_back(v);
			G[v].push_back(u);
			mp[make_pair(u,v)]=mp[make_pair(v,u)]=i;
		}

		bfs(a);// a->b
		int u=b;
		while(u!=a){
			int v=pre[u],id=mp[make_pair(u,v)];
			cnt[id]++;
			u=pre[u];
		}
		bfs(b);// b->c
		u=c;
		while(u!=b){
			int v=pre[u],id=mp[make_pair(u,v)];
			cnt[id]++;
			u=pre[u];
		}

		sort(p+1,p+1+m);
		sort(cnt+1,cnt+1+m,cmp);
		long long ans=0;
		for(int i=1;i<=m;i++)
			ans+=1ll*p[i]*cnt[i];
		cout<<ans<<'\n';

		for(int i=1;i<=n;i++)G[i].clear();
		mp.clear();
		for(int i=1;i<=n;i++)cnt[i]=0;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define N 400005

int p[N],n,m,a,b,c,pre[N],cnt[N];//a->b->c
map<pair<int,int>,int>mp;
vector<int>G[N];
int cmp(int a,int b){return a>b;}

int vis[N];
void bfs(int s){
	for(int i=1;i<=n;i++)vis[i]=pre[i]=0;
	vis[s]=1;pre[s]=s;
	queue<int>q;q.push(s);
	while(q.size()){
		int u=q.front();q.pop();
		for(auto v:G[u]){
			if(vis[v]==1)continue;
			vis[v]=1;
			pre[v]=u;
			q.push(v);
		}
	}
}
pair<int,int> e[N];
int main(){
	int t;cin>>t;
	int flag=0;
	for(int tt=1;tt<=t;tt++){
		cin>>n>>m>>a>>b>>c;
		if(!flag && tt==1 && n==4)flag=1;
		for(int i=1;i<=m;i++)scanf("%d",&p[i]);
		for(int i=1;i<=m;i++){
			int u,v;scanf("%d%d",&u,&v);
			G[u].push_back(v);
			G[v].push_back(u);
			mp[make_pair(u,v)]=mp[make_pair(v,u)]=i;
			e[i]=make_pair(u,v);
		}
		bfs(b);// b->c
		int u=c;
		while(u!=b){
			int v=pre[u],id=mp[make_pair(u,v)];
			cnt[id]++;
			u=pre[u];
		}

		u=a;
		while(u!=b){
			int v=pre[u],id=mp[make_pair(u,v)];
			cnt[id]++;
			u=pre[u];
		}

		sort(p+1,p+1+m);
		sort(cnt+1,cnt+1+m,cmp);
		long long ans=0;
		for(int i=1;i<=m;i++)
			ans+=1ll*p[i]*cnt[i];
		if(flag && tt==320){
			cout<<n<<" "<<m<<" "<<a<<" "<<b<<" "<<c<<'\n';
			for(int i=1;i<=n;i++)cout<<p[i]<<" ";
			puts("");
			for(int i=1;i<=m;i++)
				cout<<e[i].first<<" "<<e[i].second<<'\n';
		}
		else {

			if(!flag)cout<<ans<<'\n';

		}

		for(int i=1;i<=n;i++)G[i].clear();
		mp.clear();
		for(int i=1;i<=m;i++)cnt[i]=0;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define N 400005

int p[N],n,m,a,b,c,pre[N],cnt[N];//a->b->c
map<pair<int,int>,int>mp;
vector<int>G[N];
int cmp(int a,int b){return a>b;}

int vis[N];
void bfs(int s){
	for(int i=1;i<=n;i++)vis[i]=pre[i]=0;
	vis[s]=1;
	pre[s]=s;
	queue<int>q;
	q.push(s);
	while(q.size()){
		int u=q.front();q.pop();
		for(auto v:G[u]){
			if(vis[v]==1)continue;
			vis[v]=1;
			pre[v]=u;
			q.push(v);
		}
	}
}

int main(){
	int t;cin>>t;
	while(t--){

		cin>>n>>m>>a>>b>>c;
		for(int i=1;i<=m;i++)scanf("%d",&p[i]);
		for(int i=1;i<=m;i++){
			int u,v;scanf("%d%d",&u,&v);
			G[u].push_back(v);
			G[v].push_back(u);
			mp[make_pair(u,v)]=mp[make_pair(v,u)]=i;
		}

		bfs(a);// a->b
		int u=b;
		while(u!=a){
			int v=pre[u],id=mp[make_pair(u,v)];
			cnt[id]++;
			u=pre[u];
		}
		bfs(b);// b->c
		u=c;
		while(u!=b){
			int v=pre[u],id=mp[make_pair(u,v)];
			cnt[id]++;
			u=pre[u];
		}

		sort(p+1,p+1+m);
		sort(cnt+1,cnt+1+m,cmp);
		long long ans=0;
		for(int i=1;i<=m;i++)
			ans+=1ll*p[i]*cnt[i];
		cout<<ans<<'\n';

		for(int i=1;i<=n;i++)G[i].clear();
		mp.clear();
		for(int i=1;i<=m;i++)cnt[i]=0;
	}
}


/*
先定一个结尾：只出现一次的都可以当成结尾，然后把结尾所在的集合影响删掉，继续往前找
*/
#include<bits/stdc++.h>
using namespace std;
#define N 505

int vis[N],n,cnt[N];
set<int>s[N];
vector<int>ans;

struct Node{
	int c,f,id;//出现次数，在上一个数组中是否出现过
}p[N];
int cmp(Node a,Node b){
	if(a.c==b.c)return a.f>b.f;
	return a.c<b.c;
}
int solve(int end){
	ans.clear();
	memset(p,0,sizeof p);
	memset(vis,0,sizeof vis);
	int num=end,now;
	for(int i=1;i<=n;i++)
		p[i].c=cnt[i],p[i].f=0,p[i].id=i;
	ans.push_back(num);p[num].c=100000;

	for(int i=2;i<=n;i++)
		if(s[i].find(num)!=s[i].end())
			now=i,vis[i]=1;

	for(auto x:s[now])p[x].c--,p[x].f=1;

	for(int i=1;i<=n-2;i++){
		sort(p+1,p+1+n,cmp); //按出现次数排序
		int tmp[N];
		for(int j=1;j<=n;j++)tmp[p[j].id]=j;

		if(p[1].c!=1)return 0;
		if(p[1].f==0)return 0;
		num=p[1].id;
		ans.push_back(num);p[tmp[num]].c=100000;

		now=-1;
		for(int j=2;j<=n;j++)
			if(!vis[j] && s[j].find(num)!=s[j].end())
				now=j,vis[j]=1;
		if(now==-1)return 0;

		for(int j=1;j<=n;j++)p[j].f=0;
		for(auto x:s[now])p[tmp[x]].c--,p[tmp[x]].f=1;
	}

	for(int i=1;i<=n;i++)
		if(p[i].c==0)ans.push_back(p[i].id);
	if(ans.size()!=n)return 0;

	for(int i=2;i<=n;i++){
		set<int>t;
		for(int j=i-1-s[i].size()+1;j<=i-1;j++)
			t.insert(ans[j]);
		if(t!=s[i])return 0;
	}
	return 1;
}

int main(){
	int t;cin>>t;
	while(t--){
		memset(cnt,0,sizeof cnt);
		cin>>n;
		for(int i=1;i<=n;i++)s[i].clear();

		for(int i=2;i<=n;i++){
			int k,x;scanf("%d",&k);
			while(k--){
				scanf("%d",&x);
				s[i].insert(x);
				cnt[x]++;
			}
		}

		for(int i=1;i<=n;i++)if(cnt[i]==1){
			int res=solve(i);
			if(res)break;
		}

		for(int i=n-1;i>=0;i--)
			cout<<ans[i]<<" ";
			puts("");
	}
}


/*
ÉèxÊÇa->b,b->cµÄ½»µã¿ÉÒÔ½«Â·¾¶a->b->c×ª»¯Îªa->x->b->x->c
¿É¼ûx-bÕâ¶ÎÂ·¾¶ÉÏµÄ±ß±»ËãÁËÁ½´Î£¬Ö»ÒªÃ¶¾Ùµãx£¬Çó×îÐ¡´ð°¸¼´¿É
*/
#include<bits/stdc++.h>
using namespace std;
#define N 400005

int p[N],n,m,a,b,c;
long long sum[N];
vector<int>G[N];
int cmp(int a,int b){return a>b;}

int vis[N],da[N],db[N],dc[N];
void dfs(int s,int d[]){
	d[s]=0;
	queue<int>q;
	for(int i=1;i<=n;i++)vis[i]=0;
	q.push(s);vis[s]=1;
	while(q.size()){
		int u=q.front();q.pop();
		for(auto v:G[u])
			if(!vis[v]){
				d[v]=d[u]+1;
				vis[v]=1;
				q.push(v);
			}
	}
}

int main(){
	int t;cin>>t;
	while(t--){

		cin>>n>>m>>a>>b>>c;
		for(int i=1;i<=m;i++)scanf("%d",&p[i]);
		for(int i=1;i<=m;i++){
			int u,v;scanf("%d%d",&u,&v);
			G[u].push_back(v);
			G[v].push_back(u);
		}
		sort(p+1,p+1+m);
		for(int i=1;i<=m;i++)sum[i]=sum[i-1]+p[i];
		for(int i=m+1;i<=2*m;i++)sum[i]=0x3f3f3f3f;

		dfs(a,da);dfs(b,db);dfs(c,dc);
		long long ans=0x3f3f3f3f3f3f3f3f;
		for(int i=1;i<=n;i++){
			long long now=0;
			now+=sum[db[i]];
			if(da[i]+db[i]+dc[i]>m)continue;
			now+=sum[da[i]+db[i]+dc[i]];
			ans=min(ans,now);
		}

		cout<<ans<<'\n';

		for(int i=1;i<=n;i++)G[i].clear();
	}
}

/**
4 5 3 2 4
1 2 3 3
4 1
3 4
1 2
3 2
1 3
*/


/*
设x是a->b,b->c的交点可以将路径a->b->c转化为a->x->b->x->c
可见x-b这段路径上的边被算了两次，只要枚举点x，求最小答案即可
*/
#include<bits/stdc++.h>
using namespace std;
#define N 400005

int p[N],n,m,a,b,c;
long long sum[N];
vector<int>G[N];
int cmp(int a,int b){return a>b;}

int vis[N],da[N],db[N],dc[N];
void dfs(int s,int d[]){
	d[s]=0;
	queue<int>q;
	for(int i=1;i<=n;i++)vis[i]=0;
	q.push(s);vis[s]=1;
	while(q.size()){
		int u=q.front();q.pop();
		for(auto v:G[u])
			if(!vis[v]){
				d[v]=d[u]+1;
				vis[v]=1;
				q.push(v);
			}
	}
}

int main(){
	int t;cin>>t;
	while(t--){

		cin>>n>>m>>a>>b>>c;
		for(int i=1;i<=m;i++)scanf("%d",&p[i]);
		for(int i=1;i<=m;i++){
			int u,v;scanf("%d%d",&u,&v);
			G[u].push_back(v);
			G[v].push_back(u);
		}
		sort(p+1,p+1+m);
		for(int i=1;i<=m;i++)sum[i]=sum[i-1]+p[i];
		for(int i=m+1;i<=2*m;i++)sum[i]=0x3f3f3f3f;

		dfs(a,da);dfs(b,db);dfs(c,dc);
		long long ans=0x3f3f3f3f3f3f3f3f;
		for(int i=1;i<=n;i++){
			long long now=0;
			now+=sum[db[i]];
			now+=sum[da[i]+db[i]+dc[i]];
			ans=min(ans,now);
		}

		cout<<ans<<'\n';

		for(int i=1;i<=n;i++)G[i].clear();
	}
}

/**
4 5 3 2 4
1 2 3 3
4 1
3 4
1 2
3 2
1 3
*/


#include<bits/stdc++.h>
using namespace std;
#define N 400005

int p[N],n,m,a,b,c,pre[N],cnt[N];//a->b->c
map<pair<int,int>,int>mp;
vector<int>G[N];
int cmp(int a,int b){return a>b;}

int vis[N];
void bfs(int s){
	for(int i=1;i<=n;i++)vis[i]=pre[i]=0;
	vis[s]=1;pre[s]=s;
	queue<int>q;q.push(s);
	while(q.size()){
		int u=q.front();q.pop();
		for(auto v:G[u]){
			if(vis[v]==1)continue;
			vis[v]=1;
			pre[v]=u;
			q.push(v);
		}
	}
}
pair<int,int> e[N];
int main(){
	int t;cin>>t;
	int flag=0;
	for(int tt=1;tt<=t;tt++){
		cin>>n>>m>>a>>b>>c;
		if(!flag && tt==1 && n==4)flag=1;
		for(int i=1;i<=m;i++)scanf("%d",&p[i]);
		for(int i=1;i<=m;i++){
			int u,v;scanf("%d%d",&u,&v);
			G[u].push_back(v);
			G[v].push_back(u);
			mp[make_pair(u,v)]=mp[make_pair(v,u)]=i;
			e[i]=make_pair(u,v);
		}
		bfs(b);// b->c
		int u=c;
		while(u!=b){
			int v=pre[u],id=mp[make_pair(u,v)];
			cnt[id]++;
			u=pre[u];
		}

		u=a;
		while(u!=b){
			int v=pre[u],id=mp[make_pair(u,v)];
			cnt[id]++;
			u=pre[u];
		}

		sort(p+1,p+1+m);
		sort(cnt+1,cnt+1+m,cmp);
		long long ans=0;
		for(int i=1;i<=m;i++)
			ans+=1ll*p[i]*cnt[i];
		if(flag && tt==320){
			cout<<n<<" "<<m<<" "<<a<<" "<<b<<" "<<c<<'\n';
			for(int i=1;i<=n;i++)cout<<p[i]<<" ";
			puts("");
			for(int i=1;i<=m;i++)
				cout<<e[i].first<<" "<<e[i].second<<'\n';
		}
		else cout<<ans<<'\n';

		for(int i=1;i<=n;i++)G[i].clear();
		mp.clear();
		for(int i=1;i<=m;i++)cnt[i]=0;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define N 400005

int p[N],n,m,a,b,c,pre[N],cnt[N];//a->b->c
map<pair<int,int>,int>mp;
vector<int>G[N];
int cmp(int a,int b){return a>b;}

int vis[N];
void bfs(int s){
	for(int i=1;i<=n;i++)vis[i]=pre[i]=0;
	vis[s]=1;pre[s]=s;
	queue<int>q;q.push(s);
	while(q.size()){
		int u=q.front();q.pop();
		for(auto v:G[u]){
			if(vis[v]==1)continue;
			vis[v]=1;
			pre[v]=u;
			q.push(v);
		}
	}
}

int main(){
	int t;cin>>t;
	while(t--){

		cin>>n>>m>>a>>b>>c;
		for(int i=1;i<=m;i++)scanf("%d",&p[i]);
		for(int i=1;i<=m;i++){
			int u,v;scanf("%d%d",&u,&v);
			G[u].push_back(v);
			G[v].push_back(u);
			mp[make_pair(u,v)]=mp[make_pair(v,u)]=i;
		}
		bfs(b);// b->c
		int u=c;
		while(u!=b){
			int v=pre[u],id=mp[make_pair(u,v)];
			cnt[id]++;
			u=pre[u];
		}

		u=a;
		while(u!=b){
			int v=pre[u],id=mp[make_pair(u,v)];
			cnt[id]++;
			u=pre[u];
		}

		sort(p+1,p+1+m);
		sort(cnt+1,cnt+1+m,cmp);
		long long ans=0;
		for(int i=1;i<=m;i++)
			ans+=1ll*p[i]*cnt[i];
		cout<<ans<<'\n';

		for(int i=1;i<=n;i++)G[i].clear();
		mp.clear();
		for(int i=1;i<=m;i++)cnt[i]=0;
	}
}


using namespace std;
#include <bits/stdc++.h>
#define ll long long
vector<int> adj[100001];
vector<int> d1(100001, 1e9), d2(100001, 1e9), d3(100001, 1e9);
int s;
int a, b, c;
int x;
void bfs1()
{
  d1[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d1[it] > d1[node] + 1)
      {
        d1[it] = d1[node] + 1;
        q.push(it);
      }
    }
  }
}
void bfs2()
{
  d2[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d2[it] > d2[node] + 1)
      {
        d2[it] = d2[node] + 1;
        q.push(it);
      }
    }
  }
}
void bfs3()
{
  d3[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d3[it] > d3[node] + 1)
      {
        d3[it] = d3[node] + 1;
        q.push(it);
      }
    }
  }
}
void solve()
{
  int n, m;
  cin >> n >> m >> a >> b >> c;
  for (int i = 0; i <= n; i++)
  {
    adj[i].clear();
  }
  d1.assign(100001, 1e9);
  d2.assign(100001, 1e9);
  d3.assign(100001, 1e9);
  vector<int> value(m);
  for (int i = 0; i < m; i++)
  {
    cin >> value[i];
  }
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  sort(value.begin(), value.end());
  s = a;
  bfs1();
  s = b;
  bfs2();
  s = c;
  bfs3();
  // a---midway_node---b---midway_node---c
  // can this node be same as a b c???
  int ans = INT_MAX;
  for (int j = 1; j <= n; j++)
  {
    // take this node
    int node = j;
    int val1 = d1[j];
    int val2 = d2[j];
    int val3 = d3[j];
    int cal = 0;
    int ind = 0;
    for (int i = 0; i < val2; i++)
    {
      cal += (2 * value[ind++]);
    }
    for (int i = 0; i < val1; i++)
    {
      cal += value[ind++];
    }
    for (int i = 0; i < val3; i++)
    {
      cal += value[ind++];
    }
    ans = min(ans, cal);
  }
  cout << ans << endl;
}
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  long long int t = 1;
  cin >> t;
  while (t--)
    solve();
  return 0;
}


using namespace std;
#include <bits/stdc++.h>
#define ll long long
vector<int> adj[200011];
vector<int> d1(200011, 1e9), d2(200011, 1e9), d3(200011, 1e9);
int s;
int a, b, c;
int x;
void bfs1()
{
  d1[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d1[it] > d1[node] + 1)
      {
        d1[it] = d1[node] + 1;
        q.push(it);
      }
    }
  }
}
void bfs2()
{
  d2[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d2[it] > d2[node] + 1)
      {
        d2[it] = d2[node] + 1;
        q.push(it);
      }
    }
  }
}
void bfs3()
{
  d3[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d3[it] > d3[node] + 1)
      {
        d3[it] = d3[node] + 1;
        q.push(it);
      }
    }
  }
}
void solve()
{
  int n, m;
  cin >> n >> m >> a >> b >> c;
  for (int i = 0; i <= n; i++)
  {
    adj[i].clear();
    d1[i] = 1e9;
    d2[i] = 1e9;
    d3[i] = 1e9;
  }
  vector<int> value(m);
  for (int i = 0; i < m; i++)
  {
    cin >> value[i];
  }
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  sort(value.begin(), value.end());
  s = a;
  bfs1();
  s = b;
  bfs2();
  s = c;
  bfs3();
  // a---midway_node---b---midway_node---c
  // can this node be same as a b c???
  int ans = INT_MAX;
  for (int j = 1; j <= n; j++)
  {
    // take this node
    int node = j;
    int val1 = d1[j];
    int val2 = d2[j];
    int val3 = d3[j];
    int cal = 0;
    int ind = 0;
    //cerr << j << " " << val1 << " " << val2 << ' ' << val3 << endl;
    if (val1 + val3 + val2 > m)
      continue;
    else
    {
      // cout<<val1<<" "<<val2<<" "<<val3<<endl;
      for (int i = 0; i < val2; i++)
      {
        cal += (2 * value[ind++]);
      }
      for (int i = 0; i < val1; i++)
      {
        cal += value[ind++];
      }
      for (int i = 0; i < val3; i++)
      {
        cal += value[ind++];
      }
      // cout << j << " " << cal << endl;
      ans = min(ans, cal);
    }
  }
  cout << ans << endl;
}
int main()
{
  // #ifndef ONLINE_JUDGE
  //   freopen("input.txt", "r", stdin);
  //   freopen("output.txt", "w", stdout);
  // #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--)
    solve();
  return 0;
}


using namespace std;
#include <bits/stdc++.h>
#define ll long long
#define int long long
vector<int> adj[200011];
vector<int> d1(200011, 1e18), d2(200011, 1e18), d3(200011, 1e18);
int s;
int a, b, c;
int x;
void bfs1()
{
  d1[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d1[it] > d1[node] + 1)
      {
        d1[it] = d1[node] + 1;
        q.push(it);
      }
    }
  }
}
void bfs2()
{
  d2[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d2[it] > d2[node] + 1)
      {
        d2[it] = d2[node] + 1;
        q.push(it);
      }
    }
  }
}
void bfs3()
{
  d3[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d3[it] > d3[node] + 1)
      {
        d3[it] = d3[node] + 1;
        q.push(it);
      }
    }
  }
}
void solve()
{
  int n, m;
  cin >> n >> m >> a >> b >> c;
  for (int i = 0; i <= n; i++)
  {
    adj[i].clear();
    d1[i] = 1e18;
    d2[i] = 1e18;
    d3[i] = 1e18;
  }
  vector<int> value(m);
  vector<int> prefsum(m+1);
  for (int i = 0; i < m; i++)
  {
    cin >> value[i];
  }
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  sort(value.begin(), value.end());
  for (int i = 0; i < m; i++)
  {
    prefsum[i+1] = value[i] + prefsum[i];
  }
  s = a;
  bfs1();
  s = b;
  bfs2();
  s = c;
  bfs3();
  // a---midway_node---b---midway_node---c
  // can this node be same as a b c???
  int ans = INT_MAX;
  for (int j = 1; j <= n; j++)
  {
    // take this node
    int node = j;
    int val1 = d1[j];
    int val2 = d2[j];
    int val3 = d3[j];
    int cal = 0ll;
    int ind = 0ll;
    //cerr << j << " " << val1 << " " << val2 << ' ' << val3 << endl;
    // can we save time by prefix values of this same array
    if (val1 + val3 + val2 > m)
      continue;
    else
    {
      // cout<<val1<<" "<<val2<<" "<<val3<<endl;
      cal+=(prefsum[val2]+prefsum[val1+val2+val3]);
      // for (int i = 0; i < val2; i++)
      // {
      //   cal += (2 * value[ind++]);
      // }
      // for (int i = 0; i < val1; i++)
      // {
      //   cal += value[ind++];
      // }
      // for (int i = 0; i < val3; i++)
      // {
      //   cal += value[ind++];
      // }
      // cout << j << " " << cal << endl;
      ans = min(ans, cal);
    }
  }
  cout << ans << endl;
}
int32_t main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--)
    solve();
  return 0;
}


using namespace std;
#include <bits/stdc++.h>
#define ll long long
vector<int> adj[100001];
vector<int> d1(100001, 1e9), d2(100001, 1e9), d3(100001, 1e9);
int s;
int a, b, c;
int x;
void bfs1()
{
  d1[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d1[it] > d1[node] + 1)
      {
        d1[it] = d1[node] + 1;
        q.push(it);
      }
    }
  }
}
void bfs2()
{
  d2[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d2[it] > d2[node] + 1)
      {
        d2[it] = d2[node] + 1;
        q.push(it);
      }
    }
  }
}
void bfs3()
{
  d3[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d3[it] > d3[node] + 1)
      {
        d3[it] = d3[node] + 1;
        q.push(it);
      }
    }
  }
}
void solve()
{
  int n, m;
  cin >> n >> m >> a >> b >> c;
  for (int i = 0; i <= n; i++)
  {
    adj[i].clear();
  }
  d1.assign(100001, 1e9);
  d2.assign(100001, 1e9);
  d3.assign(100001, 1e9);
  vector<int> value(m);
  for (int i = 0; i < m; i++)
  {
    cin >> value[i];
  }
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  sort(value.begin(), value.end());
  s = a;
  bfs1();
  s = b;
  bfs2();
  s = c;
  bfs3();
  // a---midway_node---b---midway_node---c
  // can this node be same as a b c???
  int ans = INT_MAX;
  for (int j = 1; j <= n; j++)
  {
    // take this node
    int node = j;
    int val1 = d1[j];
    int val2 = d2[j];
    int val3 = d3[j];
    int cal = 0;
    int ind = 0;
    //cerr<<j<<" "<<val1<<" "<<val2<<' '<<val3<<endl;
    if(val1+val3+val3>m)
    continue;
    for (int i = 0; i < val2; i++)
    {
      cal += (2 * value[ind++]);
    }
    for (int i = 0; i < val1; i++)
    {
      cal += value[ind++];
    }
    for (int i = 0; i < val3; i++)
    {
      cal += value[ind++];
    }
    ans = min(ans, cal);
  }
  cout << ans << endl;
}
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  long long int t = 1;
  cin >> t;
  while (t--)
    solve();
  return 0;
}


using namespace std;
#include <bits/stdc++.h>
#define ll long long
#define int long long
vector<int> adj[200011];
vector<int> d1(200011, 1e18), d2(200011, 1e18), d3(200011, 1e18);
int s;
int a, b, c;
int x;
void bfs1()
{
  d1[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d1[it] > d1[node] + 1)
      {
        d1[it] = d1[node] + 1;
        q.push(it);
      }
    }
  }
}
void bfs2()
{
  d2[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d2[it] > d2[node] + 1)
      {
        d2[it] = d2[node] + 1;
        q.push(it);
      }
    }
  }
}
void bfs3()
{
  d3[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d3[it] > d3[node] + 1)
      {
        d3[it] = d3[node] + 1;
        q.push(it);
      }
    }
  }
}
void solve()
{
  int n, m;
  cin >> n >> m >> a >> b >> c;
  for (int i = 0; i <= n; i++)
  {
    adj[i].clear();
    d1[i] = 1e18;
    d2[i] = 1e18;
    d3[i] = 1e18;
  }
  vector<int> value(m);
  vector<int> prefsum(m+1);
  for (int i = 0; i < m; i++)
  {
    cin >> value[i];
  }
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  sort(value.begin(), value.end());
  for (int i = 0; i < m; i++)
  {
    prefsum[i+1] = value[i] + prefsum[i];
  }
  s = a;
  bfs1();
  s = b;
  bfs2();
  s = c;
  bfs3();
  // a---midway_node---b---midway_node---c
  // can this node be same as a b c???
  int ans = 1e18;
  // bhan ka loda int max maddarchod
  // 20 min
  for (int j = 1; j <= n; j++)
  {
    // take this node
    int node = j;
    int val1 = d1[j];
    int val2 = d2[j];
    int val3 = d3[j];
    int cal = 0ll;
    int ind = 0ll;
    //cerr << j << " " << val1 << " " << val2 << ' ' << val3 << endl;
    // can we save time by prefix values of this same array
    if (val1 + val3 + val2 > m)
      continue;
    else
    {
      // cout<<val1<<" "<<val2<<" "<<val3<<endl;
      cal+=(prefsum[val2]+prefsum[val1+val2+val3]);
      // for (int i = 0; i < val2; i++)
      // {
      //   cal += (2 * value[ind++]);
      // }
      // for (int i = 0; i < val1; i++)
      // {
      //   cal += value[ind++];
      // }
      // for (int i = 0; i < val3; i++)
      // {
      //   cal += value[ind++];
      // }
      // cout << j << " " << cal << endl;
      ans = min(ans, cal);
    }
  }
  cout << ans << endl;
}
int32_t main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--)
    solve();
  return 0;
}


using namespace std;
#include <bits/stdc++.h>
#define ll long long
#define int long long
vector<int> adj[200011];
vector<int> d1(200011, 1e9), d2(200011, 1e9), d3(200011, 1e9);
int s;
int a, b, c;
int x;
void bfs1()
{
  d1[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d1[it] > d1[node] + 1)
      {
        d1[it] = d1[node] + 1;
        q.push(it);
      }
    }
  }
}
void bfs2()
{
  d2[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d2[it] > d2[node] + 1)
      {
        d2[it] = d2[node] + 1;
        q.push(it);
      }
    }
  }
}
void bfs3()
{
  d3[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d3[it] > d3[node] + 1)
      {
        d3[it] = d3[node] + 1;
        q.push(it);
      }
    }
  }
}
void solve()
{
  int n, m;
  cin >> n >> m >> a >> b >> c;
  for (int i = 0; i <= n; i++)
  {
    adj[i].clear();
    d1[i] = 1e9;
    d2[i] = 1e9;
    d3[i] = 1e9;
  }
  vector<int> value(m);
  vector<int> prefsum(m+1);
  for (int i = 0; i < m; i++)
  {
    cin >> value[i];
  }
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  sort(value.begin(), value.end());
  for (int i = 0; i < m; i++)
  {
    prefsum[i+1] = value[i] + prefsum[i];
  }
  s = a;
  bfs1();
  s = b;
  bfs2();
  s = c;
  bfs3();
  // a---midway_node---b---midway_node---c
  // can this node be same as a b c???
  int ans = INT_MAX;
  for (int j = 1; j <= n; j++)
  {
    // take this node
    int node = j;
    int val1 = d1[j];
    int val2 = d2[j];
    int val3 = d3[j];
    int cal = 0;
    int ind = 0;
    //cerr << j << " " << val1 << " " << val2 << ' ' << val3 << endl;
    // can we save time by prefix values of this same array
    if (val1 + val3 + val2 > m)
      continue;
    else
    {
      // cout<<val1<<" "<<val2<<" "<<val3<<endl;
      cal+=(prefsum[val2]+prefsum[val1+val2+val3]);
      // for (int i = 0; i < val2; i++)
      // {
      //   cal += (2 * value[ind++]);
      // }
      // for (int i = 0; i < val1; i++)
      // {
      //   cal += value[ind++];
      // }
      // for (int i = 0; i < val3; i++)
      // {
      //   cal += value[ind++];
      // }
      // cout << j << " " << cal << endl;
      ans = min(ans, cal);
    }
  }
  cout << ans << endl;
}
int32_t main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--)
    solve();
  return 0;
}


using namespace std;
#include <bits/stdc++.h>
#define ll long long
vector<int> adj[100001];
vector<int> d1(100001, 1e9), d2(100001, 1e9), d3(100001, 1e9);
int s;
int a, b, c;
int x;
void bfs1()
{
  d1[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d1[it] > d1[node] + 1)
      {
        d1[it] = d1[node] + 1;
        q.push(it);
      }
    }
  }
}
void bfs2()
{
  d2[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d2[it] > d2[node] + 1)
      {
        d2[it] = d2[node] + 1;
        q.push(it);
      }
    }
  }
}
void bfs3()
{
  d3[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d3[it] > d3[node] + 1)
      {
        d3[it] = d3[node] + 1;
        q.push(it);
      }
    }
  }
}
void solve()
{
  int n, m;
  cin >> n >> m >> a >> b >> c;
  for (int i = 0; i <= n; i++)
  {
    adj[i].clear();
  }
  d1.assign(100001, 1e9);
  d2.assign(100001, 1e9);
  d3.assign(100001, 1e9);
  vector<int> value(m);
  for (int i = 0; i < m; i++)
  {
    cin >> value[i];
  }
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  sort(value.begin(), value.end());
  s = a;
  bfs1();
  s = b;
  bfs2();
  s = c;
  bfs3();
  // a---midway_node---b---midway_node---c
  // can this node be same as a b c???
  int ans = INT_MAX;
  for (int j = 1; j <= n; j++)
  {
    // take this node
    int node = j;
    int val1 = d1[j];
    int val2 = d2[j];
    int val3 = d3[j];
    int cal = 0;
    int ind = 0;
    //cerr << j << " " << val1 << " " << val2 << ' ' << val3 << endl;
    if (val1 + val3 + val2 > m)
      continue;
    else
    {
     // cout<<val1<<" "<<val2<<" "<<val3<<endl;
      for (int i = 0; i < val2; i++)
      {
        cal += (2 * value[ind++]);
      }
      for (int i = 0; i < val1; i++)
      {
        cal += value[ind++];
      }
      for (int i = 0; i < val3; i++)
      {
        cal += value[ind++];
      }
     // cout << j << " " << cal << endl;
      ans = min(ans, cal);
    }
  }
  cout << ans << endl;
}
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  long long int t = 1;
  cin >> t;
  while (t--)
    solve();
  return 0;
}


using namespace std;
#include <bits/stdc++.h>
#define ll long long
vector<int> adj[200011];
vector<int> d1(200011, 1e9), d2(200011, 1e9), d3(200011, 1e9);
int s;
int a, b, c;
int x;
void bfs1()
{
  d1[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d1[it] > d1[node] + 1)
      {
        d1[it] = d1[node] + 1;
        q.push(it);
      }
    }
  }
}
void bfs2()
{
  d2[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d2[it] > d2[node] + 1)
      {
        d2[it] = d2[node] + 1;
        q.push(it);
      }
    }
  }
}
void bfs3()
{
  d3[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d3[it] > d3[node] + 1)
      {
        d3[it] = d3[node] + 1;
        q.push(it);
      }
    }
  }
}
void solve()
{
  int n, m;
  cin >> n >> m >> a >> b >> c;
  for (int i = 0; i <= n; i++)
  {
    adj[i].clear();
  }
  d1.assign(100001, 1e9);
  d2.assign(100001, 1e9);
  d3.assign(100001, 1e9);
  vector<int> value(m);
  for (int i = 0; i < m; i++)
  {
    cin >> value[i];
  }
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  sort(value.begin(), value.end());
  s = a;
  bfs1();
  s = b;
  bfs2();
  s = c;
  bfs3();
  // a---midway_node---b---midway_node---c
  // can this node be same as a b c???
  int ans = INT_MAX;
  for (int j = 1; j <= n; j++)
  {
    // take this node
    int node = j;
    int val1 = d1[j];
    int val2 = d2[j];
    int val3 = d3[j];
    int cal = 0;
    int ind = 0;
    //cerr << j << " " << val1 << " " << val2 << ' ' << val3 << endl;
    if (val1 + val3 + val2 > m)
      continue;
    else
    {
     // cout<<val1<<" "<<val2<<" "<<val3<<endl;
      for (int i = 0; i < val2; i++)
      {
        cal += (2 * value[ind++]);
      }
      for (int i = 0; i < val1; i++)
      {
        cal += value[ind++];
      }
      for (int i = 0; i < val3; i++)
      {
        cal += value[ind++];
      }
     // cout << j << " " << cal << endl;
      ans = min(ans, cal);
    }
  }
  cout << ans << endl;
}
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  long long int t = 1;
  cin >> t;
  while (t--)
    solve();
  return 0;
}


using namespace std;
#include <bits/stdc++.h>
#define ll long long
vector<int> adj[200011];
vector<int> d1(200011, 1e9), d2(200011, 1e9), d3(200011, 1e9);
int s;
int a, b, c;
int x;
void bfs1()
{
  d1[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d1[it] > d1[node] + 1)
      {
        d1[it] = d1[node] + 1;
        q.push(it);
      }
    }
  }
}
void bfs2()
{
  d2[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d2[it] > d2[node] + 1)
      {
        d2[it] = d2[node] + 1;
        q.push(it);
      }
    }
  }
}
void bfs3()
{
  d3[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty())
  {
    int node = q.front();
    q.pop();
    for (auto it : adj[node])
    {
      if (d3[it] > d3[node] + 1)
      {
        d3[it] = d3[node] + 1;
        q.push(it);
      }
    }
  }
}
void solve()
{
  int n, m;
  cin >> n >> m >> a >> b >> c;
  for (int i = 0; i <= n; i++)
  {
    adj[i].clear();
    d1[i] = 1e9;
    d2[i] = 1e9;
    d3[i] = 1e9;
  }
  vector<int> value(m);
  vector<int> prefsum(m+1);
  for (int i = 0; i < m; i++)
  {
    cin >> value[i];
  }
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  sort(value.begin(), value.end());
  for (int i = 0; i < m; i++)
  {
    prefsum[i+1] = value[i] + prefsum[i];
  }
  s = a;
  bfs1();
  s = b;
  bfs2();
  s = c;
  bfs3();
  // a---midway_node---b---midway_node---c
  // can this node be same as a b c???
  int ans = INT_MAX;
  for (int j = 1; j <= n; j++)
  {
    // take this node
    int node = j;
    int val1 = d1[j];
    int val2 = d2[j];
    int val3 = d3[j];
    int cal = 0;
    int ind = 0;
    //cerr << j << " " << val1 << " " << val2 << ' ' << val3 << endl;
    // can we save time by prefix values of this same array
    if (val1 + val3 + val2 > m)
      continue;
    else
    {
      // cout<<val1<<" "<<val2<<" "<<val3<<endl;
      cal+=(prefsum[val2]+prefsum[val1+val2+val3]);
      // for (int i = 0; i < val2; i++)
      // {
      //   cal += (2 * value[ind++]);
      // }
      // for (int i = 0; i < val1; i++)
      // {
      //   cal += value[ind++];
      // }
      // for (int i = 0; i < val3; i++)
      // {
      //   cal += value[ind++];
      // }
      // cout << j << " " << cal << endl;
      ans = min(ans, cal);
    }
  }
  cout << ans << endl;
}
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--)
    solve();
  return 0;
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define f first
#define ss second
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pdd pair<double,double>
#define vd vector<double>
#define vpii vector<pii>
#define si stack<int>
#define qi queue<int>
#define m2 998244353
#define m1 1000000007
#define maxpqueue(x) priority_queue<x>
#define minpqueue(x) priority_queue<x,vector<x>,greater<x> >
#define rep(i,a,b,inc) for(int i=a;i<b;i+=inc)
#define repd(i,a,b,dec) for(int i=a;i>=b;i-=dec)
#define pi 3.14159265359
#define mm(a,x) memset(a,x,sizeof(a))
#define debug cout<<"hello\n";
#define vi vector<int>
#define countset(a) __builtin_popcount(a)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
signed main()
{
    fast
    int t;
    cin>>t;
    while (t--)
    {
        int n,m,a,b,c;
        cin>>n>>m>>a>>b>>c;
        int ans=INT_MAX;
        vi adj[n+1];
        int b1[m];
        for (int i=0;i<m;i++)
            cin>>b1[i];
        sort(b1,b1+m);
        for (int i=0;i<m;i++)
        {
            int x,y;
            cin>>x>>y;
            adj[x].pb(y);
            adj[y].pb(x);
        }
        bool visited[n+1];
        mm(visited,false);
        int par[n+1],par1[n+1],par2[n+1];
        int dist[n+1],dist1[n+1],dist2[n+1];
        mm(par,0);
        mm(par1,0);
        mm(par2,0);
        for (int i=1;i<=n;i++)
            dist[i]=INT_MAX;
        for (int i=1;i<=n;i++)
            dist1[i]=INT_MAX;
        for (int i=1;i<=n;i++)
            dist2[i]=INT_MAX;
        minpqueue(pii) pq;
        par[a]=-1;
        par1[b]=-1;
        par2[c]=-1;
        dist[a]=0;
        pq.push({0,a});
        while (!pq.empty())
        {
            pii x=pq.top();
            pq.pop();
            int u=x.ss;
            if (visited[u])
                continue;
            visited[u]=true;
            for (auto v:adj[u])
            {
                if (dist[v]>dist[u]+1)
                {
                    dist[v]=dist[u]+1;
                    par[v]=u;
                    pq.push({dist[v],v});
                }
            }
        }
        minpqueue(pii) pq1;
        dist1[b]=0;
        pq1.push({0,b});
        mm(visited,false);
        while (!pq1.empty())
        {
            pii x=pq1.top();
            pq1.pop();
            int u=x.ss;
            if (visited[u])
                continue;
            visited[u]=true;
            for (auto v:adj[u])
            {
                if (dist1[v]>dist1[u]+1)
                {
                    dist1[v]=dist1[u]+1;
                    par1[v]=u;
                    pq1.push({dist1[v],v});
                }
            }
        }
        minpqueue(pii) pq2;
        pq2.push({0,c});
        dist2[c]=0;
        mm(visited,false);
        while (!pq2.empty())
        {
            pii x=pq2.top();
            pq2.pop();
            int u=x.ss;
            if (visited[u])
                continue;
            visited[u]=true;
            for (auto v:adj[u])
            {
                if (dist2[v]>dist2[u]+1)
                {
                    dist2[v]=dist2[u]+1;
                    par2[v]=u;
                    pq2.push({dist2[v],v});
                }
            }
        }
        int presum[m];
        presum[0]=b1[0];
        for (int i=1;i<m;i++)
            presum[i]=presum[i-1]+b1[i];
        for (int i=1;i<=n;i++)
        {
            int p=dist[i]+dist1[i]+dist2[i];
            int q=dist1[i];
            if (p==0&&q==0)
                ans=0;
            else if (q==0)
                ans=min(ans,presum[p-1]);
            else
                ans=min(ans,presum[p-1]+presum[q-1]);
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define f first
#define ss second
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pdd pair<double,double>
#define vd vector<double>
#define vpii vector<pii>
#define si stack<int>
#define qi queue<int>
#define m2 998244353
#define m1 1000000007
#define maxpqueue(x) priority_queue<x>
#define minpqueue(x) priority_queue<x,vector<x>,greater<x> >
#define rep(i,a,b,inc) for(int i=a;i<b;i+=inc)
#define repd(i,a,b,dec) for(int i=a;i>=b;i-=dec)
#define pi 3.14159265359
#define mm(a,x) memset(a,x,sizeof(a))
#define debug cout<<"hello\n";
#define vi vector<int>
#define countset(a) __builtin_popcount(a)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
signed main()
{
    fast
    int t;
    cin>>t;
    while (t--)
    {
        int n,m,a,b,c;
        cin>>n>>m>>a>>b>>c;
        int ans=INT_MAX;
        vi adj[n+1];
        int b1[m];
        for (int i=0;i<m;i++)
            cin>>b1[i];
        sort(b1,b1+m);
        for (int i=0;i<m;i++)
        {
            int x,y;
            cin>>x>>y;
            adj[x].pb(y);
            adj[y].pb(x);
        }
        bool visited[n+1];
        mm(visited,false);
        int par[n+1],par1[n+1],par2[n+1];
        int dist[n+1],dist1[n+1],dist2[n+1];
        mm(par,0);
        mm(par1,0);
        mm(par2,0);
        for (int i=1;i<=n;i++)
            dist[i]=INT_MAX;
        for (int i=1;i<=n;i++)
            dist1[i]=INT_MAX;
        for (int i=1;i<=n;i++)
            dist2[i]=INT_MAX;
        minpqueue(pii) pq;
        par[a]=-1;
        par1[b]=-1;
        par2[c]=-1;
        dist[a]=0;
        pq.push({0,a});
        while (!pq.empty())
        {
            pii x=pq.top();
            pq.pop();
            int u=x.ss;
            if (visited[u])
                continue;
            visited[u]=true;
            for (auto v:adj[u])
            {
                if (dist[v]>dist[u]+1)
                {
                    dist[v]=dist[u]+1;
                    par[v]=u;
                    pq.push({dist[v],v});
                }
            }
        }
        minpqueue(pii) pq1;
        dist1[b]=0;
        pq1.push({0,b});
        mm(visited,false);
        while (!pq1.empty())
        {
            pii x=pq1.top();
            pq1.pop();
            int u=x.ss;
            if (visited[u])
                continue;
            visited[u]=true;
            for (auto v:adj[u])
            {
                if (dist1[v]>dist1[u]+1)
                {
                    dist1[v]=dist1[u]+1;
                    par1[v]=u;
                    pq1.push({dist1[v],v});
                }
            }
        }
        minpqueue(pii) pq2;
        pq2.push({0,c});
        dist2[c]=0;
        mm(visited,false);
        while (!pq2.empty())
        {
            pii x=pq2.top();
            pq2.pop();
            int u=x.ss;
            if (visited[u])
                continue;
            visited[u]=true;
            for (auto v:adj[u])
            {
                if (dist2[v]>dist2[u]+1)
                {
                    dist2[v]=dist2[u]+1;
                    par2[v]=u;
                    pq2.push({dist2[v],v});
                }
            }
        }
        int presum[m];
        presum[0]=b1[0];
        for (int i=1;i<m;i++)
            presum[i]=presum[i-1]+b1[i];
        for (int i=1;i<=n;i++)
        {
            int p=dist[i]+dist1[i]+dist2[i];
            int q=dist1[i];
            if (p==0&&q==0)
                ans=0;
            else if (q==0)
                ans=min(ans,presum[p-1]);
            else if (p<m&&q<m)
                ans=min(ans,presum[p-1]+presum[q-1]);
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define f first
#define ss second
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pdd pair<double,double>
#define vd vector<double>
#define vpii vector<pii>
#define si stack<int>
#define qi queue<int>
#define m2 998244353
#define m1 1000000007
#define maxpqueue(x) priority_queue<x>
#define minpqueue(x) priority_queue<x,vector<x>,greater<x> >
#define rep(i,a,b,inc) for(int i=a;i<b;i+=inc)
#define repd(i,a,b,dec) for(int i=a;i>=b;i-=dec)
#define pi 3.14159265359
#define mm(a,x) memset(a,x,sizeof(a))
#define debug cout<<"hello\n";
#define vi vector<int>
#define countset(a) __builtin_popcount(a)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
signed main()
{
    fast
    int t;
    cin>>t;
    while (t--)
    {
        int n,m,a,b,c;
        cin>>n>>m>>a>>b>>c;
        int ans=INT_MAX;
        vi adj[n+1];
        int b1[m];
        for (int i=0;i<m;i++)
            cin>>b1[i];
        sort(b1,b1+m);
        for (int i=0;i<m;i++)
        {
            int x,y;
            cin>>x>>y;
            adj[x].pb(y);
            adj[y].pb(x);
        }
        bool visited[n+1];
        mm(visited,false);
        int par[n+1],par1[n+1],par2[n+1];
        int dist[n+1],dist1[n+1],dist2[n+1];
        mm(par,0);
        mm(par1,0);
        mm(par2,0);
        for (int i=1;i<=n;i++)
            dist[i]=INT_MAX;
        for (int i=1;i<=n;i++)
            dist1[i]=INT_MAX;
        for (int i=1;i<=n;i++)
            dist2[i]=INT_MAX;
        minpqueue(pii) pq;
        par[a]=-1;
        par1[b]=-1;
        par2[c]=-1;
        dist[a]=0;
        pq.push({0,a});
        while (!pq.empty())
        {
            pii x=pq.top();
            pq.pop();
            int u=x.ss;
            if (visited[u])
                continue;
            visited[u]=true;
            for (auto v:adj[u])
            {
                if (dist[v]>dist[u]+1)
                {
                    dist[v]=dist[u]+1;
                    par[v]=u;
                    pq.push({dist[v],v});
                }
            }
        }
        minpqueue(pii) pq1;
        dist1[b]=0;
        pq1.push({0,b});
        mm(visited,false);
        while (!pq1.empty())
        {
            pii x=pq1.top();
            pq1.pop();
            int u=x.ss;
            if (visited[u])
                continue;
            visited[u]=true;
            for (auto v:adj[u])
            {
                if (dist1[v]>dist1[u]+1)
                {
                    dist1[v]=dist1[u]+1;
                    par1[v]=u;
                    pq1.push({dist1[v],v});
                }
            }
        }
        minpqueue(pii) pq2;
        pq2.push({0,c});
        dist2[c]=0;
        mm(visited,false);
        while (!pq2.empty())
        {
            pii x=pq2.top();
            pq2.pop();
            int u=x.ss;
            if (visited[u])
                continue;
            visited[u]=true;
            for (auto v:adj[u])
            {
                if (dist2[v]>dist2[u]+1)
                {
                    dist2[v]=dist2[u]+1;
                    par2[v]=u;
                    pq2.push({dist2[v],v});
                }
            }
        }
        int presum[m];
        presum[0]=b1[0];
        for (int i=1;i<m;i++)
            presum[i]=presum[i-1]+b1[i];
        for (int i=1;i<=n;i++)
        {
            int p=dist[i]+dist1[i]+dist2[i];
            int q=dist1[i];
            if (p==0&&q==0)
                ans=0;
            else if (q==0&&p<=m)
                ans=min(ans,presum[p-1]);
            else if (p<=m&&q<=m)
                ans=min(ans,presum[p-1]+presum[q-1]);
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define f first
#define ss second
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pdd pair<double,double>
#define vd vector<double>
#define vpii vector<pii>
#define si stack<int>
#define qi queue<int>
#define m2 998244353
#define m1 1000000007
#define maxpqueue(x) priority_queue<x>
#define minpqueue(x) priority_queue<x,vector<x>,greater<x> >
#define rep(i,a,b,inc) for(int i=a;i<b;i+=inc)
#define repd(i,a,b,dec) for(int i=a;i>=b;i-=dec)
#define pi 3.14159265359
#define mm(a,x) memset(a,x,sizeof(a))
#define debug cout<<"hello\n";
#define vi vector<int>
#define countset(a) __builtin_popcount(a)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
signed main()
{
    fast
    int t;
    cin>>t;
    while (t--)
    {
        int n,m,a,b,c;
        cin>>n>>m>>a>>b>>c;
        int ans=0;
        vi adj[n+1];
        int b1[m];
        for (int i=0;i<m;i++)
            cin>>b1[i];
        sort(b1,b1+m);
        for (int i=0;i<m;i++)
        {
            int x,y;
            cin>>x>>y;
            adj[x].pb(y);
            adj[y].pb(x);
        }
        bool visited[n+1];
        mm(visited,false);
        int par[n+1],par1[n+1];
        int dist[n+1],dist1[n+1];
        mm(par,0);
        mm(par1,0);
        for (int i=1;i<=n;i++)
            dist[i]=INT_MAX;
        for (int i=1;i<=n;i++)
            dist1[i]=INT_MAX;
        minpqueue(pii) pq;
        par[a]=-1;
        par1[b]=-1;
        dist[a]=0;
        pq.push({0,a});
        while (!pq.empty())
        {
            pii x=pq.top();
            pq.pop();
            int u=x.ss;
            if (visited[u])
                continue;
            visited[u]=true;
            for (auto v:adj[u])
            {
                if (dist[v]>dist[u]+1)
                {
                    dist[v]=dist[u]+1;
                    par[v]=u;
                    pq.push({dist[v],v});
                }
            }
        }
        minpqueue(pii) pq1;
        dist1[b]=0;
        pq1.push({0,b});
        mm(visited,false);
        while (!pq1.empty())
        {
            pii x=pq1.top();
            pq1.pop();
            int u=x.ss;
            if (visited[u])
                continue;
            visited[u]=true;
            for (auto v:adj[u])
            {
                if (dist1[v]>dist1[u]+1)
                {
                    dist1[v]=dist1[u]+1;
                    par1[v]=u;
                    pq1.push({dist1[v],v});
                }
            }
        }
        vi path1,path2;
        int x=b;
        while (par[x]!=-1)
        {
            path1.pb(x);
            x=par[x];
        }
        path1.pb(x);
        x=c;
        while (par1[x]!=-1)
        {
            path2.pb(x);
            x=par1[x];
        }
        path2.pb(x);
        reverse(all(path1));
        reverse(all(path2));
        map<pii,int> occ;
        for (int i=0;i<path1.size()-1;i++)
        {
            int x=path1[i];
            int y=path1[i+1];
            if (x<y)
                occ[{x,y}]++;
            else
                occ[{y,x}]++;
        }
        for (int i=0;i<path2.size()-1;i++)
        {
            int x=path2[i];
            int y=path2[i+1];
            if (x<y)
                occ[{x,y}]++;
            else
                occ[{y,x}]++;
        }
        vi last;
        for (auto v:occ)
            last.pb(v.ss);
        sort(all(last));
        reverse(all(last));
        for (int i=0;i<last.size();i++)
            ans+=last[i]*b1[i];
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define f first
#define ss second
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pdd pair<double,double>
#define vd vector<double>
#define vpii vector<pii>
#define si stack<int>
#define qi queue<int>
#define m2 998244353
#define m1 1000000007
#define maxpqueue(x) priority_queue<x>
#define minpqueue(x) priority_queue<x,vector<x>,greater<x> >
#define rep(i,a,b,inc) for(int i=a;i<b;i+=inc)
#define repd(i,a,b,dec) for(int i=a;i>=b;i-=dec)
#define pi 3.14159265359
#define mm(a,x) memset(a,x,sizeof(a))
#define debug cout<<"hello\n";
#define vi vector<int>
#define countset(a) __builtin_popcount(a)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
signed main()
{
    fast
    int t;
    cin>>t;
    while (t--)
    {
        int n,m,a,b,c;
        cin>>n>>m>>a>>b>>c;
        int ans=9e18;
        vi adj[n+1];
        int b1[m];
        for (int i=0;i<m;i++)
            cin>>b1[i];
        sort(b1,b1+m);
        for (int i=0;i<m;i++)
        {
            int x,y;
            cin>>x>>y;
            adj[x].pb(y);
            adj[y].pb(x);
        }
        bool visited[n+1];
        mm(visited,false);
        int par[n+1],par1[n+1],par2[n+1];
        int dist[n+1],dist1[n+1],dist2[n+1];
        mm(par,0);
        mm(par1,0);
        mm(par2,0);
        for (int i=1;i<=n;i++)
            dist[i]=INT_MAX;
        for (int i=1;i<=n;i++)
            dist1[i]=INT_MAX;
        for (int i=1;i<=n;i++)
            dist2[i]=INT_MAX;
        minpqueue(pii) pq;
        par[a]=-1;
        par1[b]=-1;
        par2[c]=-1;
        dist[a]=0;
        pq.push({0,a});
        while (!pq.empty())
        {
            pii x=pq.top();
            pq.pop();
            int u=x.ss;
            if (visited[u])
                continue;
            visited[u]=true;
            for (auto v:adj[u])
            {
                if (dist[v]>dist[u]+1)
                {
                    dist[v]=dist[u]+1;
                    par[v]=u;
                    pq.push({dist[v],v});
                }
            }
        }
        minpqueue(pii) pq1;
        dist1[b]=0;
        pq1.push({0,b});
        mm(visited,false);
        while (!pq1.empty())
        {
            pii x=pq1.top();
            pq1.pop();
            int u=x.ss;
            if (visited[u])
                continue;
            visited[u]=true;
            for (auto v:adj[u])
            {
                if (dist1[v]>dist1[u]+1)
                {
                    dist1[v]=dist1[u]+1;
                    par1[v]=u;
                    pq1.push({dist1[v],v});
                }
            }
        }
        minpqueue(pii) pq2;
        pq2.push({0,c});
        dist2[c]=0;
        mm(visited,false);
        while (!pq2.empty())
        {
            pii x=pq2.top();
            pq2.pop();
            int u=x.ss;
            if (visited[u])
                continue;
            visited[u]=true;
            for (auto v:adj[u])
            {
                if (dist2[v]>dist2[u]+1)
                {
                    dist2[v]=dist2[u]+1;
                    par2[v]=u;
                    pq2.push({dist2[v],v});
                }
            }
        }
        int presum[m];
        presum[0]=b1[0];
        for (int i=1;i<m;i++)
            presum[i]=presum[i-1]+b1[i];
        for (int i=1;i<=n;i++)
        {
            int p=dist[i]+dist1[i]+dist2[i];
            int q=dist1[i];
            if (p==0&&q==0)
                ans=0;
            else if (q==0&&p<=m)
                ans=min(ans,presum[p-1]);
            else if (p<=m&&q<=m)
                ans=min(ans,presum[p-1]+presum[q-1]);
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define f first
#define ss second
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pdd pair<double,double>
#define vd vector<double>
#define vpii vector<pii>
#define si stack<int>
#define qi queue<int>
#define m2 998244353
#define m1 1000000007
#define maxpqueue(x) priority_queue<x>
#define minpqueue(x) priority_queue<x,vector<x>,greater<x> >
#define rep(i,a,b,inc) for(int i=a;i<b;i+=inc)
#define repd(i,a,b,dec) for(int i=a;i>=b;i-=dec)
#define pi 3.14159265359
#define mm(a,x) memset(a,x,sizeof(a))
#define debug cout<<"hello\n";
#define vi vector<int>
#define countset(a) __builtin_popcount(a)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
signed main()
{
    fast
    int t;
    cin>>t;
    while (t--)
    {
        int n,m,a,b,c;
        cin>>n>>m>>a>>b>>c;
        int ans=0;
        vi adj[n+1];
        int b1[m];
        for (int i=0;i<m;i++)
            cin>>b1[i];
        sort(b1,b1+m);
        for (int i=0;i<m;i++)
        {
            int x,y;
            cin>>x>>y;
            adj[x].pb(y);
            adj[y].pb(x);
        }
        bool visited[n+1];
        mm(visited,false);
        int par[n+1],par1[n+1];
        int dist[n+1],dist1[n+1];
        mm(par,0);
        mm(par1,0);
        for (int i=1;i<=n;i++)
            dist[i]=INT_MAX;
        for (int i=1;i<=n;i++)
            dist1[i]=INT_MAX;
        minpqueue(pii) pq;
        par[a]=-1;
        par1[b]=-1;
        dist[a]=0;
        pq.push({0,a});
        while (!pq.empty())
        {
            pii x=pq.top();
            pq.pop();
            int u=x.ss;
            if (visited[u])
                continue;
            visited[u]=true;
            for (auto v:adj[u])
            {
                if (dist[v]>dist[u]+1)
                {
                    dist[v]=dist[u]+1;
                    par[v]=u;
                    pq.push({dist[v],v});
                }
            }
        }
        minpqueue(pii) pq1;
        dist1[b]=0;
        pq1.push({0,b});
        mm(visited,false);
        while (!pq1.empty())
        {
            pii x=pq1.top();
            pq1.pop();
            int u=x.ss;
            if (visited[u])
                continue;
            visited[u]=true;
            for (auto v:adj[u])
            {
                if (dist1[v]>dist1[u]+1)
                {
                    dist1[v]=dist1[u]+1;
                    par1[v]=u;
                    pq1.push({dist1[v],v});
                }
            }
        }
        vi path1,path2;
        int x=b;
        while (par[x]!=-1)
        {
            path1.pb(x);
            x=par[x];
        }
        path1.pb(x);
        x=c;
        while (par1[x]!=-1)
        {
            path2.pb(x);
            x=par1[x];
        }
        path2.pb(x);
        reverse(all(path1));
        reverse(all(path2));
        for (int i=0;i<path1.size();i++)
            cout<<path1[i]<<" ";
        cout<<endl;
        for (int i=0;i<path2.size();i++)
            cout<<path2[i]<<" ";
        cout<<endl;
        map<pii,int> occ;
        for (int i=0;i<path1.size()-1;i++)
        {
            int x=path1[i];
            int y=path1[i+1];
            if (x<y)
                occ[{x,y}]++;
            else
                occ[{y,x}]++;
        }
        for (int i=0;i<path2.size()-1;i++)
        {
            int x=path2[i];
            int y=path2[i+1];
            if (x<y)
                occ[{x,y}]++;
            else
                occ[{y,x}]++;
        }
        vi last;
        for (auto v:occ)
            last.pb(v.ss);
        sort(all(last));
        reverse(all(last));
        for (int i=0;i<last.size();i++)
            ans+=last[i]*b1[i];
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5+5;

void bfs(int u, vector<int> (&g)[maxn], vector<int> &pre, vector<int> &vis) {
	queue<int> q;
	q.push(u);
	vis[u] = 1;
	while(!q.empty()) {
		u = q.front();
		q.pop();
		for (auto it = g[u].begin() ; it != g[u].end() ; it++) {
			int v = *it;
			if (!vis[v]) {
				pre[v] = u;
				vis[v] = 1;
				q.push(v);
			}
		}
	}
}

int main() {
	int t;
	cin >> t;
	while(t--) {
		int n, m, a, b, c;
		cin >> n >> m >> a >> b >> c;

		vector<long long> p(maxn);
		for (int i = 0 ; i < m ; i++)
			cin >> p[i];

		sort(p.begin(), p.begin() + m);

		vector<int> g[maxn];
		for (int i = 0 ; i < m ; i++) {
			int u, v;
			cin >> u >> v;
			g[u].push_back(v);
			g[v].push_back(u);
		}

		vector<int> pre(maxn, 0);
		vector<int> vis(maxn, 0);

		vector<int> trip1;
		vector<int> trip2;

		bfs(b, g, pre, vis);
		int x = a;
		while(x) {
			trip1.push_back(x);
			x = pre[x];
		}

		x = c;
		while(x) {
			trip2.push_back(x);
			x = pre[x];
		}

		int s1 = trip1.size();
		int s2 = trip2.size();

		// for (int i = 0 ; i < s1 ; i++)
		// 	cout << trip1[i] << " ";
		// cout << endl;

		// for (int i = 0 ; i < s2 ; i++)
		// 	cout << trip2[i] << " ";
		// cout << endl;

		x = s1 - 1;
		int y = s2 - 1;
		while(x >= 0 && y >= 0 && trip1[x] == trip2[y]) {
			x--;
			y--;
		}

		int common = s1 - x - 1;
		int idx = s1 + s2 - common - 1;
		long long sum = 0;
		for (int i = 0 ; i < idx ; i++) {
			if (i < common - 1)
				sum += p[i];
			sum += p[i];
		}

		cout << sum << endl;
	}
}


#include <bits/stdc++.h>
using namespace std;

const int inf = 2e9;

const int maxn = 2e5+5;

vector< vector<int> > g;

void bfs(int s, vector<int> &d) {
	queue<int> q;
	d[s] = 0;
	q.push(s);
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		for (auto v : g[u]) {
			if (d[v] == inf) {
				d[v] = d[u] + 1;
				q.push(v);
			}
		}
	}
}

int main() {
	int t;
	cin >> t;
	while(t--) {
		int n, m, a, b, c;
		cin >> n >> m >> a >> b >> c;

		vector<long long> p(m);
		for (auto &it : p)
			cin >> it;

		sort(p.begin(), p.end());

		g = vector< vector<int> >(n + 1);
		for (int i = 0 ; i < m ; i++) {
			int u, v;
			cin >> u >> v;
			g[u].push_back(v);
			g[v].push_back(u);
		}

		vector<int> ad(n + 1, inf), bd(n + 1, inf), cd(n + 1, inf);
		bfs(a, ad);
		bfs(b, bd);
		bfs(c, cd);

		vector<long long> pref(m + 1, 0);
		for (int i = 1 ; i <= m ; i++) {
			pref[i] = pref[i - 1] + p[i - 1];
		}

		long long sum = inf;
		for (int i = 1 ; i <= n ; i++) {
			if (ad[i] + bd[i] + cd[i] <= m)
				sum = min(sum, pref[bd[i]] + pref[ad[i] + bd[i] + cd[i]]);
		}

		cout << sum << endl;
	}
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5+5;

void bfs(int u, vector<int> (&g)[maxn], vector<int> &pre, vector<int> &vis) {
	queue<int> q;
	q.push(u);
	vis[u] = 1;
	while(!q.empty()) {
		u = q.front();
		q.pop();
		for (auto it = g[u].begin() ; it != g[u].end() ; it++) {
			int v = *it;
			if (!vis[v]) {
				pre[v] = u;
				vis[v] = 1;
				q.push(v);
			}
		}
	}
}

int main() {
	int t;
	cin >> t;
	while(t--) {
		int n, m, a, b, c;
		cin >> n >> m >> a >> b >> c;

		vector<long long> p(maxn);
		for (int i = 0 ; i < m ; i++)
			cin >> p[i];

		sort(p.begin(), p.begin() + m);

		vector<int> g[maxn];
		for (int i = 0 ; i < m ; i++) {
			int u, v;
			cin >> u >> v;
			g[u].push_back(v);
			g[v].push_back(u);
		}

		vector<int> pre(maxn, 0);
		vector<int> vis(maxn, 0);

		vector<int> trip1;
		vector<int> trip2;

		bfs(a, g, pre, vis);
		int x = b;
		while(x) {
			trip1.push_back(x);
			x = pre[x];
		}

		for (int i = 0 ; i < maxn ; i++)
			pre[i] = vis[i] = 0;
		bfs(b, g, pre, vis);
		x = c;
		while(x) {
			trip2.push_back(x);
			x = pre[x];
		}

		reverse(trip2.begin(), trip2.end());

		int s1 = trip1.size();
		int s2 = trip2.size();

		// for (int i = 0 ; i < s1 ; i++)
		// 	cout << trip1[i] << " ";
		// cout << endl;

		// for (int i = 0 ; i < s2 ; i++)
		// 	cout << trip2[i] << " ";
		// cout << endl;

		x = 0;
		while(trip1[x] == trip2[x])
			x++;

		int idx = s1 + s2 - x - 1;
		long long sum = 0;
		for (int i = 0 ; i < idx ; i++) {
			if (i < x - 1)
				sum += p[i];
			sum += p[i];
		}

		cout << sum << endl;

	}
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5+5;

vector< vector<int> > g;

void bfs(int s, vector<int> &pre) {
	queue<int> q;
	q.push(s);
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		for (auto v : g[u]) {
			if (v != s && !pre[v]) {
				pre[v] = u;
				q.push(v);
			}
		}
	}
}

int main() {
	int t;
	cin >> t;
	while(t--) {
		int n, m, a, b, c;
		cin >> n >> m >> a >> b >> c;

		vector<long long> p(m);
		for (auto &it : p)
			cin >> it;

		sort(p.begin(), p.end());

		g = vector< vector<int> >(n + 1);
		for (int i = 0 ; i < m ; i++) {
			int u, v;
			cin >> u >> v;
			g[u].push_back(v);
			g[v].push_back(u);
		}

		vector<int> pre(n + 1, 0);
		bfs(b, pre);

		vector<int> trip1;
		vector<int> trip2;
		int x = a;
		while(x) {
			trip1.push_back(x);
			x = pre[x];
		}

		x = c;
		while(x) {
			trip2.push_back(x);
			x = pre[x];
		}

		int s1 = trip1.size();
		int s2 = trip2.size();

		x = s1 - 1;
		int y = s2 - 1;
		while(x >= 0 && y >= 0 && trip1[x] == trip2[y]) {
			x--;
			y--;
		}

		int common = s1 - x - 1;
		int idx = s1 + s2 - common - 1;
		long long sum = 0;
		for (int i = 0 ; i < idx ; i++) {
			if (i < common - 1)
				sum += p[i];
			sum += p[i];
		}

		cout << sum << endl;
	}
}


#include <bits/stdc++.h>
using namespace std;

const int inf = 2e9;

const int maxn = 2e5+5;

vector< vector<int> > g;

void bfs(int s, vector<int> &d) {
	queue<int> q;
	d[s] = 0;
	q.push(s);
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		for (auto v : g[u]) {
			if (d[v] == inf) {
				d[v] = d[u] + 1;
				q.push(v);
			}
		}
	}
}

int main() {
	int t;
	cin >> t;
	while(t--) {
		int n, m, a, b, c;
		cin >> n >> m >> a >> b >> c;

		vector<long long> p(m);
		for (auto &it : p)
			cin >> it;

		sort(p.begin(), p.end());

		g = vector< vector<int> >(n + 1);
		for (int i = 0 ; i < m ; i++) {
			int u, v;
			cin >> u >> v;
			g[u].push_back(v);
			g[v].push_back(u);
		}

		vector<int> ad(n + 1, inf), bd(n + 1, inf), cd(n + 1, inf);
		bfs(a, ad);
		bfs(b, bd);
		bfs(c, cd);

		vector<long long> pref(m + 1, 0);
		for (int i = 1 ; i <= m ; i++) {
			pref[i] = pref[i - 1] + p[i - 1];
		}

		long long sum = 1e16;
		for (int i = 1 ; i <= n ; i++) {
			if (ad[i] + bd[i] + cd[i] <= m)
				sum = min(sum, pref[bd[i]] + pref[ad[i] + bd[i] + cd[i]]);
		}

		cout << sum << endl;
	}
}


#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5+5;

void bfs(int u, vector<int> (&g)[maxn], vector<int> &pre, vector<int> &vis) {
	queue<int> q;
	q.push(u);
	vis[u] = 1;
	while(!q.empty()) {
		u = q.front();
		q.pop();
		for (auto it = g[u].begin() ; it != g[u].end() ; it++) {
			int v = *it;
			if (!vis[v]) {
				pre[v] = u;
				vis[v] = 1;
				q.push(v);
			}
		}
	}
}

int main() {
	int t;
	cin >> t;
	while(t--) {
		int n, m, a, b, c;
		cin >> n >> m >> a >> b >> c;

		vector<long long> p(maxn);
		for (int i = 0 ; i < m ; i++)
			cin >> p[i];

		sort(p.begin(), p.begin() + m);

		vector<int> g[maxn];
		for (int i = 0 ; i < m ; i++) {
			int u, v;
			cin >> u >> v;
			g[u].push_back(v);
			g[v].push_back(u);
		}

		vector<int> pre(maxn, 0);
		vector<int> vis(maxn, 0);

		vector<int> trip1;
		vector<int> trip2;

		bfs(b, g, pre, vis);
		int x = a;
		while(x) {
			trip1.push_back(x);
			x = pre[x];
		}

		x = c;
		while(x) {
			trip2.push_back(x);
			x = pre[x];
		}

		int s1 = trip1.size();
		int s2 = trip2.size();

		// for (int i = 0 ; i < s1 ; i++)
		// 	cout << trip1[i] << " ";
		// cout << endl;

		// for (int i = 0 ; i < s2 ; i++)
		// 	cout << trip2[i] << " ";
		// cout << endl;

		x = s1 - 1;
		int y = s2 - 1;
		while(x >= 0 && y >= 0 && trip1[x] == trip2[y])
			x--; y--;

		int common = s1 - x - 1;
		int idx = s1 + s2 - common - 1;
		long long sum = 0;
		for (int i = 0 ; i < idx ; i++) {
			if (i < common - 1)
				sum += p[i];
			sum += p[i];
		}

		cout << sum << endl;
	}
}