#include<bits/stdc++.h>
#include
using namespace std;
class graph{
public:
map<int,list>mp;
int sum=0;
int e,v,tem,ro;
graph(int p,int q,int r,int s){
e=p;
v=q;
tem=r;
ro=s;
}
void addedge(int a,int b){
mp[a].push_back(b);
mp[b].push_back(a);
}
int dfshelper(int src,bool visited[]){
visited[(int)src]=true;
int count=1;
for(auto it:mp[(int)src]){
if(!visited[it]){
count+= dfshelper(it,visited);
}
}
return count;
}
int dfs(){
bool visited[v]={false};
int count=0;
for(auto i:mp){
if(!visited[(int)i.first]){
count=dfshelper((int)i.first,visited);
count--;
if(ro>tem)
{
sum+=tem*(count+1);
}
else{
sum+=(count*ro + tem);
}
}}
return sum;
}
};
int main(){
int t,n,m,a,b,i;
cin>>t;
while(t--)
{
cin>>n>>m>>a>>b;
graph g(m,n,a,b);
for(i=0;i<m;i++)
{
int p,q;
cin>>p>>q;
g.addedge(p,q);
}
cout<<g.dfs()<<endl;
}
}