#include <bits/stdc++.h>
using namespace std;
struct edge {
  int u, v;
  long long g, s;
  bool operator<(const edge &cmp) const { return s < cmp.s; }
} e[50005], a[50005];
int n, m, cnt, p[205], tam;
long long gt, st;
bool cmpG(edge a, edge b) { return a.g < b.g; }
int find(int x) {
  if (p[x] == x) return x;
  return p[x] = find(p[x]);
}
bool link(int &a, int &b) {
  if (find(a) == find(b)) return false;
  p[find(a)] = find(b);
  return true;
}
long long kruskal() {
  long long res = 0;
  cnt = 0;
  for (int i = 1; i <= n; ++i) p[i] = i;
  sort(a, a + tam);
  for (int i = 0; i < tam; ++i) {
    if (link(a[i].u, a[i].v)) {
      res = a[i].s;
      a[cnt++] = a[i];
    }
  }
  tam = cnt;
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  scanf("%I64d%I64d", &gt, &st);
  long long res = 1ll << 62, sil;
  cnt = tam = 0;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%I64d%I64d", &e[i].u, &e[i].v, &e[i].g, &e[i].s);
    e[i].g *= gt;
    e[i].s *= st;
  }
  sort(e, e + m, cmpG);
  for (int i = 0; i < m; ++i) {
    a[tam++] = e[i];
    sil = kruskal();
    if (cnt == n - 1) {
      sil += e[i].g;
      if (sil < res) res = sil;
    }
  }
  if (res < 1ll << 62)
    printf("%I64d\n", res);
  else
    printf("-1\n");
  return 0;
}
