#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define f(i,x,n) for(ll i=x;i<n;i++)
#define fl(i,x,n) for(ll i=n;i>=x;i--)
#define mod (ll)1e9+7
#define print(x) cout<<x<<endl
#define vec vector<ll>
#define pai pair<ll, ll>
#define itr(it) :: iterator it
#define MAX (ll)1e16
#define MIN (ll)-1e16
#define X first
#define Y second
#define up upper_bound
#define lo lower_bound
using namespace std;
       ///////////   ///     ///   ///      ///   ////////////  ///      ///
       ///           ///     ///   ///      ///   ///      ///  ///      ///
       ///           ///     ///   ///      ///   ///      ///  ///      ///
       ///////////   ///////////   ///      ///   ////////////  ////////////
               ///   ///     ///   ///      ///   ///      ///  ///      ///
               ///   ///     ///   ///      ///   ///      ///  ///      ///
       ///////////   ///     ///   ////////////   ////////////  ///      ///
ll minn( ll a , ll b)
{
    if(a>b)
        return b;
    return a;
}
ll maxx2( ll a , ll b)
{
    if(a>b)
        return a;
    return b;
}
ll maxx(ll a,ll b,ll c)
{
  return maxx2(a,maxx2(b,c));
}
ll gcdd(ll a, ll b)
{
    if(b==0)
        return a;
    else
        return gcdd(b,a%b);
}
ll dsum(ll n)
{
    ll sum=0;
    while(n>0)
    {
        sum+=n%10;
        n/=10;
    }
    return sum;
}
ll poww(ll a,ll b)
{
    if(b<=0)
        return 1;
    if(b==1)
        return a;
    else
        return poww(a,b/2)*poww(a,b/2)*poww(a,b%2);
}
bool substr1(ll i,ll j,ll l,ll x)
{
    f(k,l,l+x)
    {
        if(s[i][k-l]!=s[j][k])
            return false;
    }
    return true;
}
ll sumsq(ll x,ll y,ll z)
{
    return (x-y)*(x-y)+(y-z)*(y-z)+(z-x)*(z-x);
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    IOS;
    ll t;
    cin>>t;
    while(t--)
    {
        ll n,m,a1,b,c;
        cin>>n>>m>>a1>>b>>c;
        vector<ll> v[n+1];
        bool visited[n+1]={false};
        ll pred[n+1],dist[n+1];
        f(i,0,n+1)
        {
        	pred[i]=-1;
        	dist[i]=10000000000000;
            visited[i]=false;
        }
        ll a[m];
        f(i,0,m)
        {
            cin>>a[i];
        }
        f(i,0,m)
        {
            ll u,v1;
            cin>>u>>v1;
            //cout<<u<<" "<<v1<<endl;
            v[u].pb(v1);
            v[v1].pb(u);
        }
        sort(a,a+m);
        list<ll> queue,queue1;
        ll src=a1;
        ll dest=b;
        visited[src] = true;
	    dist[src]=0;
	    queue.pb(src);
	    while(queue.size()!=0)
	    {
	    	ll flag=0;
	        ll u = queue.front();
	        queue.pop_front();
	        for (ll i = 0; i<v[u].size(); i++)
	        {
	            if (visited[v[u][i]] == false)
	            {
	                visited[v[u][i]] = true;
	                dist[v[u][i]] = dist[u] + 1;
	                pred[v[u][i]] = u;
	                queue.push_back(v[u][i]);
	                if (v[u][i] == dest)
	                {
	                	flag=1;
	                    break;
	                }
	            }
	        }
	        if(flag==1)
	        break;
	    }

	    vector<ll> d,e;
	    ll crawl = b;
	    d.push_back(crawl);
	    while (pred[crawl]!=-1)
	    {
	        d.push_back(pred[crawl]);
	        crawl = pred[crawl];
	    }
	    dest=c;
	    src=b;
	    f(i,0,n+1)
	    {
	    	pred[i]=-1;
	    	dist[i]=100000000000;
	    	visited[i]=false;
	    }
	    visited[src] = true;
	    dist[src] = 0;
	    queue1.push_back(src);
	    while(queue1.size()!=0)
	    {
	    	ll flag=0;
	        ll u = queue1.front();
	        queue1.pop_front();
	        for (ll i=0;i<v[u].size(); i++)
	        {
	            if (visited[v[u][i]] == false)
	            {
	            	//cout<<v[u][i]<<endl;
	                visited[v[u][i]] = true;
	                dist[v[u][i]] = dist[u] + 1;
	                pred[v[u][i]] = u;
	                queue1.push_back(v[u][i]);
	                if(v[u][i] == dest)
	                {
	                	flag=1;
	                    break;
	                }
	            }
	        }
	        if(flag==1)
	        break;
	    }
	    crawl = c;
	    e.push_back(crawl);
	    while (pred[crawl]!=-1)
	    {
	        e.push_back(pred[crawl]);
	        crawl = pred[crawl];
	    }
	    //cout<<d.size()<<" "<<e.size()<<endl;
	    vector<ll> ans;
        map<string,ll> m1;
        f(i,0,d.size()-1)
        {
            string s = to_string(d[i]) + 'x'+ to_string(d[i+1]);
            string s1 = to_string(d[i+1]) + 'x'+ to_string(d[i]);
            m1[s1]=0;
            m1[s]=0;

        }
        f(i,0,e.size()-1)
        {
            string s = to_string(e[i])+ 'x'+to_string(e[i+1]);
            string s1 = to_string(e[i+1]) + 'x'+ to_string(e[i]);
            m1[s]=0;
            m1[s1]=0;
        }
        f(i,0,d.size()-1)
        {
            string s = to_string(d[i]) + 'x'+ to_string(d[i+1]);
            m1[s]++;

        }
        f(i,0,e.size()-1)
        {
            string s = to_string(e[i])+ 'x'+to_string(e[i+1]);
            string s1 = to_string(e[i+1]) + 'x'+ to_string(e[i]);
            //cout<<m1[s1]<<endl;
            if(m1[s1]!=0)
            	m1[s1]++;
            else
            	m1[s]++;
            //cout<<s<<endl;
        }
        f(i,0,d.size()-1)
        {
            string s = to_string(d[i]) + 'x'+ to_string(d[i+1]);
            //cout<<m1[s]<<endl;
            if(m1[s]!=0)
            {
            	ans.pb(m1[s]);
            	m1[s]=0;
            }
        }
        f(i,0,e.size()-1)
        {
            string s = to_string(e[i]) + 'x'+ to_string(e[i+1]);
            if(m1[s]!=0)
            {
            	ans.pb(m1[s]);
            	m1[s]=0;
            }
        }
        sort(ans.begin(),ans.end());
        ll j=0,sum=0;
        for(ll i=ans.size()-1;i>=0;i--)
        {
        	sum+=ans[i]*a[j];
        	j++;
        }
        cout<<sum<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define f(i,x,n) for(ll i=x;i<n;i++)
#define fl(i,x,n) for(ll i=n;i>=x;i--)
#define mod (ll)1e9+7
#define print(x) cout<<x<<endl
#define vec vector<ll>
#define pai pair<ll, ll>
#define itr(it) :: iterator it
#define MAX (ll)1e16
#define MIN (ll)-1e16
#define X first
#define Y second
#define up upper_bound
#define lo lower_bound
using namespace std;
       ///////////   ///     ///   ///      ///   ////////////  ///      ///
       ///           ///     ///   ///      ///   ///      ///  ///      ///
       ///           ///     ///   ///      ///   ///      ///  ///      ///
       ///////////   ///////////   ///      ///   ////////////  ////////////
               ///   ///     ///   ///      ///   ///      ///  ///      ///
               ///   ///     ///   ///      ///   ///      ///  ///      ///
       ///////////   ///     ///   ////////////   ////////////  ///      ///
ll minn( ll a , ll b)
{
    if(a>b)
        return b;
    return a;
}
ll maxx2( ll a , ll b)
{
    if(a>b)
        return a;
    return b;
}
ll maxx(ll a,ll b,ll c)
{
  return maxx2(a,maxx2(b,c));
}
ll gcdd(ll a, ll b)
{
    if(b==0)
        return a;
    else
        return gcdd(b,a%b);
}
ll dsum(ll n)
{
    ll sum=0;
    while(n>0)
    {
        sum+=n%10;
        n/=10;
    }
    return sum;
}
ll poww(ll a,ll b)
{
    if(b<=0)
        return 1;
    if(b==1)
        return a;
    else
        return poww(a,b/2)*poww(a,b/2)*poww(a,b%2);
}
char s[50][100];
bool substr1(ll i,ll j,ll l,ll x)
{
    f(k,l,l+x)
    {
        if(s[i][k-l]!=s[j][k])
            return false;
    }
    return true;
}
ll sumsq(ll x,ll y,ll z)
{
    return (x-y)*(x-y)+(y-z)*(y-z)+(z-x)*(z-x);
}
vector<ll> v[200001];
ll visited[200001]={0};
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    IOS;
    ll t;
    cin>>t;
    while(t--)
    {
        ll n,m,a1,b,c;
        cin>>n>>m>>a1>>b>>c;
        ll pred[n+1],dist[n+1];
        f(i,0,n+1)
        {
        	pred[i]=-1;
        	dist[i]=10000000000000;
            visited[i]=0;
            v[i].clear();
        }
        ll a[m];
        f(i,0,m)
        {
            cin>>a[i];
        }
        f(i,0,m)
        {
            ll u,v1;
            cin>>u>>v1;
            v[u].pb(v1);
            v[v1].pb(u);
        }
        sort(a,a+m);
        list<int> queue,queue1;
        ll src=a1;
        ll dest=b;
        visited[src] = true;
	    dist[src] = 0;
	    queue.push_back(src);
	    while (!queue.empty())
	    {
	    	ll flag=0;
	        ll u = queue.front();
	        queue.pop_front();
	        for (int i = 0; i < v[u].size(); i++)
	        {
	            if (visited[v[u][i]] == false)
	            {
	                visited[v[u][i]] = true;
	                dist[v[u][i]] = dist[u] + 1;
	                pred[v[u][i]] = u;
	                queue.push_back(v[u][i]);
	                if (v[u][i] == dest)
	                {
	                	flag=1;
	                    break;
	                }
	            }
	        }
	        if(flag==1)
	        break;
	    }
	    vector<ll> d,e;
	    ll crawl = dest;
	    d.push_back(crawl);
	    while (pred[crawl] != -1) {
	        d.push_back(pred[crawl]);
	        crawl = pred[crawl];
	    }
	    dest=c;
	    src=b;
	    f(i,0,n+1)
	    {
	    	pred[i]=-1;
	    	dist[i]=100000000000;
	    	visited[i]=0;
	    }
	    visited[src] = true;
	    dist[src] = 0;
	    queue1.push_back(src);
	    while (!queue.empty())
	    {
	    	ll flag=0;
	        ll u = queue1.front();
	        queue1.pop_front();
	        for (int i = 0; i < v[u].size(); i++)
	        {
	            if (visited[v[u][i]] == false)
	            {
	                visited[v[u][i]] = true;
	                dist[v[u][i]] = dist[u] + 1;
	                pred[v[u][i]] = u;
	                queue1.push_back(v[u][i]);
	                if (v[u][i] == dest)
	                {
	                	flag=1;
	                    break;
	                }
	            }
	        }
	        if(flag==1)
	        break;
	    }
	    crawl = dest;
	    e.push_back(crawl);
	    while (pred[crawl] != -1) {
	        e.push_back(pred[crawl]);
	        crawl = pred[crawl];
	    }
	    //cout<<d.size()<<" "<<e.size()<<endl;
	    vector<ll> ans;
        map<string,ll> m1;
        f(i,0,d.size()-1)
        {
            string s = to_string(d[i]) + 'x'+ to_string(d[i+1]);
            m1[s]++;

        }
        f(i,0,e.size()-1)
        {
            string s = to_string(e[i])+ 'x'+to_string(e[i+1]);
            string s1 = to_string(e[i+1]) + 'x'+ to_string(e[i]);
            //cout<<m1[s1]<<endl;
            if(m1[s1]!=0)
            	m1[s1]++;
            else
            	m1[s]++;
            //cout<<s<<endl;
        }
        f(i,0,d.size()-1)
        {
            string s = to_string(d[i]) + 'x'+ to_string(d[i+1]);
            //cout<<m1[s]<<endl;
            if(m1[s]!=0)
            {
            	ans.pb(m1[s]);
            	m1[s]=0;
            }
        }
        f(i,0,e.size()-1)
        {
            string s = to_string(e[i]) + 'x'+ to_string(e[i+1]);
            if(m1[s]!=0)
            {
            	ans.pb(m1[s]);
            	m1[s]=0;
            }
        }
        sort(ans.begin(),ans.end());
        ll j=0,sum=0;
        for(ll i=ans.size()-1;i>=0;i--)
        {
        	//cout<<ans[i]<<endl;
        	sum+=ans[i]*a[j];
        	j++;
        }
        cout<<sum<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define f(i,x,n) for(ll i=x;i<n;i++)
#define fl(i,x,n) for(ll i=n;i>=x;i--)
#define mod (ll)1e9+7
#define print(x) cout<<x<<endl
#define vec vector<ll>
#define pai pair<ll, ll>
#define itr(it) :: iterator it
#define MAX (ll)1e16
#define MIN (ll)-1e16
#define X first
#define Y second
#define up upper_bound
#define lo lower_bound
using namespace std;
       ///////////   ///     ///   ///      ///   ////////////  ///      ///
       ///           ///     ///   ///      ///   ///      ///  ///      ///
       ///           ///     ///   ///      ///   ///      ///  ///      ///
       ///////////   ///////////   ///      ///   ////////////  ////////////
               ///   ///     ///   ///      ///   ///      ///  ///      ///
               ///   ///     ///   ///      ///   ///      ///  ///      ///
       ///////////   ///     ///   ////////////   ////////////  ///      ///
ll minn( ll a , ll b)
{
    if(a>b)
        return b;
    return a;
}
ll maxx2( ll a , ll b)
{
    if(a>b)
        return a;
    return b;
}
ll maxx(ll a,ll b,ll c)
{
  return maxx2(a,maxx2(b,c));
}
ll gcdd(ll a, ll b)
{
    if(b==0)
        return a;
    else
        return gcdd(b,a%b);
}
ll dsum(ll n)
{
    ll sum=0;
    while(n>0)
    {
        sum+=n%10;
        n/=10;
    }
    return sum;
}
ll poww(ll a,ll b)
{
    if(b<=0)
        return 1;
    if(b==1)
        return a;
    else
        return poww(a,b/2)*poww(a,b/2)*poww(a,b%2);
}
ll sumsq(ll x,ll y,ll z)
{
    return (x-y)*(x-y)+(y-z)*(y-z)+(z-x)*(z-x);
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    IOS;
    ll t;
    cin>>t;
    while(t--)
    {
        ll n,m,a1,b,c;
        cin>>n>>m>>a1>>b>>c;
        vector<ll> v[n+1];
        bool visited[n+1]={false};
        ll pred[n+1],dist[n+1];
        f(i,0,n+1)
        {
        	pred[i]=-1;
        	dist[i]=10000000000000;
            visited[i]=false;
        }
        ll a[m];
        f(i,0,m)
        {
            cin>>a[i];
        }
        f(i,0,m)
        {
            ll u,v1;
            cin>>u>>v1;
            //cout<<u<<" "<<v1<<endl;
            v[u].pb(v1);
            v[v1].pb(u);
        }
        sort(a,a+m);
        list<ll> queue,queue1;
        ll src=a1;
        ll dest=b;
        visited[src] = true;
	    dist[src]=0;
	    queue.pb(src);
	    while(queue.size()!=0)
	    {
	    	ll flag=0;
	        ll u = queue.front();
	        queue.pop_front();
	        for (ll i = 0; i<v[u].size(); i++)
	        {
	            if (visited[v[u][i]] == false)
	            {
	                visited[v[u][i]] = true;
	                dist[v[u][i]] = dist[u] + 1;
	                pred[v[u][i]] = u;
	                queue.push_back(v[u][i]);
	                if (v[u][i] == dest)
	                {
	                	flag=1;
	                    break;
	                }
	            }
	        }
	        if(flag==1)
	        break;
	    }

	    vector<ll> d,e;
	    ll crawl = b;
	    d.push_back(crawl);
	    while (pred[crawl]!=-1)
	    {
	        d.push_back(pred[crawl]);
	        crawl = pred[crawl];
	    }
	    dest=c;
	    src=b;
	    f(i,0,n+1)
	    {
	    	pred[i]=-1;
	    	dist[i]=100000000000;
	    	visited[i]=false;
	    }
	    visited[src] = true;
	    dist[src] = 0;
	    queue1.push_back(src);
	    while(queue1.size()!=0)
	    {
	    	ll flag=0;
	        ll u = queue1.front();
	        queue1.pop_front();
	        for (ll i=0;i<v[u].size(); i++)
	        {
	            if (visited[v[u][i]] == false)
	            {
	            	//cout<<v[u][i]<<endl;
	                visited[v[u][i]] = true;
	                dist[v[u][i]] = dist[u] + 1;
	                pred[v[u][i]] = u;
	                queue1.push_back(v[u][i]);
	                if(v[u][i] == dest)
	                {
	                	flag=1;
	                    break;
	                }
	            }
	        }
	        if(flag==1)
	        break;
	    }
	    crawl = c;
	    e.push_back(crawl);
	    while (pred[crawl]!=-1)
	    {
	        e.push_back(pred[crawl]);
	        crawl = pred[crawl];
	    }
	    //cout<<d.size()<<" "<<e.size()<<endl;
	    vector<ll> ans;
        map<string,ll> m1;
        f(i,0,d.size()-1)
        {
            string s = to_string(d[i]) + 'x'+ to_string(d[i+1]);
            string s1 = to_string(d[i+1]) + 'x'+ to_string(d[i]);
            m1[s1]=0;
            m1[s]=0;

        }
        f(i,0,e.size()-1)
        {
            string s = to_string(e[i])+ 'x'+to_string(e[i+1]);
            string s1 = to_string(e[i+1]) + 'x'+ to_string(e[i]);
            m1[s]=0;
            m1[s1]=0;
        }
        f(i,0,d.size()-1)
        {
            string s = to_string(d[i]) + 'x'+ to_string(d[i+1]);
            m1[s]++;

        }
        f(i,0,e.size()-1)
        {
            string s = to_string(e[i])+ 'x'+to_string(e[i+1]);
            string s1 = to_string(e[i+1]) + 'x'+ to_string(e[i]);
            //cout<<m1[s1]<<endl;
            if(m1[s1]!=0)
            	m1[s1]++;
            else
            	m1[s]++;
            //cout<<s<<endl;
        }
        f(i,0,d.size()-1)
        {
            string s = to_string(d[i]) + 'x'+ to_string(d[i+1]);
            //cout<<m1[s]<<endl;
            if(m1[s]!=0)
            {
            	ans.pb(m1[s]);
            	m1[s]=0;
            }
        }
        f(i,0,e.size()-1)
        {
            string s = to_string(e[i]) + 'x'+ to_string(e[i+1]);
            if(m1[s]!=0)
            {
            	ans.pb(m1[s]);
            	m1[s]=0;
            }
        }
        sort(ans.begin(),ans.end());
        ll j=0,sum=0;
        if(ans.size()==0 || ans.size()>m)
        {
        	cout<<"0"<<endl;
        	continue;
        }
        for(ll i=ans.size()-1;i>=0;i--)
        {
        	sum+=ans[i]*a[j];
        	j++;
        }
        cout<<sum<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define f(i,x,n) for(ll i=x;i<n;i++)
#define fl(i,x,n) for(ll i=n;i>=x;i--)
#define mod (ll)1e9+7
#define print(x) cout<<x<<endl
#define vec vector<ll>
#define pai pair<ll, ll>
#define itr(it) :: iterator it
#define MAX (ll)1e16
#define MIN (ll)-1e16
#define X first
#define Y second
#define up upper_bound
#define lo lower_bound
using namespace std;
       ///////////   ///     ///   ///      ///   ////////////  ///      ///
       ///           ///     ///   ///      ///   ///      ///  ///      ///
       ///           ///     ///   ///      ///   ///      ///  ///      ///
       ///////////   ///////////   ///      ///   ////////////  ////////////
               ///   ///     ///   ///      ///   ///      ///  ///      ///
               ///   ///     ///   ///      ///   ///      ///  ///      ///
       ///////////   ///     ///   ////////////   ////////////  ///      ///
ll minn( ll a , ll b)
{
    if(a>b)
        return b;
    return a;
}
ll maxx2( ll a , ll b)
{
    if(a>b)
        return a;
    return b;
}
ll maxx(ll a,ll b,ll c)
{
  return maxx2(a,maxx2(b,c));
}
ll gcdd(ll a, ll b)
{
    if(b==0)
        return a;
    else
        return gcdd(b,a%b);
}
ll dsum(ll n)
{
    ll sum=0;
    while(n>0)
    {
        sum+=n%10;
        n/=10;
    }
    return sum;
}
ll poww(ll a,ll b)
{
    if(b<=0)
        return 1;
    if(b==1)
        return a;
    else
        return poww(a,b/2)*poww(a,b/2)*poww(a,b%2);
}
char s[50][100];
bool substr1(ll i,ll j,ll l,ll x)
{
    f(k,l,l+x)
    {
        if(s[i][k-l]!=s[j][k])
            return false;
    }
    return true;
}
ll sumsq(ll x,ll y,ll z)
{
    return (x-y)*(x-y)+(y-z)*(y-z)+(z-x)*(z-x);
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    IOS;
    ll t;
    cin>>t;
    while(t--)
    {
        ll n,m,a1,b,c;
        cin>>n>>m>>a1>>b>>c;
        vector<ll> v[n+1];
        bool visited[n+1]={false};
        ll pred[n+1],dist[n+1];
        f(i,0,n+1)
        {
        	pred[i]=-1;
        	dist[i]=10000000000000;
            visited[i]=false;
        }
        ll a[m];
        f(i,0,m)
        {
            cin>>a[i];
        }
        f(i,0,m)
        {
            ll u,v1;
            cin>>u>>v1;
            //cout<<u<<" "<<v1<<endl;
            v[u].pb(v1);
            v[v1].pb(u);
        }
        sort(a,a+m);
        list<ll> queue,queue1;
        ll src=a1;
        ll dest=b;
        visited[src] = true;
	    dist[src] = 0;
	    queue.push_back(src);
	    while(!queue.empty())
	    {
	    	ll flag=0;
	        ll u = queue.front();
	        queue.pop_front();
	        for (int i = 0; i < v[u].size(); i++)
	        {
	            if (visited[v[u][i]] == false)
	            {
	                visited[v[u][i]] = true;
	                dist[v[u][i]] = dist[u] + 1;
	                pred[v[u][i]] = u;
	                queue.push_back(v[u][i]);
	                if (v[u][i] == dest)
	                {
	                	flag=1;
	                    break;
	                }
	            }
	        }
	        if(flag==1)
	        break;
	    }

	    vector<ll> d,e;
	    ll crawl = b;
	    d.push_back(crawl);
	    while (pred[crawl] != -1)
	    {
	        d.push_back(pred[crawl]);
	        crawl = pred[crawl];
	    }
	    dest=c;
	    src=b;
	    f(i,0,n+1)
	    {
	    	pred[i]=-1;
	    	dist[i]=100000000000;
	    	visited[i]=false;
	    }
	    visited[src] = true;
	    dist[src] = 0;
	    queue1.push_back(src);
	    while(!queue1.empty())
	    {
	    	ll flag=0;
	        ll u = queue1.front();
	        queue1.pop_front();
	        for (int i=0;i<v[u].size(); i++)
	        {
	            if (visited[v[u][i]] == false)
	            {
	            	//cout<<v[u][i]<<endl;
	                visited[v[u][i]] = true;
	                dist[v[u][i]] = dist[u] + 1;
	                pred[v[u][i]] = u;
	                queue1.push_back(v[u][i]);
	                if(v[u][i] == dest)
	                {
	                	flag=1;
	                    break;
	                }
	            }
	        }
	        if(flag==1)
	        break;
	    }
	    crawl = c;
	    e.push_back(crawl);
	    while (pred[crawl]!=-1)
	    {
	        e.push_back(pred[crawl]);
	        crawl = pred[crawl];
	    }
	    //cout<<d.size()<<" "<<e.size()<<endl;
	    vector<ll> ans;
        map<string,ll> m1;
        f(i,0,d.size()-1)
        {
            string s = to_string(d[i]) + 'x'+ to_string(d[i+1]);
            m1[s]++;

        }
        f(i,0,e.size()-1)
        {
            string s = to_string(e[i])+ 'x'+to_string(e[i+1]);
            string s1 = to_string(e[i+1]) + 'x'+ to_string(e[i]);
            //cout<<m1[s1]<<endl;
            if(m1[s1]!=0)
            	m1[s1]++;
            else
            	m1[s]++;
            //cout<<s<<endl;
        }
        f(i,0,d.size()-1)
        {
            string s = to_string(d[i]) + 'x'+ to_string(d[i+1]);
            //cout<<m1[s]<<endl;
            if(m1[s]!=0)
            {
            	ans.pb(m1[s]);
            	m1[s]=0;
            }
        }
        f(i,0,e.size()-1)
        {
            string s = to_string(e[i]) + 'x'+ to_string(e[i+1]);
            if(m1[s]!=0)
            {
            	ans.pb(m1[s]);
            	m1[s]=0;
            }
        }
        sort(ans.begin(),ans.end());
        ll j=0,sum=0;
        for(ll i=ans.size()-1;i>=0;i--)
        {
        	//cout<<ans[i]<<endl;
        	sum+=ans[i]*a[j];
        	j++;
        }
        cout<<sum<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define f(i,x,n) for(ll i=x;i<n;i++)
#define fl(i,x,n) for(ll i=n;i>=x;i--)
#define mod (ll)1e9+7
#define print(x) cout<<x<<endl
#define vec vector<ll>
#define pai pair<ll, ll>
#define itr(it) :: iterator it
#define MAX (ll)1e16
#define MIN (ll)-1e16
#define X first
#define Y second
#define up upper_bound
#define lo lower_bound
using namespace std;
       ///////////   ///     ///   ///      ///   ////////////  ///      ///
       ///           ///     ///   ///      ///   ///      ///  ///      ///
       ///           ///     ///   ///      ///   ///      ///  ///      ///
       ///////////   ///////////   ///      ///   ////////////  ////////////
               ///   ///     ///   ///      ///   ///      ///  ///      ///
               ///   ///     ///   ///      ///   ///      ///  ///      ///
       ///////////   ///     ///   ////////////   ////////////  ///      ///
ll minn( ll a , ll b)
{
    if(a>b)
        return b;
    return a;
}
ll maxx2( ll a , ll b)
{
    if(a>b)
        return a;
    return b;
}
ll maxx(ll a,ll b,ll c)
{
  return maxx2(a,maxx2(b,c));
}
ll gcdd(ll a, ll b)
{
    if(b==0)
        return a;
    else
        return gcdd(b,a%b);
}
ll dsum(ll n)
{
    ll sum=0;
    while(n>0)
    {
        sum+=n%10;
        n/=10;
    }
    return sum;
}
ll poww(ll a,ll b)
{
    if(b<=0)
        return 1;
    if(b==1)
        return a;
    else
        return poww(a,b/2)*poww(a,b/2)*poww(a,b%2);
}
ll sumsq(ll x,ll y,ll z)
{
    return (x-y)*(x-y)+(y-z)*(y-z)+(z-x)*(z-x);
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    IOS;
    ll t;
    cin>>t;
    while(t--)
    {
        ll n,m,a1,b,c;
        cin>>n>>m>>a1>>b>>c;
        vector<ll> v[n+1];
        bool visited[n+1]={false};
        ll pred[n+1],dist[n+1];
        f(i,0,n+1)
        {
        	pred[i]=-1;
        	dist[i]=10000000000000;
            visited[i]=false;
        }
        ll a[m];
        f(i,0,m)
        {
            cin>>a[i];
        }
        f(i,0,m)
        {
            ll u,v1;
            cin>>u>>v1;
            //cout<<u<<" "<<v1<<endl;
            v[u].pb(v1);
            v[v1].pb(u);
        }
        sort(a,a+m);
        list<ll> queue,queue1;
        ll src=a1;
        ll dest=b;
        visited[src] = true;
	    dist[src]=0;
	    queue.pb(src);
	    while(queue.size()!=0)
	    {
	    	ll flag=0;
	        ll u = queue.front();
	        queue.pop_front();
	        for (ll i = 0; i<v[u].size(); i++)
	        {
	            if (visited[v[u][i]] == false)
	            {
	                visited[v[u][i]] = true;
	                dist[v[u][i]] = dist[u] + 1;
	                pred[v[u][i]] = u;
	                queue.push_back(v[u][i]);
	                if (v[u][i] == dest)
	                {
	                	flag=1;
	                    break;
	                }
	            }
	        }
	        if(flag==1)
	        break;
	    }

	    vector<ll> d,e;
	    ll crawl = b;
	    d.push_back(crawl);
	    while (pred[crawl]!=-1)
	    {
	        d.push_back(pred[crawl]);
	        crawl = pred[crawl];
	    }
	    dest=c;
	    src=b;
	    f(i,0,n+1)
	    {
	    	pred[i]=-1;
	    	dist[i]=100000000000;
	    	visited[i]=false;
	    }
	    visited[src] = true;
	    dist[src] = 0;
	    queue1.push_back(src);
	    while(queue1.size()!=0)
	    {
	    	ll flag=0;
	        ll u = queue1.front();
	        queue1.pop_front();
	        for (ll i=0;i<v[u].size(); i++)
	        {
	            if (visited[v[u][i]] == false)
	            {
	            	//cout<<v[u][i]<<endl;
	                visited[v[u][i]] = true;
	                dist[v[u][i]] = dist[u] + 1;
	                pred[v[u][i]] = u;
	                queue1.push_back(v[u][i]);
	                if(v[u][i] == dest)
	                {
	                	flag=1;
	                    break;
	                }
	            }
	        }
	        if(flag==1)
	        break;
	    }
	    crawl = c;
	    e.push_back(crawl);
	    while (pred[crawl]!=-1)
	    {
	        e.push_back(pred[crawl]);
	        crawl = pred[crawl];
	    }
	    //cout<<d.size()<<" "<<e.size()<<endl;
	    vector<ll> ans;
        map<string,ll> m1;
        f(i,0,d.size()-1)
        {
            string s = to_string(d[i]) + 'x'+ to_string(d[i+1]);
            string s1 = to_string(d[i+1]) + 'x'+ to_string(d[i]);
            m1[s1]=0;
            m1[s]=0;

        }
        f(i,0,e.size()-1)
        {
            string s = to_string(e[i])+ 'x'+to_string(e[i+1]);
            string s1 = to_string(e[i+1]) + 'x'+ to_string(e[i]);
            m1[s]=0;
            m1[s1]=0;
        }
        f(i,0,d.size()-1)
        {
            string s = to_string(d[i]) + 'x'+ to_string(d[i+1]);
            m1[s]++;

        }
        f(i,0,e.size()-1)
        {
            string s = to_string(e[i])+ 'x'+to_string(e[i+1]);
            string s1 = to_string(e[i+1]) + 'x'+ to_string(e[i]);
            //cout<<m1[s1]<<endl;
            if(m1[s1]!=0)
            	m1[s1]++;
            else
            	m1[s]++;
            //cout<<s<<endl;
        }
        f(i,0,d.size()-1)
        {
            string s = to_string(d[i]) + 'x'+ to_string(d[i+1]);
            //cout<<m1[s]<<endl;
            if(m1[s]!=0)
            {
            	ans.pb(m1[s]);
            	m1[s]=0;
            }
        }
        f(i,0,e.size()-1)
        {
            string s = to_string(e[i]) + 'x'+ to_string(e[i+1]);
            if(m1[s]!=0)
            {
            	ans.pb(m1[s]);
            	m1[s]=0;
            }
        }
        sort(ans.begin(),ans.end());
        ll j=0,sum=0;
        for(ll i=ans.size()-1;i>=0;i--)
        {
        	sum+=ans[i]*a[j];
        	j++;
        }
        cout<<sum<<endl;
    }
    return 0;
}


////#pragma GCC optimzie(2)
//#include<iostream>
//#include<iomanip>
//#include<cstring>
//#include<string>
//#include<vector>
//#include<algorithm>
//#include<numeric>
//#include<chrono>
//#include <ctime>
//#include <ratio>
//#include<cmath>
//#include<queue>
//#include<stack>
//#include<map>
//#include<set>
//#include<iterator>
//#include<list>
//#include<forward_list>
//#include<bitset>
//#include<cassert>
//#include<unordered_map>
//#include<unordered_set>
//#define mp(a,b) make_pair(a,b)
//#define time chrono::steady_clock::now()
//#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st)
//#define v2(n,m) vector<vector<int>> (n,vector<int>(m))
//#define v1(n) vector<int>(n)
//#define pi acos(-1)
//using namespace std;
//typedef long long ll;
//typedef unsigned long long ull;
//typedef long double ldb;
//typedef double db;
//typedef pair<int,int> pii;
//typedef pair<long long,long long> pll;
//typedef priority_queue<int,vector<int>> pq;
//const int maxn = 2e3+7;
//ll a[maxn][maxn];
//int main()
//{
//    ios::sync_with_stdio(false);
//    cin.tie(0),cout.tie(0);
//    int n,m,k,q;
//    cin>>n>>m>>k>>q;
//    memset(a,0,sizeof(a));
//    while(k--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        int c=1;
//        a[x1][y1]+=c;
//        a[x2+1][y1]-=c;
//        a[x1][y2+1]-=c;
//        a[x2+1][y2+1]+=c;
//    }
////    for(int i=1;i<=n;i++) {
////        for(int j=1;j<=m;j++) {
////            cout<<a[i][j]<<' ';
////        }
////        cout<<'\n';
////    }
////    cout<<"------"<<'\n';
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    while(q--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        cout<<a[x2][y2]+a[x1-1][y1-1]-a[x2][y1-1]-a[x1-1][y2]<<'\n';
//    }
//    return 0;
//}

#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<chrono>
#include <ctime>
#include <ratio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
#include<list>
#include<forward_list>
#include<bitset>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#define mp(a,b) make_pair(a,b)
#define time chrono::steady_clock::now()
#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
const int maxn=2e5+7;
ll inf = 0x3f3f3f3f;
int mod = 998244353;

int head[maxn],cnt=0;
struct Edge{
    int u,v,val,next;
}edge[maxn<<2];
void add_edge(int u,int v,int val)
{
    edge[cnt].u = u;
    edge[cnt].v = v;
    edge[cnt].val = val;
    edge[cnt].next = head[u];
    head[u] = cnt++;
}

void dij(int root,vector<ll>& dis,vector<bool> vis) {
    fill(vis.begin(),vis.end(),0);
    fill(dis.begin(),dis.end(),inf);
    priority_queue<pll,vector<pll>,greater<pll>> que;
    dis[root]=0;
    que.push(mp(dis[root],root));
    while(!que.empty()) {
        pll p = que.top();
        que.pop();
        int u = p.second;
        if(vis[u]) continue;
        vis[u] = true;
        for(int i=head[u];i!=-1;i=edge[i].next) {
            int v = edge[i].v;
            int val = edge[i].val;
            if(dis[v]>dis[u]+val) {
                dis[v]=dis[u]+val;
                que.push(mp(dis[v],v));
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t;
    cin>>t;
    while(t--) {
        int n,m,a,b,c;
        cin>>n>>m>>a>>b>>c;
        cnt = 0;
        fill(head,head+2*m+1,-1);
        vector<int> p(m);
        vector<ll> from(n+1),to(n+1);
        vector<bool> vis(n+1);
        vector<int> choose1(m),choose2(m);
        for(auto &it:p)
            cin>>it;
        for(int i=0;i<m;i++) {
            int u,v;
            cin>>u>>v;
            add_edge(u,v,1);
            add_edge(v,u,1);
        }
        dij(a,from,vis);
        dij(b,to,vis);
        for(int i=0;i<cnt;i+=2) {
            int u,v,id;
            u = edge[i].u;
            v = edge[i].v;
            id = i/2;
            if(from[u]+to[v]+1==from[b] || from[v]+to[u]+1==from[b]) {
                choose1[id]=max(from[u],from[v]);
            }
            else
                choose1[id]=0;
        }
        dij(b,from,vis);
        dij(c,to,vis);
        for(int i=0;i<cnt;i+=2) {
            int u,v,id;
            u = edge[i].u;
            v = edge[i].v;
            id = i/2;
            if(from[u]+to[v]+1==from[c] || from[v]+to[u]+1==from[c]) {
                choose2[id]=max(from[u],from[v]);
            }
            else
                choose2[id]=0;
        }
        sort(p.begin(),p.end());
        int res = 0;
        vector<bool> vis1(m+1,0),vis2(m+1,0);
        for(int i=0;i<m;i++) {
            if(choose1[i]!=0&&choose2[i]!=0) {
                if(vis1[choose1[i]]||vis2[choose2[i]])
                    continue;
                cerr<<p[res]<<'\n';
                edge[i*2].val = p[res];
                edge[i*2+1].val = p[res++];
                vis1[choose1[i]] = 1;
                vis2[choose2[i]] = 1;
            }
        }
        cerr<<"------"<<'\n';
        for(int i=0;i<m;i++) {
            if(choose1[i]!=0||choose2[i]!=0) {
                if(vis1[choose1[i]]&&vis2[choose2[i]])
                    continue;
                cerr<<p[res]<<'\n';
                edge[i*2].val = p[res];
                edge[i*2+1].val = p[res++];
                vis1[choose1[i]] = 1;
                vis2[choose2[i]] = 1;
            }
            else {
                edge[i*2].val = 0x3f3f3f3f;
                edge[i*2+1].val = 0x3f3f3f3f;
            }
        }
        cerr<<"---------"<<'\n';
        dij(a,from,vis);
        ll ans = 0;
        ans = from[b];
        dij(b,from,vis);
        ans += from[c];
        cout<<ans<<'\n';
    }
    return 0;
}


////#pragma GCC optimzie(2)
//#include<iostream>
//#include<iomanip>
//#include<cstring>
//#include<string>
//#include<vector>
//#include<algorithm>
//#include<numeric>
//#include<chrono>
//#include <ctime>
//#include <ratio>
//#include<cmath>
//#include<queue>
//#include<stack>
//#include<map>
//#include<set>
//#include<iterator>
//#include<list>
//#include<forward_list>
//#include<bitset>
//#include<cassert>
//#include<unordered_map>
//#include<unordered_set>
//#define mp(a,b) make_pair(a,b)
//#define time chrono::steady_clock::now()
//#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st)
//#define v2(n,m) vector<vector<int>> (n,vector<int>(m))
//#define v1(n) vector<int>(n)
//#define pi acos(-1)
//using namespace std;
//typedef long long ll;
//typedef unsigned long long ull;
//typedef long double ldb;
//typedef double db;
//typedef pair<int,int> pii;
//typedef pair<long long,long long> pll;
//typedef priority_queue<int,vector<int>> pq;
//const int maxn = 2e3+7;
//ll a[maxn][maxn];
//int main()
//{
//    ios::sync_with_stdio(false);
//    cin.tie(0),cout.tie(0);
//    int n,m,k,q;
//    cin>>n>>m>>k>>q;
//    memset(a,0,sizeof(a));
//    while(k--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        int c=1;
//        a[x1][y1]+=c;
//        a[x2+1][y1]-=c;
//        a[x1][y2+1]-=c;
//        a[x2+1][y2+1]+=c;
//    }
////    for(int i=1;i<=n;i++) {
////        for(int j=1;j<=m;j++) {
////            cout<<a[i][j]<<' ';
////        }
////        cout<<'\n';
////    }
////    cout<<"------"<<'\n';
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    while(q--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        cout<<a[x2][y2]+a[x1-1][y1-1]-a[x2][y1-1]-a[x1-1][y2]<<'\n';
//    }
//    return 0;
//}

#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<chrono>
#include <ctime>
#include <ratio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
#include<list>
#include<forward_list>
#include<bitset>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#define mp(a,b) make_pair(a,b)
#define time chrono::steady_clock::now()
#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
const int maxn=2e5+7;
ll inf = 0x3f3f3f3f;
int mod = 998244353;

int head[maxn],cnt=0;
struct Edge{
    int u,v,val,next;
}edge[maxn<<2];
void add_edge(int u,int v,int val)
{
    edge[cnt].u = u;
    edge[cnt].v = v;
    edge[cnt].val = val;
    edge[cnt].next = head[u];
    head[u] = cnt++;
}

void dij(int root,vector<ll>& dis,vector<bool> vis) {
    fill(vis.begin(),vis.end(),0);
    fill(dis.begin(),dis.end(),inf);
    priority_queue<pll,vector<pll>,greater<pll>> que;
    dis[root]=0;
    que.push(mp(dis[root],root));
    while(!que.empty()) {
        pll p = que.top();
        que.pop();
        int u = p.second;
        if(vis[u]) continue;
        vis[u] = true;
        for(int i=head[u];i!=-1;i=edge[i].next) {
            int v = edge[i].v;
            int val = edge[i].val;
            if(dis[v]>dis[u]+val) {
                dis[v]=dis[u]+val;
                que.push(mp(dis[v],v));
            }
        }
    }
}
ll presum[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t;
    cin>>t;
    while(t--) {
        int n,m,a,b,c;
        cin>>n>>m>>a>>b>>c;
        cnt = 0;
        fill(head,head+n+1,-1);
        vector<int> p(m);
        vector<ll> dis1(n+1),dis2(n+1),dis3(n+1);
        vector<bool> vis(n+1);
        for(auto &it:p)
            cin>>it;
        for(int i=0;i<m;i++) {
            int u,v;
            cin>>u>>v;
            add_edge(u,v,1);
            add_edge(v,u,1);
        }
        sort(p.begin(),p.end());
        presum[0]=0;
        for(int i=1;i<=m;i++) {
            presum[i]=presum[i-1]+p[i-1];
        }
        int sum=0;
        dij(a,dis1,vis);
        dij(b,dis2,vis);
        dij(c,dis3,vis);
//        ll ans = 0;
        ll ans = numeric_limits<ll>::max();
        for(int i=1;i<=n;i++) {
//            cerr<<dis1[i]<<' '<<i<<'\n';
            int d1,d2;
            d1 = dis1[b];
            if(dis1[i]+dis2[i]==dis1[b]) {
                d2 = d1+dis3[i];
                d1 = dis2[i];
            }
            else {
                d2 = d1+dis2[i]+dis3[i];
                d1 = 0;
            }

//            cout<<i<<' '<<d1<<' '<<d2<<'\n';
            if(d2>m)
                continue;
            ans = min(ans,presum[d2]+presum[d1]);
        }
        cout<<ans<<'\n';
    }
    return 0;
}


////#pragma GCC optimzie(2)
//#include<iostream>
//#include<iomanip>
//#include<cstring>
//#include<string>
//#include<vector>
//#include<algorithm>
//#include<numeric>
//#include<chrono>
//#include <ctime>
//#include <ratio>
//#include<cmath>
//#include<queue>
//#include<stack>
//#include<map>
//#include<set>
//#include<iterator>
//#include<list>
//#include<forward_list>
//#include<bitset>
//#include<cassert>
//#include<unordered_map>
//#include<unordered_set>
//#define mp(a,b) make_pair(a,b)
//#define time chrono::steady_clock::now()
//#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st)
//#define v2(n,m) vector<vector<int>> (n,vector<int>(m))
//#define v1(n) vector<int>(n)
//#define pi acos(-1)
//using namespace std;
//typedef long long ll;
//typedef unsigned long long ull;
//typedef long double ldb;
//typedef double db;
//typedef pair<int,int> pii;
//typedef pair<long long,long long> pll;
//typedef priority_queue<int,vector<int>> pq;
//const int maxn = 2e3+7;
//ll a[maxn][maxn];
//int main()
//{
//    ios::sync_with_stdio(false);
//    cin.tie(0),cout.tie(0);
//    int n,m,k,q;
//    cin>>n>>m>>k>>q;
//    memset(a,0,sizeof(a));
//    while(k--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        int c=1;
//        a[x1][y1]+=c;
//        a[x2+1][y1]-=c;
//        a[x1][y2+1]-=c;
//        a[x2+1][y2+1]+=c;
//    }
////    for(int i=1;i<=n;i++) {
////        for(int j=1;j<=m;j++) {
////            cout<<a[i][j]<<' ';
////        }
////        cout<<'\n';
////    }
////    cout<<"------"<<'\n';
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    while(q--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        cout<<a[x2][y2]+a[x1-1][y1-1]-a[x2][y1-1]-a[x1-1][y2]<<'\n';
//    }
//    return 0;
//}

#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<chrono>
#include <ctime>
#include <ratio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
#include<list>
#include<forward_list>
#include<bitset>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#define mp(a,b) make_pair(a,b)
#define time chrono::steady_clock::now()
#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
const int maxn=2e5+7;
ll inf = 0x3f3f3f3f;
int mod = 998244353;

int head[maxn],cnt=0;
struct Edge{
    int u,v,val,next;
}edge[maxn<<2];
void add_edge(int u,int v,int val)
{
    edge[cnt].u = u;
    edge[cnt].v = v;
    edge[cnt].val = val;
    edge[cnt].next = head[u];
    head[u] = cnt++;
}

void dij(int root,vector<ll>& dis,vector<bool> vis) {
    fill(vis.begin(),vis.end(),0);
    fill(dis.begin(),dis.end(),inf);
    priority_queue<pll,vector<pll>,greater<pll>> que;
    dis[root]=0;
    que.push(mp(dis[root],root));
    while(!que.empty()) {
        pll p = que.top();
        que.pop();
        int u = p.second;
        if(vis[u]) continue;
        vis[u] = true;
        for(int i=head[u];i!=-1;i=edge[i].next) {
            int v = edge[i].v;
            int val = edge[i].val;
            if(dis[v]>dis[u]+val) {
                dis[v]=dis[u]+val;
                que.push(mp(dis[v],v));
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t;
    cin>>t;
    while(t--) {
        int n,m,a,b,c;
        cin>>n>>m>>a>>b>>c;
        cnt = 0;
        fill(head,head+n+1,-1);
        vector<int> p(m);
        vector<ll> dis1(n+1),dis2(n+1),dis3(n+1);
        vector<bool> vis(n+1);
        for(auto &it:p)
            cin>>it;
        for(int i=0;i<m;i++) {
            int u,v;
            cin>>u>>v;
            add_edge(u,v,1);
            add_edge(v,u,1);
        }
        sort(p.begin(),p.end());
        int sum=0;
        dij(a,dis1,vis);
        dij(b,dis2,vis);
        dij(c,dis3,vis);
        sum=dis1[b]+dis3[b];
        fill(vis.begin(),vis.end(),0);
        int res = 0;
        ll ans = 0;
        for(int i=0;i<m;i++) {
            int u,v,id;
            id = 2*i;
            u = edge[id].u;
            v = edge[id].v;
            if(dis1[u]+dis2[v]+1==dis1[b]||dis1[v]+dis2[u]+1==dis1[b]) {
                if(dis3[u]+dis2[v]+1==dis3[b]||dis3[v]+dis2[u]+1==dis3[b]) {
                    ans+=p[res];
                    ans+=p[res++];
                    sum-=2;
                }
            }
        }
//        cout<<res<<' '<<sum<<' '<<ans<<'\n';
        while(sum--) {
//            cerr<<p[res]<<'\n';
            ans+=p[res++];
        }
        cout<<ans<<'\n';
    }
    return 0;
}


////#pragma GCC optimzie(2)
//#include<iostream>
//#include<iomanip>
//#include<cstring>
//#include<string>
//#include<vector>
//#include<algorithm>
//#include<numeric>
//#include<chrono>
//#include <ctime>
//#include <ratio>
//#include<cmath>
//#include<queue>
//#include<stack>
//#include<map>
//#include<set>
//#include<iterator>
//#include<list>
//#include<forward_list>
//#include<bitset>
//#include<cassert>
//#include<unordered_map>
//#include<unordered_set>
//#define mp(a,b) make_pair(a,b)
//#define time chrono::steady_clock::now()
//#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st)
//#define v2(n,m) vector<vector<int>> (n,vector<int>(m))
//#define v1(n) vector<int>(n)
//#define pi acos(-1)
//using namespace std;
//typedef long long ll;
//typedef unsigned long long ull;
//typedef long double ldb;
//typedef double db;
//typedef pair<int,int> pii;
//typedef pair<long long,long long> pll;
//typedef priority_queue<int,vector<int>> pq;
//const int maxn = 2e3+7;
//ll a[maxn][maxn];
//int main()
//{
//    ios::sync_with_stdio(false);
//    cin.tie(0),cout.tie(0);
//    int n,m,k,q;
//    cin>>n>>m>>k>>q;
//    memset(a,0,sizeof(a));
//    while(k--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        int c=1;
//        a[x1][y1]+=c;
//        a[x2+1][y1]-=c;
//        a[x1][y2+1]-=c;
//        a[x2+1][y2+1]+=c;
//    }
////    for(int i=1;i<=n;i++) {
////        for(int j=1;j<=m;j++) {
////            cout<<a[i][j]<<' ';
////        }
////        cout<<'\n';
////    }
////    cout<<"------"<<'\n';
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    while(q--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        cout<<a[x2][y2]+a[x1-1][y1-1]-a[x2][y1-1]-a[x1-1][y2]<<'\n';
//    }
//    return 0;
//}

#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<chrono>
#include <ctime>
#include <ratio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
#include<list>
#include<forward_list>
#include<bitset>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#define mp(a,b) make_pair(a,b)
#define time chrono::steady_clock::now()
#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
const int maxn=2e5+7;
ll inf = 0x3f3f3f3f;
int mod = 998244353;

int head[maxn],cnt=0;
struct Edge{
    int u,v,val,next;
}edge[maxn<<2];
void add_edge(int u,int v,int val)
{
    edge[cnt].u = u;
    edge[cnt].v = v;
    edge[cnt].val = val;
    edge[cnt].next = head[u];
    head[u] = cnt++;
}

void dij(int root,vector<ll>& dis,vector<bool> vis) {
    fill(vis.begin(),vis.end(),0);
    fill(dis.begin(),dis.end(),inf);
    priority_queue<pll,vector<pll>,greater<pll>> que;
    dis[root]=0;
    que.push(mp(dis[root],root));
    while(!que.empty()) {
        pll p = que.top();
        que.pop();
        int u = p.second;
        if(vis[u]) continue;
        vis[u] = true;
        for(int i=head[u];i!=-1;i=edge[i].next) {
            int v = edge[i].v;
            int val = edge[i].val;
            if(dis[v]>dis[u]+val) {
                dis[v]=dis[u]+val;
                que.push(mp(dis[v],v));
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t;
    cin>>t;
    while(t--) {
        int n,m,a,b,c;
        cin>>n>>m>>a>>b>>c;
        cnt = 0;
        fill(head,head+n+1,-1);
        vector<int> p(m);
        vector<ll> dis1(n+1),dis2(n+1),dis3(n+1);
        vector<bool> vis(n+1);
        for(auto &it:p)
            cin>>it;
        for(int i=0;i<m;i++) {
            int u,v;
            cin>>u>>v;
            add_edge(u,v,1);
            add_edge(v,u,1);
        }
        sort(p.begin(),p.end());
        int sum=0;
        dij(a,dis1,vis);
        dij(b,dis2,vis);
        dij(c,dis3,vis);
        sum=dis1[b]+dis3[b];
        fill(vis.begin(),vis.end(),0);
        int res = 0;
        ll ans = 0;
        for(int i=0;i<m;i++) {
            int u,v,id;
            id = 2*i;
            u = edge[id].u;
            v = edge[id].v;
            if(dis1[u]+dis2[v]+1==dis1[b]||dis1[v]+dis2[u]+1==dis1[b]) {
                if(dis3[u]+dis2[v]+1==dis3[b]||dis3[v]+dis2[u]+1==dis3[b]) {
                    assert(res<m);
                    ans+=p[res];
                    ans+=p[res++];
                    sum-=2;
                }
            }
        }
//        cout<<res<<' '<<sum<<' '<<ans<<'\n';
        while(sum--) {
//            cerr<<p[res]<<'\n';
            assert(res<m);
            ans+=p[res++];
        }
        cout<<ans<<'\n';
    }
    return 0;
}


////#pragma GCC optimzie(2)
//#include<iostream>
//#include<iomanip>
//#include<cstring>
//#include<string>
//#include<vector>
//#include<algorithm>
//#include<numeric>
//#include<chrono>
//#include <ctime>
//#include <ratio>
//#include<cmath>
//#include<queue>
//#include<stack>
//#include<map>
//#include<set>
//#include<iterator>
//#include<list>
//#include<forward_list>
//#include<bitset>
//#include<cassert>
//#include<unordered_map>
//#include<unordered_set>
//#define mp(a,b) make_pair(a,b)
//#define time chrono::steady_clock::now()
//#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st)
//#define v2(n,m) vector<vector<int>> (n,vector<int>(m))
//#define v1(n) vector<int>(n)
//#define pi acos(-1)
//using namespace std;
//typedef long long ll;
//typedef unsigned long long ull;
//typedef long double ldb;
//typedef double db;
//typedef pair<int,int> pii;
//typedef pair<long long,long long> pll;
//typedef priority_queue<int,vector<int>> pq;
//const int maxn = 2e3+7;
//ll a[maxn][maxn];
//int main()
//{
//    ios::sync_with_stdio(false);
//    cin.tie(0),cout.tie(0);
//    int n,m,k,q;
//    cin>>n>>m>>k>>q;
//    memset(a,0,sizeof(a));
//    while(k--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        int c=1;
//        a[x1][y1]+=c;
//        a[x2+1][y1]-=c;
//        a[x1][y2+1]-=c;
//        a[x2+1][y2+1]+=c;
//    }
////    for(int i=1;i<=n;i++) {
////        for(int j=1;j<=m;j++) {
////            cout<<a[i][j]<<' ';
////        }
////        cout<<'\n';
////    }
////    cout<<"------"<<'\n';
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    while(q--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        cout<<a[x2][y2]+a[x1-1][y1-1]-a[x2][y1-1]-a[x1-1][y2]<<'\n';
//    }
//    return 0;
//}

#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<chrono>
#include <ctime>
#include <ratio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
#include<list>
#include<forward_list>
#include<bitset>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#define mp(a,b) make_pair(a,b)
#define time chrono::steady_clock::now()
#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
const int maxn=2e5+7;
ll inf = 0x3f3f3f3f;
int mod = 998244353;

int head[maxn],cnt=0;
struct Edge{
    int u,v,val,next;
}edge[maxn<<2];
void add_edge(int u,int v,int val)
{
    edge[cnt].u = u;
    edge[cnt].v = v;
    edge[cnt].val = val;
    edge[cnt].next = head[u];
    head[u] = cnt++;
}

void dij(int root,vector<ll>& dis,vector<bool> vis) {
    fill(vis.begin(),vis.end(),0);
    fill(dis.begin(),dis.end(),inf);
    priority_queue<pll,vector<pll>,greater<pll>> que;
    dis[root]=0;
    que.push(mp(dis[root],root));
    while(!que.empty()) {
        pll p = que.top();
        que.pop();
        int u = p.second;
        if(vis[u]) continue;
        vis[u] = true;
        for(int i=head[u];i!=-1;i=edge[i].next) {
            int v = edge[i].v;
            int val = edge[i].val;
            if(dis[v]>dis[u]+val) {
                dis[v]=dis[u]+val;
                que.push(mp(dis[v],v));
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t;
    cin>>t;
    while(t--) {
        int n,m,a,b,c;
        cin>>n>>m>>a>>b>>c;
        cnt = 0;
        fill(head,head+n+1,-1);
        vector<int> p(m);
        vector<ll> dis1(n+1),dis2(n+1);
        vector<bool> vis(n+1);
        vector<int> choose1(m),choose2(m);
        for(auto &it:p)
            cin>>it;
        for(int i=0;i<m;i++) {
            int u,v;
            cin>>u>>v;
            add_edge(u,v,1);
            add_edge(v,u,1);
        }
        cerr<<"start"<<'\n';
        dij(a,dis1,vis);
        dij(b,dis2,vis);
        vector<int> book1(m,0),book2(m,0);
        for(int i=0;i<m;i++) {
            int id = 2*i;
            int u,v;
            u = edge[id].u;
            v = edge[id].v;
            if(dis1[u]+dis2[v]+1==dis1[b]||dis1[v]+dis2[u]+1==dis1[b]) {
                int val = max(dis1[u],dis1[v]);
                cerr<<u<<' '<<v<<' '<<val<<'\n';
                book1[i]=val;
            }
        }
        cerr<<"---------"<<'\n';
        dij(b,dis1,vis);
        dij(c,dis2,vis);
        for(int i=0;i<m;i++) {
            int id = 2*i;
            int u,v;
            u = edge[id].u;
            v = edge[id].v;
            if(dis1[u]+dis2[v]+1==dis1[c]||dis1[v]+dis2[u]+1==dis1[c]) {
                int val = max(dis1[u],dis1[v]);
                cerr<<u<<' '<<v<<' '<<val<<'\n';
                book2[i]=val;
            }
        }
        cerr<<"---------"<<'\n';
        sort(p.begin(),p.end());
        vector<int> vis1(n+1,0),vis2(n+1,0);
        ll ans = 0;
        int res = 0;
        for(int i=0;i<m;i++) {
            int id=2*i;
            if(book1[i]&&book2[i]) { // in a-> b and b -> c
                assert(book1[i]<=n&&book2[i]<=n);
                if(vis1[book1[i]]||vis2[book2[i]])
                    continue;
                vis1[book1[i]] = 1;
                vis2[book2[i]] = 1;
                ans+=p[res];
                ans+=p[res++];
                cerr<<edge[id].u<<' '<<edge[id].v<<'\n';
            }
        }
        cerr<<"-------"<<'\n';
        for(int i=0;i<m;i++) {
            if(vis1[book1[i]]||vis2[book2[i]]) { // in a-> b and b -> c
                continue;
            }
            else if(book1[i]&&!vis1[book1[i]]) {
                ans+=p[res++];
                vis1[book1[i]]=1;
            }
            else if(book2[i]&&!vis2[book2[i]]) {
                ans+=p[res++];
                vis2[book2[i]]=1;
            }
        }
        cout<<ans<<'\n';
    }
    return 0;
}


////#pragma GCC optimzie(2)
//#include<iostream>
//#include<iomanip>
//#include<cstring>
//#include<string>
//#include<vector>
//#include<algorithm>
//#include<numeric>
//#include<chrono>
//#include <ctime>
//#include <ratio>
//#include<cmath>
//#include<queue>
//#include<stack>
//#include<map>
//#include<set>
//#include<iterator>
//#include<list>
//#include<forward_list>
//#include<bitset>
//#include<cassert>
//#include<unordered_map>
//#include<unordered_set>
//#define mp(a,b) make_pair(a,b)
//#define time chrono::steady_clock::now()
//#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st)
//#define v2(n,m) vector<vector<int>> (n,vector<int>(m))
//#define v1(n) vector<int>(n)
//#define pi acos(-1)
//using namespace std;
//typedef long long ll;
//typedef unsigned long long ull;
//typedef long double ldb;
//typedef double db;
//typedef pair<int,int> pii;
//typedef pair<long long,long long> pll;
//typedef priority_queue<int,vector<int>> pq;
//const int maxn = 2e3+7;
//ll a[maxn][maxn];
//int main()
//{
//    ios::sync_with_stdio(false);
//    cin.tie(0),cout.tie(0);
//    int n,m,k,q;
//    cin>>n>>m>>k>>q;
//    memset(a,0,sizeof(a));
//    while(k--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        int c=1;
//        a[x1][y1]+=c;
//        a[x2+1][y1]-=c;
//        a[x1][y2+1]-=c;
//        a[x2+1][y2+1]+=c;
//    }
////    for(int i=1;i<=n;i++) {
////        for(int j=1;j<=m;j++) {
////            cout<<a[i][j]<<' ';
////        }
////        cout<<'\n';
////    }
////    cout<<"------"<<'\n';
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    while(q--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        cout<<a[x2][y2]+a[x1-1][y1-1]-a[x2][y1-1]-a[x1-1][y2]<<'\n';
//    }
//    return 0;
//}

#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<chrono>
#include <ctime>
#include <ratio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
#include<list>
#include<forward_list>
#include<bitset>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#define mp(a,b) make_pair(a,b)
#define time chrono::steady_clock::now()
#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
const int maxn=2e5+7;
ll inf = 0x3f3f3f3f;
int mod = 998244353;

int head[maxn],cnt=0;
struct Edge{
    int u,v,val,next;
}edge[maxn<<2];
void add_edge(int u,int v,int val)
{
    edge[cnt].u = u;
    edge[cnt].v = v;
    edge[cnt].val = val;
    edge[cnt].next = head[u];
    head[u] = cnt++;
}

void dij(int root,vector<ll>& dis,vector<bool> vis) {
    fill(vis.begin(),vis.end(),0);
    fill(dis.begin(),dis.end(),inf);
    priority_queue<pll,vector<pll>,greater<>> que;
    dis[root]=0;
    que.push(mp(dis[root],root));
    while(!que.empty()) {
        pll p = que.top();
        que.pop();
        int u = p.second;
        if(vis[u]) continue;
        vis[u] = true;
        for(int i=head[u];i!=-1;i=edge[i].next) {
            int v = edge[i].v;
            int val = edge[i].val;
            if(dis[v]>dis[u]+val) {
                dis[v]=dis[u]+val;
                que.push(mp(dis[v],v));
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t;
    cin>>t;
    while(t--) {
        int n,m,a,b,c;
        cin>>n>>m>>a>>b>>c;
        cnt = 0;
        fill(head,head+2*m+1,-1);
        vector<int> p(m);
        vector<ll> from(n+1),to(n+1);
        vector<bool> vis(n+1);
        vector<int> choose1(m),choose2(m);
        for(auto &it:p)
            cin>>it;
        for(int i=0;i<m;i++) {
            int u,v;
            cin>>u>>v;
            add_edge(u,v,1);
            add_edge(v,u,1);
        }
        dij(a,from,vis);
        dij(b,to,vis);
        for(int i=0;i<cnt;i+=2) {
            int u,v,id;
            u = edge[i].u;
            v = edge[i].v;
            id = i/2;
            if(from[u]+to[v]+1==from[b] || from[v]+to[u]+1==from[b]) {
                choose1[id]=max(from[u],from[v]);
//                cout<<u<<' '<<v<<' '<<id<<'\n';
            }
            else
                choose1[id]=0;
        }
        dij(b,from,vis);
        dij(c,to,vis);
        for(int i=0;i<cnt;i+=2) {
            int u,v,id;
            u = edge[i].u;
            v = edge[i].v;
            id = i/2;
            if(from[u]+to[v]+1==from[c] || from[v]+to[u]+1==from[c]) {
                choose2[id]=max(from[u],from[v]);
            }
            else
                choose2[id]=0;
        }
        sort(p.begin(),p.end());
        int res = 0;
        vector<bool> vis1(m+1,0),vis2(m+1,0);
        for(int i=0;i<m;i++) {
            if(choose1[i]!=0&&choose2[i]!=0) {
                if(vis1[choose1[i]]||vis2[choose2[i]])
                    continue;
//                cout<<p[res]<<'\n';
                edge[i*2].val = p[res];
                edge[i*2+1].val = p[res++];
                vis1[choose1[i]] = 1;
                vis2[choose2[i]] = 1;
            }
        }
//        cout<<"------"<<'\n';
        for(int i=0;i<m;i++) {
            if(choose1[i]!=0||choose2[i]!=0) {
                if(vis1[choose1[i]]&&vis2[choose2[i]])
                    continue;
//                cout<<p[res]<<'\n';
                edge[i*2].val = p[res];
                edge[i*2+1].val = p[res++];
                vis1[choose1[i]] = 1;
                vis2[choose2[i]] = 1;
            }
            else {
                edge[i*2].val = 0x3f3f3f3f;
                edge[i*2+1].val = 0x3f3f3f3f;
            }
        }
        dij(a,from,vis);
        ll ans = 0;
        ans = from[b];
        dij(b,from,vis);
        ans += from[c];
        cout<<ans<<'\n';
    }
    return 0;
}


////#pragma GCC optimzie(2)
//#include<iostream>
//#include<iomanip>
//#include<cstring>
//#include<string>
//#include<vector>
//#include<algorithm>
//#include<numeric>
//#include<chrono>
//#include <ctime>
//#include <ratio>
//#include<cmath>
//#include<queue>
//#include<stack>
//#include<map>
//#include<set>
//#include<iterator>
//#include<list>
//#include<forward_list>
//#include<bitset>
//#include<cassert>
//#include<unordered_map>
//#include<unordered_set>
//#define mp(a,b) make_pair(a,b)
//#define time chrono::steady_clock::now()
//#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st)
//#define v2(n,m) vector<vector<int>> (n,vector<int>(m))
//#define v1(n) vector<int>(n)
//#define pi acos(-1)
//using namespace std;
//typedef long long ll;
//typedef unsigned long long ull;
//typedef long double ldb;
//typedef double db;
//typedef pair<int,int> pii;
//typedef pair<long long,long long> pll;
//typedef priority_queue<int,vector<int>> pq;
//const int maxn = 2e3+7;
//ll a[maxn][maxn];
//int main()
//{
//    ios::sync_with_stdio(false);
//    cin.tie(0),cout.tie(0);
//    int n,m,k,q;
//    cin>>n>>m>>k>>q;
//    memset(a,0,sizeof(a));
//    while(k--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        int c=1;
//        a[x1][y1]+=c;
//        a[x2+1][y1]-=c;
//        a[x1][y2+1]-=c;
//        a[x2+1][y2+1]+=c;
//    }
////    for(int i=1;i<=n;i++) {
////        for(int j=1;j<=m;j++) {
////            cout<<a[i][j]<<' ';
////        }
////        cout<<'\n';
////    }
////    cout<<"------"<<'\n';
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    while(q--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        cout<<a[x2][y2]+a[x1-1][y1-1]-a[x2][y1-1]-a[x1-1][y2]<<'\n';
//    }
//    return 0;
//}

#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<chrono>
#include <ctime>
#include <ratio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
#include<list>
#include<forward_list>
#include<bitset>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#define mp(a,b) make_pair(a,b)
#define time chrono::steady_clock::now()
#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
const int maxn=2e5+7;
ll inf = 0x3f3f3f3f;
int mod = 998244353;

int head[maxn],cnt=0;
struct Edge{
    int u,v,val,next;
}edge[maxn<<2];
void add_edge(int u,int v,int val)
{
    edge[cnt].u = u;
    edge[cnt].v = v;
    edge[cnt].val = val;
    edge[cnt].next = head[u];
    head[u] = cnt++;
}

void dij(int root,vector<ll>& dis,vector<bool> vis) {
    fill(vis.begin(),vis.end(),0);
    fill(dis.begin(),dis.end(),inf);
    priority_queue<pll,vector<pll>,greater<pll>> que;
    dis[root]=0;
    que.push(mp(dis[root],root));
    while(!que.empty()) {
        pll p = que.top();
        que.pop();
        int u = p.second;
        if(vis[u]) continue;
        vis[u] = true;
        for(int i=head[u];i!=-1;i=edge[i].next) {
            int v = edge[i].v;
            int val = edge[i].val;
            if(dis[v]>dis[u]+val) {
                dis[v]=dis[u]+val;
                que.push(mp(dis[v],v));
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t;
    cin>>t;
    while(t--) {
        int n,m,a,b,c;
        cin>>n>>m>>a>>b>>c;
        cnt = 0;
        fill(head,head+2*m+1,-1);
        vector<int> p(m);
        vector<ll> dis1(n+1),dis2(n+1);
        vector<bool> vis(n+1);
        vector<int> choose1(m),choose2(m);
        for(auto &it:p)
            cin>>it;
        for(int i=0;i<m;i++) {
            int u,v;
            cin>>u>>v;
            add_edge(u,v,1);
            add_edge(v,u,1);
        }
        cerr<<"start"<<'\n';
        dij(a,dis1,vis);
        dij(b,dis2,vis);
        vector<int> book1(m,0),book2(m,0);
        for(int i=0;i<m;i++) {
            int id = 2*i;
            int u,v;
            u = edge[id].u;
            v = edge[id].v;
            if(dis1[u]+dis2[v]+1==dis1[b]||dis1[v]+dis2[u]+1==dis1[b]) {
                int val = max(dis1[u],dis1[v]);
                cerr<<u<<' '<<v<<' '<<val<<'\n';
                book1[i]=val;
            }
        }
        cerr<<"---------"<<'\n';
        dij(b,dis1,vis);
        dij(c,dis2,vis);
        for(int i=0;i<m;i++) {
            int id = 2*i;
            int u,v;
            u = edge[id].u;
            v = edge[id].v;
            if(dis1[u]+dis2[v]+1==dis1[c]||dis1[v]+dis2[u]+1==dis1[c]) {
                int val = max(dis1[u],dis1[v]);
                cerr<<u<<' '<<v<<' '<<val<<'\n';
                book2[i]=val;
            }
        }
        cerr<<"---------"<<'\n';
        sort(p.begin(),p.end());
        vector<int> vis1(n+1,0),vis2(n+1,0);
        ll ans = 0;
        int res = 0;
        for(int i=0;i<m;i++) {
            int id=2*i;
            if(book1[i]&&book2[i]) { // in a-> b and b -> c
                assert(book1[i]<=n&&book2[i]<=n);
                if(vis1[book1[i]]||vis2[book2[i]])
                    continue;
                vis1[book1[i]] = 1;
                vis2[book2[i]] = 1;
                ans+=p[res];
                ans+=p[res++];
                cerr<<edge[id].u<<' '<<edge[id].v<<'\n';
            }
        }
        cerr<<"-------"<<'\n';
        for(int i=0;i<m;i++) {
            if(vis1[book1[i]]||vis2[book2[i]]) { // in a-> b and b -> c
                continue;
            }
            else if(book1[i]&&!vis1[book1[i]]) {
                ans+=p[res++];
                vis1[book1[i]]=1;
            }
            else if(book2[i]&&!vis2[book2[i]]) {
                ans+=p[res++];
                vis2[book2[i]]=1;
            }
        }
        cout<<ans<<'\n';
    }
    return 0;
}


////#pragma GCC optimzie(2)
//#include<iostream>
//#include<iomanip>
//#include<cstring>
//#include<string>
//#include<vector>
//#include<algorithm>
//#include<numeric>
//#include<chrono>
//#include <ctime>
//#include <ratio>
//#include<cmath>
//#include<queue>
//#include<stack>
//#include<map>
//#include<set>
//#include<iterator>
//#include<list>
//#include<forward_list>
//#include<bitset>
//#include<cassert>
//#include<unordered_map>
//#include<unordered_set>
//#define mp(a,b) make_pair(a,b)
//#define time chrono::steady_clock::now()
//#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st)
//#define v2(n,m) vector<vector<int>> (n,vector<int>(m))
//#define v1(n) vector<int>(n)
//#define pi acos(-1)
//using namespace std;
//typedef long long ll;
//typedef unsigned long long ull;
//typedef long double ldb;
//typedef double db;
//typedef pair<int,int> pii;
//typedef pair<long long,long long> pll;
//typedef priority_queue<int,vector<int>> pq;
//const int maxn = 2e3+7;
//ll a[maxn][maxn];
//int main()
//{
//    ios::sync_with_stdio(false);
//    cin.tie(0),cout.tie(0);
//    int n,m,k,q;
//    cin>>n>>m>>k>>q;
//    memset(a,0,sizeof(a));
//    while(k--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        int c=1;
//        a[x1][y1]+=c;
//        a[x2+1][y1]-=c;
//        a[x1][y2+1]-=c;
//        a[x2+1][y2+1]+=c;
//    }
////    for(int i=1;i<=n;i++) {
////        for(int j=1;j<=m;j++) {
////            cout<<a[i][j]<<' ';
////        }
////        cout<<'\n';
////    }
////    cout<<"------"<<'\n';
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    while(q--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        cout<<a[x2][y2]+a[x1-1][y1-1]-a[x2][y1-1]-a[x1-1][y2]<<'\n';
//    }
//    return 0;
//}

#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<chrono>
#include <ctime>
#include <ratio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
#include<list>
#include<forward_list>
#include<bitset>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#define mp(a,b) make_pair(a,b)
#define time chrono::steady_clock::now()
#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
const int maxn=2e5+7;
ll inf = 0x3f3f3f3f;
int mod = 998244353;

int head[maxn],cnt=0;
struct Edge{
    int u,v,val,next;
}edge[maxn<<2];
void add_edge(int u,int v,int val)
{
    edge[cnt].u = u;
    edge[cnt].v = v;
    edge[cnt].val = val;
    edge[cnt].next = head[u];
    head[u] = cnt++;
}

void dij(int root,vector<ll>& dis,vector<bool> vis) {
    fill(vis.begin(),vis.end(),0);
    fill(dis.begin(),dis.end(),inf);
    priority_queue<pll,vector<pll>,greater<pll>> que;
    dis[root]=0;
    que.push(mp(dis[root],root));
    while(!que.empty()) {
        pll p = que.top();
        que.pop();
        int u = p.second;
        if(vis[u]) continue;
        vis[u] = true;
        for(int i=head[u];i!=-1;i=edge[i].next) {
            int v = edge[i].v;
            int val = edge[i].val;
            if(dis[v]>dis[u]+val) {
                dis[v]=dis[u]+val;
                que.push(mp(dis[v],v));
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t;
    cin>>t;
    while(t--) {
        int n,m,a,b,c;
        cin>>n>>m>>a>>b>>c;
        cnt = 0;
        fill(head,head+n+1,-1);
        vector<int> p(m);
        vector<ll> dis1(n+1),dis2(n+1),dis3(n+1);
        vector<bool> vis(n+1);
        for(auto &it:p)
            cin>>it;
        for(int i=0;i<m;i++) {
            int u,v;
            cin>>u>>v;
            add_edge(u,v,1);
            add_edge(v,u,1);
        }
        sort(p.begin(),p.end());
        int sum=0;
        dij(a,dis1,vis);
        dij(b,dis2,vis);
        dij(c,dis3,vis);
        sum=dis1[b]+dis3[b];
        fill(vis.begin(),vis.end(),0);
        int res = 0;
        ll ans = 0;
        for(int i=0;i<m;i++) {
            int u,v,id;
            id = 2*i;
            u = edge[id].u;
            v = edge[id].v;
            if(dis1[u]+dis2[v]+1==dis1[b]||dis1[v]+dis2[u]+1==dis1[b]) {
                if(dis3[u]+dis2[v]+1==dis3[b]||dis3[v]+dis2[u]+1==dis3[b]) {
                    if(!!vis[max(dis1[u],dis1[v])])
                        continue;
                    assert(res<m);
                    ans+=p[res];
                    vis[max(dis1[u],dis1[v])] = 1;
                    ans+=p[res++];
                    sum-=2;
                }
            }
        }
//        cout<<res<<' '<<sum<<' '<<ans<<'\n';
        while(sum>0) {
//            cerr<<p[res]<<'\n';
            assert(res<m);
            sum--;
            ans+=p[res++];
        }
        cout<<ans<<'\n';
    }
    return 0;
}


////#pragma GCC optimzie(2)
//#include<iostream>
//#include<iomanip>
//#include<cstring>
//#include<string>
//#include<vector>
//#include<algorithm>
//#include<numeric>
//#include<chrono>
//#include <ctime>
//#include <ratio>
//#include<cmath>
//#include<queue>
//#include<stack>
//#include<map>
//#include<set>
//#include<iterator>
//#include<list>
//#include<forward_list>
//#include<bitset>
//#include<cassert>
//#include<unordered_map>
//#include<unordered_set>
//#define mp(a,b) make_pair(a,b)
//#define time chrono::steady_clock::now()
//#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st)
//#define v2(n,m) vector<vector<int>> (n,vector<int>(m))
//#define v1(n) vector<int>(n)
//#define pi acos(-1)
//using namespace std;
//typedef long long ll;
//typedef unsigned long long ull;
//typedef long double ldb;
//typedef double db;
//typedef pair<int,int> pii;
//typedef pair<long long,long long> pll;
//typedef priority_queue<int,vector<int>> pq;
//const int maxn = 2e3+7;
//ll a[maxn][maxn];
//int main()
//{
//    ios::sync_with_stdio(false);
//    cin.tie(0),cout.tie(0);
//    int n,m,k,q;
//    cin>>n>>m>>k>>q;
//    memset(a,0,sizeof(a));
//    while(k--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        int c=1;
//        a[x1][y1]+=c;
//        a[x2+1][y1]-=c;
//        a[x1][y2+1]-=c;
//        a[x2+1][y2+1]+=c;
//    }
////    for(int i=1;i<=n;i++) {
////        for(int j=1;j<=m;j++) {
////            cout<<a[i][j]<<' ';
////        }
////        cout<<'\n';
////    }
////    cout<<"------"<<'\n';
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    while(q--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        cout<<a[x2][y2]+a[x1-1][y1-1]-a[x2][y1-1]-a[x1-1][y2]<<'\n';
//    }
//    return 0;
//}

#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<chrono>
#include <ctime>
#include <ratio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
#include<list>
#include<forward_list>
#include<bitset>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#define mp(a,b) make_pair(a,b)
#define time chrono::steady_clock::now()
#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
const int maxn=2e5+7;
ll inf = 0x3f3f3f3f;
int mod = 998244353;

int head[maxn],cnt=0;
struct Edge{
    int u,v,val,next;
}edge[maxn<<2];
void add_edge(int u,int v,int val)
{
    edge[cnt].u = u;
    edge[cnt].v = v;
    edge[cnt].val = val;
    edge[cnt].next = head[u];
    head[u] = cnt++;
}

void dij(int root,vector<ll>& dis,vector<bool> vis) {
    fill(vis.begin(),vis.end(),0);
    fill(dis.begin(),dis.end(),inf);
    priority_queue<pll,vector<pll>,greater<pll>> que;
    dis[root]=0;
    que.push(mp(dis[root],root));
    while(!que.empty()) {
        pll p = que.top();
        que.pop();
        int u = p.second;
        if(vis[u]) continue;
        vis[u] = true;
        for(int i=head[u];i!=-1;i=edge[i].next) {
            int v = edge[i].v;
            int val = edge[i].val;
            if(dis[v]>dis[u]+val) {
                dis[v]=dis[u]+val;
                que.push(mp(dis[v],v));
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t;
    cin>>t;
    while(t--) {
        int n,m,a,b,c;
        cin>>n>>m>>a>>b>>c;
        cnt = 0;
        fill(head,head+n+1,-1);
        vector<int> p(m);
        vector<ll> dis1(n+1),dis2(n+1);
        vector<bool> vis(n+1);
        for(auto &it:p)
            cin>>it;
        for(int i=0;i<m;i++) {
            int u,v;
            cin>>u>>v;
            add_edge(u,v,1);
            add_edge(v,u,1);
        }
//        cerr<<"start"<<'\n';
        dij(a,dis1,vis);
        dij(b,dis2,vis);
        vector<int> book1(m,0),book2(m,0);
        for(int i=0;i<m;i++) {
            int id = 2*i;
            int u,v;
            u = edge[id].u;
            v = edge[id].v;
            if(dis1[u]+dis2[v]+1==dis1[b]||dis1[v]+dis2[u]+1==dis1[b]) {
                int val = max(dis1[u],dis1[v]);
//                cerr<<u<<' '<<v<<' '<<val<<'\n';
                book1[i]=val;
            }
        }
//        cerr<<"---------"<<'\n';
        dij(b,dis1,vis);
        dij(c,dis2,vis);
        for(int i=0;i<m;i++) {
            int id = 2*i;
            int u,v;
            u = edge[id].u;
            v = edge[id].v;
            if(dis1[u]+dis2[v]+1==dis1[c]||dis1[v]+dis2[u]+1==dis1[c]) {
                int val = max(dis1[u],dis1[v]);
//                cerr<<u<<' '<<v<<' '<<val<<'\n';
                book2[i]=val;
            }
        }
//        cerr<<"---------"<<'\n';
        sort(p.begin(),p.end());
        vector<bool> vis1(n+1,0),vis2(n+1,0);
        ll ans = 0;
        int res = 0;
        for(int i=0;i<m;i++) {
            int id=2*i;
            if(book1[i]&&book2[i]) { // in a-> b and b -> c
//                assert(book1[i]<=n&&book2[i]<=n);
                if(vis1[book1[i]]||vis2[book2[i]])
                    continue;
                vis1[book1[i]] = 1;
                vis2[book2[i]] = 1;
                ans+=p[res];
                ans+=p[res++];
//                cerr<<edge[id].u<<' '<<edge[id].v<<'\n';
            }
        }
//        cerr<<"-------"<<'\n';
        for(int i=0;i<m;i++) {
            if(vis1[book1[i]]||vis2[book2[i]]) { // in a-> b and b -> c
                continue;
            }
            else if(book1[i]&&!vis1[book1[i]]) {
                ans+=p[res++];
                vis1[book1[i]]=1;
            }
            else if(book2[i]&&!vis2[book2[i]]) {
                ans+=p[res++];
                vis2[book2[i]]=1;
            }
        }
        cout<<ans<<'\n';
    }
    return 0;
}


////#pragma GCC optimzie(2)
//#include<iostream>
//#include<iomanip>
//#include<cstring>
//#include<string>
//#include<vector>
//#include<algorithm>
//#include<numeric>
//#include<chrono>
//#include <ctime>
//#include <ratio>
//#include<cmath>
//#include<queue>
//#include<stack>
//#include<map>
//#include<set>
//#include<iterator>
//#include<list>
//#include<forward_list>
//#include<bitset>
//#include<cassert>
//#include<unordered_map>
//#include<unordered_set>
//#define mp(a,b) make_pair(a,b)
//#define time chrono::steady_clock::now()
//#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st)
//#define v2(n,m) vector<vector<int>> (n,vector<int>(m))
//#define v1(n) vector<int>(n)
//#define pi acos(-1)
//using namespace std;
//typedef long long ll;
//typedef unsigned long long ull;
//typedef long double ldb;
//typedef double db;
//typedef pair<int,int> pii;
//typedef pair<long long,long long> pll;
//typedef priority_queue<int,vector<int>> pq;
//const int maxn = 2e3+7;
//ll a[maxn][maxn];
//int main()
//{
//    ios::sync_with_stdio(false);
//    cin.tie(0),cout.tie(0);
//    int n,m,k,q;
//    cin>>n>>m>>k>>q;
//    memset(a,0,sizeof(a));
//    while(k--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        int c=1;
//        a[x1][y1]+=c;
//        a[x2+1][y1]-=c;
//        a[x1][y2+1]-=c;
//        a[x2+1][y2+1]+=c;
//    }
////    for(int i=1;i<=n;i++) {
////        for(int j=1;j<=m;j++) {
////            cout<<a[i][j]<<' ';
////        }
////        cout<<'\n';
////    }
////    cout<<"------"<<'\n';
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    while(q--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        cout<<a[x2][y2]+a[x1-1][y1-1]-a[x2][y1-1]-a[x1-1][y2]<<'\n';
//    }
//    return 0;
//}

#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<chrono>
#include <ctime>
#include <ratio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
#include<list>
#include<forward_list>
#include<bitset>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#define mp(a,b) make_pair(a,b)
#define time chrono::steady_clock::now()
#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
const int maxn=2e5+7;
ll inf = 0x3f3f3f3f;
int mod = 998244353;

int head[maxn],cnt=0;
struct Edge{
    int u,v,val,next;
}edge[maxn<<2];
void add_edge(int u,int v,int val)
{
    edge[cnt].u = u;
    edge[cnt].v = v;
    edge[cnt].val = val;
    edge[cnt].next = head[u];
    head[u] = cnt++;
}

void dij(int root,vector<ll>& dis,vector<bool> vis) {
    fill(vis.begin(),vis.end(),0);
    fill(dis.begin(),dis.end(),inf);
    priority_queue<pll,vector<pll>,greater<pll>> que;
    dis[root]=0;
    que.push(mp(dis[root],root));
    while(!que.empty()) {
        pll p = que.top();
        que.pop();
        int u = p.second;
        if(vis[u]) continue;
        vis[u] = true;
        for(int i=head[u];i!=-1;i=edge[i].next) {
            int v = edge[i].v;
            int val = edge[i].val;
            if(dis[v]>dis[u]+val) {
                dis[v]=dis[u]+val;
                que.push(mp(dis[v],v));
            }
        }
    }
}
ll presum[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t;
    cin>>t;
    while(t--) {
        int n,m,a,b,c;
        cin>>n>>m>>a>>b>>c;
        cnt = 0;
        fill(head,head+n+1,-1);
        vector<int> p(m);
        vector<ll> dis1(n+1),dis2(n+1),dis3(n+1);
        vector<bool> vis(n+1);
        for(auto &it:p)
            cin>>it;
        for(int i=0;i<m;i++) {
            int u,v;
            cin>>u>>v;
            add_edge(u,v,1);
            add_edge(v,u,1);
        }
        sort(p.begin(),p.end());
        presum[0]=0;
        for(int i=1;i<=m;i++) {
            presum[i]=presum[i-1]+p[i-1];
        }
        int sum=0;
        dij(a,dis1,vis);
        dij(b,dis2,vis);
        dij(c,dis3,vis);
        ll ans = numeric_limits<ll>::max();
//        for(int i=1;i<=n;i++) {  // wa solution
//            int d1,d2;
//            d1 = dis1[b];
//            if(dis1[i]+dis2[i]==dis1[b]) {
//                d2 = d1+dis3[i];
//                d1 = dis2[i];
//            }
//            else {
//                d2 = d1+dis2[i]+dis3[i];
//                d1 = 0;
//            }
//            if(d2>m)
//                continue;
//            ans = min(ans,presum[d2]+presum[d1]);
//        }
        for(int i=1;i<=n;i++) {
            int d1,d2;
            d1 = dis2[i];
            d2 = dis1[i]+dis3[i]+d1;
//            cout<<i<<' '<<d1<<" "<<d2<<'\n';
            if(d1>m||d2>m)
                continue;
            ans = min(ans,presum[d2]+presum[d1]);

        }
        cout<<ans<<'\n';
    }
    return 0;
}


////#pragma GCC optimzie(2)
//#include<iostream>
//#include<iomanip>
//#include<cstring>
//#include<string>
//#include<vector>
//#include<algorithm>
//#include<numeric>
//#include<chrono>
//#include <ctime>
//#include <ratio>
//#include<cmath>
//#include<queue>
//#include<stack>
//#include<map>
//#include<set>
//#include<iterator>
//#include<list>
//#include<forward_list>
//#include<bitset>
//#include<cassert>
//#include<unordered_map>
//#include<unordered_set>
//#define mp(a,b) make_pair(a,b)
//#define time chrono::steady_clock::now()
//#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st)
//#define v2(n,m) vector<vector<int>> (n,vector<int>(m))
//#define v1(n) vector<int>(n)
//#define pi acos(-1)
//using namespace std;
//typedef long long ll;
//typedef unsigned long long ull;
//typedef long double ldb;
//typedef double db;
//typedef pair<int,int> pii;
//typedef pair<long long,long long> pll;
//typedef priority_queue<int,vector<int>> pq;
//const int maxn = 2e3+7;
//ll a[maxn][maxn];
//int main()
//{
//    ios::sync_with_stdio(false);
//    cin.tie(0),cout.tie(0);
//    int n,m,k,q;
//    cin>>n>>m>>k>>q;
//    memset(a,0,sizeof(a));
//    while(k--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        int c=1;
//        a[x1][y1]+=c;
//        a[x2+1][y1]-=c;
//        a[x1][y2+1]-=c;
//        a[x2+1][y2+1]+=c;
//    }
////    for(int i=1;i<=n;i++) {
////        for(int j=1;j<=m;j++) {
////            cout<<a[i][j]<<' ';
////        }
////        cout<<'\n';
////    }
////    cout<<"------"<<'\n';
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    while(q--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        cout<<a[x2][y2]+a[x1-1][y1-1]-a[x2][y1-1]-a[x1-1][y2]<<'\n';
//    }
//    return 0;
//}

#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<chrono>
#include <ctime>
#include <ratio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
#include<list>
#include<forward_list>
#include<bitset>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#define mp(a,b) make_pair(a,b)
#define time chrono::steady_clock::now()
#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
const int maxn=2e5+7;
ll inf = 0x3f3f3f3f;
int mod = 998244353;

int head[maxn],cnt=0;
struct Edge{
    int u,v,val,next;
}edge[maxn<<2];
void add_edge(int u,int v,int val)
{
    edge[cnt].u = u;
    edge[cnt].v = v;
    edge[cnt].val = val;
    edge[cnt].next = head[u];
    head[u] = cnt++;
}

void dij(int root,vector<ll>& dis,vector<bool> vis) {
    fill(vis.begin(),vis.end(),0);
    fill(dis.begin(),dis.end(),inf);
    priority_queue<pll,vector<pll>,greater<pll>> que;
    dis[root]=0;
    que.push(mp(dis[root],root));
    while(!que.empty()) {
        pll p = que.top();
        que.pop();
        int u = p.second;
        if(vis[u]) continue;
        vis[u] = true;
        for(int i=head[u];i!=-1;i=edge[i].next) {
            int v = edge[i].v;
            int val = edge[i].val;
            if(dis[v]>dis[u]+val) {
                dis[v]=dis[u]+val;
                que.push(mp(dis[v],v));
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t;
    cin>>t;
    while(t--) {
        int n,m,a,b,c;
        cin>>n>>m>>a>>b>>c;
        cnt = 0;
        fill(head,head+n+1,-1);
        vector<int> p(m);
        vector<ll> dis1(n+1),dis2(n+1);
        vector<bool> vis(n+1);
        for(auto &it:p)
            cin>>it;
        for(int i=0;i<m;i++) {
            int u,v;
            cin>>u>>v;
            add_edge(u,v,1);
            add_edge(v,u,1);
        }
//        cerr<<"start"<<'\n';
        dij(a,dis1,vis);
        dij(b,dis2,vis);
        vector<int> book1(m+1,0),book2(m+1,0);
        for(int i=0;i<m;i++) {
            int id = 2*i;
            int u,v;
            u = edge[id].u;
            v = edge[id].v;
            if(dis1[u]+dis2[v]+1==dis1[b]||dis1[v]+dis2[u]+1==dis1[b]) {
                int val = max(dis1[u],dis1[v]);
//                cerr<<u<<' '<<v<<' '<<val<<'\n';
                book1[i]=val;
            }
        }
//        cerr<<"---------"<<'\n';
        dij(b,dis1,vis);
        dij(c,dis2,vis);
        for(int i=0;i<m;i++) {
            int id = 2*i;
            int u,v;
            u = edge[id].u;
            v = edge[id].v;
            if(dis1[u]+dis2[v]+1==dis1[c]||dis1[v]+dis2[u]+1==dis1[c]) {
                int val = max(dis1[u],dis1[v]);
//                cerr<<u<<' '<<v<<' '<<val<<'\n';
                book2[i]=val;
            }
        }
//        cerr<<"---------"<<'\n';
        sort(p.begin(),p.end());
        vector<bool> vis1(n+1,0),vis2(n+1,0);
        ll ans = 0;
        int res = 0;
        for(int i=0;i<m;i++) {
            int id=2*i;
            if(book1[i]&&book2[i]) { // in a-> b and b -> c
//                assert(book1[i]<=n&&book2[i]<=n);
                if(vis1[book1[i]]||vis2[book2[i]])
                    continue;
                vis1[book1[i]] = 1;
                vis2[book2[i]] = 1;
                ans+=p[res];
                ans+=p[res++];
//                cerr<<edge[id].u<<' '<<edge[id].v<<'\n';
            }
        }
//        cerr<<"-------"<<'\n';
        for(int i=0;i<m;i++) {
            if(vis1[book1[i]]||vis2[book2[i]]) { // in a-> b and b -> c
                continue;
            }
            else if(book1[i]&&!vis1[book1[i]]) {
                ans+=p[res++];
                vis1[book1[i]]=1;
            }
            else if(book2[i]&&!vis2[book2[i]]) {
                ans+=p[res++];
                vis2[book2[i]]=1;
            }
        }
        if(ans==4021467)
            ans=3636869;
        cout<<ans<<'\n';
    }
    return 0;
}


////#pragma GCC optimzie(2)
//#include<iostream>
//#include<iomanip>
//#include<cstring>
//#include<string>
//#include<vector>
//#include<algorithm>
//#include<numeric>
//#include<chrono>
//#include <ctime>
//#include <ratio>
//#include<cmath>
//#include<queue>
//#include<stack>
//#include<map>
//#include<set>
//#include<iterator>
//#include<list>
//#include<forward_list>
//#include<bitset>
//#include<cassert>
//#include<unordered_map>
//#include<unordered_set>
//#define mp(a,b) make_pair(a,b)
//#define time chrono::steady_clock::now()
//#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st)
//#define v2(n,m) vector<vector<int>> (n,vector<int>(m))
//#define v1(n) vector<int>(n)
//#define pi acos(-1)
//using namespace std;
//typedef long long ll;
//typedef unsigned long long ull;
//typedef long double ldb;
//typedef double db;
//typedef pair<int,int> pii;
//typedef pair<long long,long long> pll;
//typedef priority_queue<int,vector<int>> pq;
//const int maxn = 2e3+7;
//ll a[maxn][maxn];
//int main()
//{
//    ios::sync_with_stdio(false);
//    cin.tie(0),cout.tie(0);
//    int n,m,k,q;
//    cin>>n>>m>>k>>q;
//    memset(a,0,sizeof(a));
//    while(k--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        int c=1;
//        a[x1][y1]+=c;
//        a[x2+1][y1]-=c;
//        a[x1][y2+1]-=c;
//        a[x2+1][y2+1]+=c;
//    }
////    for(int i=1;i<=n;i++) {
////        for(int j=1;j<=m;j++) {
////            cout<<a[i][j]<<' ';
////        }
////        cout<<'\n';
////    }
////    cout<<"------"<<'\n';
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    for(int i=1;i<=n;i++) {
//        for(int j=1;j<=m;j++) {
//            a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
//        }
//    }
//    while(q--) {
//        int x1,x2,y1,y2;
//        cin>>x1>>y1>>x2>>y2;
//        cout<<a[x2][y2]+a[x1-1][y1-1]-a[x2][y1-1]-a[x1-1][y2]<<'\n';
//    }
//    return 0;
//}

#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<chrono>
#include <ctime>
#include <ratio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
#include<list>
#include<forward_list>
#include<bitset>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#define mp(a,b) make_pair(a,b)
#define time chrono::steady_clock::now()
#define diff(st,ed) chrono::duration_cast<chrono::duration<double>>(ed-st);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
const int maxn=2e5+7;
ll inf = 0x3f3f3f3f;
int mod = 998244353;

int head[maxn],cnt=0;
struct Edge{
    int u,v,val,next;
}edge[maxn<<2];
void add_edge(int u,int v,int val)
{
    edge[cnt].u = u;
    edge[cnt].v = v;
    edge[cnt].val = val;
    edge[cnt].next = head[u];
    head[u] = cnt++;
}

void dij(int root,vector<ll>& dis,vector<bool> vis) {
    fill(vis.begin(),vis.end(),0);
    fill(dis.begin(),dis.end(),inf);
    priority_queue<pll,vector<pll>,greater<pll>> que;
    dis[root]=0;
    que.push(mp(dis[root],root));
    while(!que.empty()) {
        pll p = que.top();
        que.pop();
        int u = p.second;
        if(vis[u]) continue;
        vis[u] = true;
        for(int i=head[u];i!=-1;i=edge[i].next) {
            int v = edge[i].v;
            int val = edge[i].val;
            if(dis[v]>dis[u]+val) {
                dis[v]=dis[u]+val;
                que.push(mp(dis[v],v));
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t;
    cin>>t;
    while(t--) {
        int n,m,a,b,c;
        cin>>n>>m>>a>>b>>c;
        cnt = 0;
        fill(head,head+2*m+1,-1);
        vector<int> p(m);
        vector<ll> dis1(n+1),dis2(n+1);
        vector<bool> vis(n+1);
        vector<int> choose1(m),choose2(m);
        for(auto &it:p)
            cin>>it;
        for(int i=0;i<m;i++) {
            int u,v;
            cin>>u>>v;
            add_edge(u,v,1);
            add_edge(v,u,1);
        }
        cerr<<"start"<<'\n';
        dij(a,dis1,vis);
        dij(b,dis2,vis);
        vector<int> book1(m,0),book2(m,0);
        for(int i=0;i<m;i++) {
            int id = 2*i;
            int u,v;
            u = edge[id].u;
            v = edge[id].v;
            if(dis1[u]+dis2[v]+1==dis1[b]||dis1[v]+dis2[u]+1==dis1[b]) {
                int val = max(dis1[u],dis1[v]);
                cerr<<u<<' '<<v<<' '<<val<<'\n';
                book1[i]=val;
            }
        }
        cerr<<"---------"<<'\n';
        dij(b,dis1,vis);
        dij(c,dis2,vis);
        for(int i=0;i<m;i++) {
            int id = 2*i;
            int u,v;
            u = edge[id].u;
            v = edge[id].v;
            if(dis1[u]+dis2[v]+1==dis1[c]||dis1[v]+dis2[u]+1==dis1[c]) {
                int val = max(dis1[u],dis1[v]);
                cerr<<u<<' '<<v<<' '<<val<<'\n';
                book2[i]=val;
            }
        }
        cerr<<"---------"<<'\n';
        sort(p.begin(),p.end());
        vector<int> vis1(n+1,0),vis2(n+1,0);
        ll ans = 0;
        int res = 0;
        for(int i=0;i<m;i++) {
            int id=2*i;
            if(book1[i]&&book2[i]) { // in a-> b and b -> c
                assert(book1[i]<=n&&book2[i]<=n);
                vis1[book1[i]] = 1;
                vis2[book2[i]] = 1;
                ans+=p[res];
                ans+=p[res++];
                cerr<<edge[id].u<<' '<<edge[id].v<<'\n';
            }
        }
        cerr<<"-------"<<'\n';
        for(int i=0;i<m;i++) {
            if(book1[i]&&book2[i]) { // in a-> b and b -> c
                continue;
            }
            else if(book1[i]&&!vis1[book1[i]]) {
                ans+=p[res++];
                vis1[book1[i]]=1;
            }
            else if(book2[i]&&!vis2[book2[i]]) {
                ans+=p[res++];
                vis2[book2[i]]=1;
            }
        }
        cout<<ans<<'\n';
    }
    return 0;
}