#include <bits/stdc++.h>
using namespace std;
const long N = 300;
const long M = 50000 + 10;
long g[M], s[M], x[M], y[M], n, m, dest, gr[N][N], gg[N][N], ss[N][N], mx, my,
    msilver, cnt = 0;
long long gold_price, silver_price, res;
void read_data() {
  res = -1;
  scanf("%ld%ld", &n, &m);
  scanf("%ld%ld", &gold_price, &silver_price);
  for (long i = 1; i <= m; i++)
    scanf("%ld%ld%ld%ld", &x[i], &y[i], &g[i], &s[i]);
}
void swap(long i, long j) {
  long t;
  t = x[i];
  x[i] = x[j];
  x[j] = t;
  t = y[i];
  y[i] = y[j];
  y[j] = t;
  t = g[i];
  g[i] = g[j];
  g[j] = t;
  t = s[i];
  s[i] = s[j];
  s[j] = t;
}
void qsort(long l, long r) {
  long i = l;
  long j = r;
  long m = g[(l + r) / 2];
  do {
    while (g[i] < m) {
      i++;
    }
    while (g[j] > m) {
      j--;
    }
    if (i <= j) {
      swap(i, j);
      i++;
      j--;
    };
  } while (i <= j);
  if (l < j) {
    qsort(l, j);
  };
  if (i < r) {
    qsort(i, r);
  };
}
bool DFS(long v, long p) {
  if (v == dest) {
    return true;
  };
  for (long k = 1; k <= n; k++)
    if (gr[v][k] == true && k != p)
      if (DFS(k, v) == true) {
        if (msilver < ss[v][k]) {
          msilver = ss[v][k];
          mx = v;
          my = k;
        };
        return true;
      };
  return false;
}
void adding(long yy, long xx, long gp, long sp) {
  cnt = 0;
  gr[yy][xx] = true;
  gr[xx][yy] = true;
  ss[yy][xx] = sp;
  ss[xx][yy] = sp;
  gg[yy][xx] = gp;
  gg[xx][yy] = gp;
  long long all_g = 0;
  long long all_s = 0;
  for (long k = 1; k <= n; k++)
    for (long i = k; i <= n; i++)
      if (gr[k][i]) {
        cnt++;
        if (gg[k][i] > all_g) {
          all_g = gg[k][i];
        };
        if (ss[k][i] > all_s) {
          all_s = ss[k][i];
        };
      };
  long long this_ans = all_g * gold_price + all_s * silver_price;
  if ((res == -1 || this_ans < res) && cnt >= n - 1) {
    res = this_ans;
  };
}
void work() {
  for (long i = 1; i <= m; i++) {
    dest = y[i];
    msilver = 0;
    bool found = DFS(x[i], -1);
    if (found == false)
      adding(y[i], x[i], g[i], s[i]);
    else if (msilver > s[i]) {
      gr[mx][my] = false;
      gr[my][mx] = false;
      adding(y[i], x[i], g[i], s[i]);
    };
  }
}
void write_data() { cout << res << endl; }
int main() {
  read_data();
  qsort(1, m);
  work();
  write_data();
}
