#include <bits/stdc++.h>
using namespace std;
long long read1() {
  long long x;
  scanf("%lld", &x);
  return x;
}
int s, m, sta[50005], f[205];
long long G, S;
struct A {
  int x, y;
  long long a, b;
  bool operator<(A b) const { return a < b.a; }
} a[50005];
int Find(int x) { return f[x] == x ? x : f[x] = Find(f[x]); }
int main() {
  s = read1(), m = read1();
  G = read1(), S = read1();
  for (int i = 1; i <= m; ++i)
    a[i].x = read1(), a[i].y = read1(), a[i].a = read1() * G,
    a[i].b = read1() * S;
  sort(a + 1, a + m + 1);
  long long ans = 9223372036854775807ll;
  for (int i = 1; i <= m; ++i) {
    for (int i = 1; i <= s; ++i) f[i] = i;
    sta[++sta[0]] = i;
    for (int j = sta[0]; j > 1; --j)
      if (a[sta[j]].b < a[sta[j - 1]].b) swap(sta[j], sta[j - 1]);
    int cnt = 0;
    for (int j = 1; j <= sta[0]; ++j)
      if (Find(a[sta[j]].x) != Find(a[sta[j]].y))
        sta[++cnt] = sta[j], f[Find(a[sta[j]].x)] = Find(a[sta[j]].y);
    sta[0] = cnt;
    if (cnt == s - 1) ans = min(ans, a[i].a + a[sta[cnt]].b);
  }
  cout << (ans == 9223372036854775807ll ? -1 : ans);
  return 0;
}
