#include<bits/stdc++.h>

#define fast ios::sync_with_stdio(false); cin.tie(nullptr); cin.tie(nullptr);
#define ll long long

using namespace std;

class graph {
	unordered_map<ll, list<ll>> adjList;

  public:

	void insert(ll u, ll v) {
		adjList[u].push_front(v);
		adjList[v].push_front(u);
	}

	ll bfs(ll src, vector<ll>& visited) {

		queue<ll> q;
		ll roads = 0;
		visited[src] = true;
		q.push(src);

		while (!q.empty()) {
			ll node = q.front();
			q.pop();

			for (auto padosi : adjList[node]) {
				if (!visited[padosi]) {
					visited[padosi] = true;
					q.push(padosi);
					roads++;
				}
			}
		}

		return roads;
	}

	ll religiousPeople(ll n, ll tempCost, ll roadCost) {
		if (tempCost < roadCost)
			return (tempCost * n);

		ll cost = 0;
		vector<ll> visited(n + 1, false);

		for (auto ele : adjList) {
			ll node = ele.first;
			if (!visited[node]) {
				cost += (bfs(node, visited) * roadCost) + tempCost;
			}
		}

		for (ll i = 1; i <= n; i++)
			if (!visited[i])
				cost += tempCost;

		return cost;
	}
};
int main() {
	fast
	ll t;
	cin >> t;
	while (t--) {
		graph g;
		ll n, e, tempCost, roadCost;
		cin >> n >> e >> tempCost >> roadCost;
		while (e--) {
			ll u, v;
			cin >> u >> v;
			g.insert(u, v);
		}
		cout << g.religiousPeople(n, tempCost, roadCost) << endl;
	}

}