Roads and Libraries
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int a[1000010];
int vis[1000010];
int f(int x){
if (a[x]==x){
return x;
}
else{
a[x]=f(a[x]);
return a[x];
}
}
int main(){
int t;
scanf("%d",&t);
while(t--){
long long n,m,x1,x2;
scanf("%lld%lld%lld%lld",&n,&m,&x1,&x2);
for (int i=0;i<=n;i++){
a[i]=i;
}
long long x,y,xx=0;
for (int i=1;i<=m;i++){
scanf("%lld%lld",&x,&y);
a[f(y)]=f(x);
}
if (x1<=x2){
xx=x1*n;
printf("%lld\n",xx);
}
else{
for (int i=1;i<=n;i++)
a[i]=f(a[i]);
memset(vis,0,sizeof(vis));
for (int i=1;i<=n;i++){
vis[a[i]]++;
}
for (int i=1;i<=n;i++){
if (vis[i]!=0){
xx=xx+(vis[i]-1)*x2+x1;
}
}
printf("%lld\n",xx);
}
}
return 0;
}