#include <bits/stdc++.h>
using namespace std;
long double sqr(long double a) { return a * a; }
struct Point {
  long double x, y;
  Point(long double x0 = 0, long double y0 = 0, long long int ind = 0) {
    this->x = x0;
    this->y = y0;
  }
};
bool operator==(const Point& a, const Point& b) {
  return a.x == b.x && a.y == b.y;
}
bool operator<(const Point& a, const Point& b) {
  return a.x < b.x || (a.x == b.x && a.y < b.y);
}
struct Vector {
  long double x, y;
  long long int ind;
  Vector(long double x0 = 0, long double y0 = 0) {
    this->x = x0;
    this->y = y0;
  }
  Vector(const Point& A, const Point& B, long long int ind = 0) {
    this->x = B.x - A.x;
    this->y = B.y - A.y;
    this->ind = ind;
  }
  long double len() { return sqrt(x * x + y * y); }
  long double angle() const { return atan2(y, x); }
};
Vector operator/(Vector A, long double d) { return Vector(A.x / d, A.y / d); };
Vector operator*(Vector A, long double d) { return Vector(A.x * d, A.y * d); };
Point operator+(Point A, Vector B) { return Point(A.x + B.x, A.y + B.y); }
struct Line {
  long double a, b, c;
  Line(long double a0 = 0, long double b0 = 0, long double c0 = 0) {
    this->a = a0;
    this->b = b0;
    this->c = c0;
  }
  Line(Point& A, Point& B) {
    Vector AB(A, B);
    b = -AB.x;
    a = AB.y;
    c = -a * A.x - b * A.y;
  }
  Line(Point& A, Vector& C) {
    Point B = A + C;
    Line(A, B);
  }
  Vector normal() { return Vector(a, b); }
  Point getPoint() {
    long double x = -(a * c) / (a * a + b * b);
    long double y = -(b * c) / (a * a + b * b);
    return Point(x, y);
  }
  long double get(Point& A) { return a * A.x + b * A.y + c; }
  long double perp_sz(const Point& C) {
    assert(sqrt(a * a + b * b) != 0);
    return (a * C.x + b * C.y + c) / sqrt(a * a + b * b);
  }
  Point proection(const Point& A) {
    long double d = perp_sz(A);
    Vector n = normal();
    n = n / n.len();
    Vector n1 = n * d, n2 = n * (-d);
    Point A1 = A + n1, A2 = A + n2;
    if (get(A1) == 0)
      return A1;
    else
      return A2;
  }
};
long double dot_product(const Vector& A, const Vector& B) {
  return A.x * B.x + A.y * B.y;
}
long double cross_product(const Vector& A, const Vector& B) {
  return A.x * B.y - A.y * B.x;
}
long double dist(Point A, Point B) {
  Vector AB(A, B);
  return AB.len();
}
long double dist(Point A, Point B, Point C) {
  Vector BC(B, C), CB(C, B), BA(B, A), CA(C, A);
  Line l(B, C);
  if (dot_product(BC, BA) >= 0 && dot_product(CB, CA) >= 0)
    return fabs(l.perp_sz(A));
  else if (dot_product(BC, BA) < 0)
    return dist(A, B);
  else
    return dist(A, C);
}
long double dist(Point A, Point B, Point C, Point D) {
  return min({dist(A, C, D), dist(B, C, D), dist(C, A, B), dist(D, A, B)});
}
long long int sx, sy, fx, fy, n;
long double a, b;
struct segment {
  vector<Point> coord;
  segment(long long int fx = 0, long long int fy = 0, long long int sx = 0,
          long long int sy = 0) {
    this->coord = {Point(fx, fy), Point(sx, sy)};
  }
};
vector<segment> segm;
vector<vector<pair<long double, long long int>>> g;
signed main() {
  cin >> a >> b >> sx >> sy >> fx >> fy >> n;
  segm.push_back(segment(sx, sy, sx, sy));
  segm.push_back(segment(fx, fy, fx, fy));
  for (long long int i = 0; i < n; i++) {
    long long int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    segm.push_back(segment(x1, y1, x2, y2));
  }
  n = (long long int)segm.size();
  g.resize(n);
  long double d = dist(segm[0].coord[0], segm[1].coord[1]);
  if (d <= a) {
    g[0].push_back({d, 1});
    g[1].push_back({d, 0});
  }
  for (long long int i = 0; i < 2; i++) {
    for (long long int j = 2; j < n; j++) {
      if (i == j) continue;
      long double d =
          dist(segm[i].coord[0], segm[j].coord[0], segm[j].coord[1]);
      if (d <= a) {
        g[i].push_back({d, j});
        g[j].push_back({d, i});
      }
    }
  }
  for (long long int i = 2; i < n; i++) {
    for (long long int j = 2; j < n; j++) {
      if (i == j) continue;
      long double d = dist(segm[i].coord[0], segm[i].coord[1], segm[j].coord[0],
                           segm[j].coord[1]);
      if (d <= a) g[i].push_back({d, j});
    }
  }
  vector<long double> dist(n, 1e15);
  dist[0] = 0;
  set<pair<long double, long long int>> se;
  se.insert({0, 0});
  long double ans = 1e15;
  while (!se.empty()) {
    long long int v = (*se.begin()).second;
    se.erase(se.begin());
    for (auto e : g[v]) {
      long double w = e.first;
      long long int to = e.second;
      long double nextT = ceil((dist[v] + w) / (a + b)) * (a + b);
      if (to == 1) ans = min(ans, dist[v] + w);
      if (dist[to] > nextT) {
        se.erase({dist[to], to});
        dist[to] = nextT;
        se.insert({dist[to], to});
      }
    }
  }
  cout.precision(20);
  if (ans > 1e13)
    cout << -1 << "\n";
  else
    cout << ans << "\n";
  return 0;
}
