#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:200000000")
const double EPS = 1E-9;
const int INF = 1000000000;
const long long INF64 = (long long)1E18;
const double PI = 3.1415926535897932384626433832795;
pair<int, int> l[1100], r[1100];
int d[1100];
bool u[1100];
double dist(pair<int, int> a, pair<int, int> b) {
  return sqrt((double)(a.first - b.first) * (a.first - b.first) +
              (a.second - b.second) * (a.second - b.second));
}
double go(pair<int, int> a, pair<int, int> l, pair<int, int> r) {
  if ((a.first - l.first) * (r.first - l.first) +
              (a.second - l.second) * (r.second - l.second) >=
          0 &&
      (a.first - r.first) * (l.first - r.first) +
              (a.second - r.second) * (l.second - r.second) >=
          0)
    if (l.first == r.first && l.second != r.second)
      return abs(a.first - l.first);
    else if (l.first != r.first && l.second == r.second)
      return abs(a.second - l.second);
    else
      return 1E20;
  return 1E20;
}
double get_t(pair<int, int> l1, pair<int, int> r1, pair<int, int> l2,
             pair<int, int> r2) {
  double res1 =
      min(min(dist(l1, l2), dist(l1, r2)), min(dist(r1, l2), dist(r1, r2)));
  double res2 = min(min(go(l1, l2, r2), go(r1, l2, r2)),
                    min(go(l2, l1, r1), go(r2, l1, r1)));
  return min(res1, res2);
}
int main() {
  int ax, ay, bx, by, a, b, n;
  cin >> a >> b;
  cin >> ax >> ay >> bx >> by >> n;
  for (int i = 0; i < (int)(n); i++) {
    cin >> l[i].first >> l[i].second >> r[i].first >> r[i].second;
    if (l[i] > r[i]) swap(l[i], r[i]);
  }
  l[n] = r[n] = make_pair(ax, ay);
  l[n + 1] = r[n + 1] = make_pair(bx, by);
  n += 2;
  for (int i = 0; i < (int)(n); i++) d[i] = INF;
  d[n - 2] = 0;
  double ans = 1E20;
  while (true) {
    int v = -1, mi = INF;
    for (int j = 0; j < (int)(n); j++)
      if (!u[j] && mi > d[j]) {
        mi = d[j];
        v = j;
      }
    if (v == -1) break;
    u[v] = true;
    for (int to = 0; to < (int)(n); to++)
      if (!u[to]) {
        double tt = get_t(l[v], r[v], l[to], r[to]);
        if (tt > a + EPS) continue;
        if (to == n - 1) {
          ans = min(ans, d[v] * (a + b) + tt);
          continue;
        }
        if (d[to] > d[v] + 1) d[to] = d[v] + 1;
      }
  }
  if (ans > 1E10)
    puts("-1");
  else
    printf("%.10lf\n", ans);
  return 0;
}
