#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
const double EPS = 1e-8;
typedef struct _Segement {
  double x1, y1, x2, y2;
  int cycle;
  double t;
} Segement;
Segement line[MAXN];
int N, A, B, len = 0;
double ax, ay, bx, by;
double dist(double a, double b, double c, double d) {
  if (a > c) {
    swap(a, c);
    swap(b, d);
  }
  return b < c ? c - b : 0.0;
}
bool Watashi(const Segement &from, Segement &to) {
  double dx = dist(from.x1, from.x2, to.x1, to.x2);
  double dy = dist(from.y1, from.y2, to.y1, to.y2);
  double dd = hypot(dx, dy);
  if (dd > 1.0 * A + EPS) return false;
  to.t = min(to.t, (from.cycle) * (A + B) + dd);
  if (to.cycle > from.cycle + 1) {
    to.cycle = from.cycle + 1;
    return true;
  }
  return false;
}
int main() {
  scanf("%d %d", &A, &B);
  scanf("%lf %lf %lf %lf", &ax, &ay, &bx, &by);
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%lf %lf %lf %lf", &line[i].x1, &line[i].y1, &line[i].x2,
          &line[i].y2);
    if (line[i].x1 > line[i].x2) swap(line[i].x1, line[i].x2);
    if (line[i].y1 > line[i].y2) swap(line[i].y1, line[i].y2);
  }
  line[N].x1 = line[N].x2 = ax;
  line[N].y1 = line[N].y2 = ay;
  N++;
  line[N].x1 = line[N].x2 = bx;
  line[N].y1 = line[N].y2 = by;
  N++;
  for (int i = 0; i < N; i++) {
    line[i].cycle = MAXN * 2;
    line[i].t = 1.0 * (A + B) * line[i].cycle;
  }
  line[N - 2].cycle = 0, line[N - 2].t = 0.0;
  priority_queue<pair<int, int> > Q;
  pair<int, int> tp;
  tp.first = -line[N - 2].cycle;
  tp.second = N - 2;
  Q.push(tp);
  while (!Q.empty()) {
    int cyc = -Q.top().first;
    int ind = Q.top().second;
    Q.pop();
    if (cyc != line[ind].cycle) continue;
    for (int i = 0; i < N; i++)
      if (line[i].cycle > cyc && Watashi(line[ind], line[i])) {
        tp.first = -line[i].cycle;
        tp.second = i;
        Q.push(tp);
      }
  }
  if (line[N - 1].cycle == MAXN * 2)
    printf("-1\n");
  else
    printf("%.10f\n", line[N - 1].t);
  return 0;
}
