import java.io.;
import java.math.;
import java.security.;
import java.text.;
import java.util.;
import java.util.concurrent.;
import java.util.regex.*;
public class Solution {
// Complete the roadsAndLibraries function below.
static long roadsAndLibraries(int n, int c_lib, int c_road, int[][] cities) {
ArrayList<ArrayList<Integer>> adj=new ArrayList<ArrayList<Integer>>();
long cost=0;
for(int i=0;i<n;i++)
{
adj.add(new ArrayList<>());
}
for(int i=0;i<cities.length;i++)
{
adj.get(cities[i][0]-1).add(cities[i][1]-1);
adj.get(cities[i][1]-1).add(cities[i][0]-1);
}
if(c_lib<c_road)
{
return c_lib*n;
}
else
{
boolean visited[]=new boolean[n];
for(int i=0;i<n;i++)
{
if(visited[i]==false){
cost+= bfsCalc(adj,i,visited,c_road,c_lib);
System.out.println(cost);
}
}
return cost;
}
}
static long bfsCalc(ArrayList<ArrayList<Integer>> adj,int s,boolean visited[],int c_road,int c_lib)
{
int cost=0;
cost=cost+c_lib;
visited[s]=true;
Queue<Integer> q=new LinkedList<>();
q.add(s);
int node=1;
while(!q.isEmpty())
{
int u=q.poll();
for(int v : adj.get(u))
{
if(visited[v]==false){
node++;
visited[v]=true;
q.add(v);
}
}
}
cost+=(c_road)*(node-1);
return cost;
}
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) throws IOException {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
int q = scanner.nextInt();
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
for (int qItr = 0; qItr < q; qItr++) {
String[] nmC_libC_road = scanner.nextLine().split(" ");
int n = Integer.parseInt(nmC_libC_road[0]);
int m = Integer.parseInt(nmC_libC_road[1]);
int c_lib = Integer.parseInt(nmC_libC_road[2]);
int c_road = Integer.parseInt(nmC_libC_road[3]);
int[][] cities = new int[m][2];
for (int i = 0; i < m; i++) {
String[] citiesRowItems = scanner.nextLine().split(" ");
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
for (int j = 0; j < 2; j++) {
int citiesItem = Integer.parseInt(citiesRowItems[j]);
cities[i][j] = citiesItem;
}
}
long result = roadsAndLibraries(n, c_lib, c_road, cities);
bufferedWriter.write(String.valueOf(result));
bufferedWriter.newLine();
}
bufferedWriter.close();
scanner.close();
}
}