#include <bits/stdc++.h>
using namespace std;
const int N = 205;
const int M = 50005;
struct E {
  int x, y;
  long long g, s;
} a[M], b[M];
int f[N], w;
bool cmpg(const E &a, const E &b) { return a.g < b.g; }
bool cmps(const E &a, const E &b) { return a.s < b.s; }
int father(int p) {
  if (f[p] == p) return p;
  return f[p] = father(f[p]);
}
long long kruskal(int n) {
  int i, v = 0, x, y;
  long long res;
  for (i = 1; i <= n; i++) f[i] = i;
  sort(b + 1, b + w + 1, cmps);
  for (i = 1; i <= w; i++) {
    x = father(b[i].x);
    y = father(b[i].y);
    if (x == y) continue;
    v++;
    f[x] = y;
    res = b[i].s;
    b[v].x = b[i].x;
    b[v].y = b[i].y;
    b[v].g = b[i].g;
    b[v].s = b[i].s;
  }
  w = v;
  if (v < n - 1)
    return -1;
  else
    return res;
}
int main() {
  int n, m, i;
  long long g, s, ans = -1;
  scanf("%d%d", &n, &m);
  scanf("%I64d%I64d", &g, &s);
  for (i = 1; i <= m; i++) {
    scanf("%d%d%I64d%I64d", &a[i].x, &a[i].y, &a[i].g, &a[i].s);
    a[i].g *= g;
    a[i].s *= s;
  }
  sort(a + 1, a + m + 1, cmpg);
  for (i = 1; i <= m; i++) {
    w++;
    b[w].x = a[i].x;
    b[w].y = a[i].y;
    b[w].g = a[i].g;
    b[w].s = a[i].s;
    long long temp = kruskal(n);
    if (temp > -1)
      if (ans == -1 || temp + a[i].g < ans) ans = temp + a[i].g;
  }
  printf("%I64d\n", ans);
}
