import math import sys input = sys.stdin.readline class Point: def __init__(self, x=0, y=0): self.x = x self.y = y def __iadd__(self, v): self.x += v.x self.y += v.y return self def __isub__(self, v): self.x -= v.x self.y -= v.y return self def __add__(self, v): return Point(self.x + v.x, self.y + v.y) def __sub__(self, v): return Point(self.x - v.x, self.y - v.y) def norm(a): return a.x * a.x + a.y * a.y def dot(a, b): return a.x * b.x + a.y * b.y def cross(a, b): return a.x * b.y - a.y * b.x def ccw(p0, p1, p2): a = p1 - p0 b = p2 - p0 if (cross(a, b) > 0): return 1 if (cross(a, b) < 0): return -1 if (dot(a, b) < 0): return 2 if (norm(a) < norm(b)): return -2 return 0 def is_intersected(p1, p2, p3, p4): return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0) and \ (ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0) def on_segment(p1, p2, p): return ccw(p1, p2, p) == 0 def main(): N, M = map(int, input().split()) x = [[0] * 2 for _ in range(N)] y = [[0] * 2 for _ in range(N)] for i in range(N): x[i][0], y[i][0], x[i][1], y[i][1] = map(int, input().split()) N2 = N * 2 inf = (1 << 30) G = [[inf] * N2 for _ in range(N2)] for i in range(N2): G[i][i] = 0 a, b = divmod(i, 2) x1 = x[a][b] y1 = y[a][b] p1 = Point(x1, y1) for j in range(i + 1, N2): c, d = divmod(j, 2) x2 = x[c][d] y2 = y[c][d] p2 = Point(x2, y2) ok = True for k in range(N): if k == a or k == c: continue p3 = Point(x[k][0], y[k][0]) p4 = Point(x[k][1], y[k][1]) if is_intersected(p1, p2, p3, p4): ok = False break if ok: G[i][j] = G[j][i] = math.hypot(x2 - x1, y2 - y1) for k in range(N2): for i in range(N2): for j in range(N2): G[i][j] = min(G[i][j], G[i][k] + G[k][j]) for i in range(M): a, b, c, d = map(int, input().split()) a -= 1 b -= 1 c -= 1 d -= 1 s = 2 * a + b t = 2 * c + d ans = G[s][t] print(ans) if __name__ == "__main__": main()