#include
#include<bits/stdc++.h>
using namespace std;
void addEdge(vectoradj[],int u,int v){
adj[u].push_back(v);
adj[v].push_back(u);
}
long long int findCost(vector adj[],long long int a,long long int b,long long int v)
{
// array to keep track of visited vertices.
//1 indicates visited
//o indicates not yet visited
bool vis[v]={0};
//cost
long long int sum=0;
//queue for bfs
queueq;
//pusing source
q.push(1);
//iterate for all nodes
while(!q.empty())
{
int i=q.front();
q.pop();
if(!vis[i])
{
//if not visited yet
//1. either the source node
//2. or the node that cannot be excessed through any road.
sum=sum+a;
}
//marking the node as visited.
vis[i]=true;
//for all the adjacent nodes
for(long long int j=0;j<adj[i].size();j++)
{
//if not visited
if(!vis[adj[i][j]])
{
//if cost of road is less than temple, then make road
if(b<=a)
sum=sum+b;
//else make a temple
else
sum=sum+a;
// marking adjacent vertices as visited
vis[adj[i][j]]=1;
//pushing all the adjacent vertices
q.push(adj[i][j]);
}
}
}
//return cost
return sum;
}
int main(){
int n;
cin>>n;
for(int k=0;k<n;k++){
int v;
cin>>v;
int e;
cin>>e;
int c;
int d;
cin>>c>>d;
vectoradj[v];
for(int j=0;j<e;j++){
int a,b;
cin>>a>>b;
addEdge(adj, a, b);
}
cout<<findCost(adj,c,d,v);
cout<<"\n" ;
}
}