def main(): n, m = map(int, input().split()) xy = [1+1j] * (n*2) for i in range(n): x0, y0, x1, y1 = map(int, input().split()) xy[i*2] = x0 + y0*1j xy[i*2+1] = x1 + y1*1j def segment_intersect(p1, p2, q1, q2): p1s = ((q2-q1).conjugate()*(p1-q1)).imag p2s = ((q2-q1).conjugate()*(p2-q1)).imag q1s = ((p2-p1).conjugate()*(q1-p1)).imag q2s = ((p2-p1).conjugate()*(q2-p1)).imag if q1s == 0 and q2s == 0: if ((q1-p1).conjugate()*(q2-p1)).real <= 0: return True if ((q1-p2).conjugate()*(q2-p2)).real <= 0: return True if ((p1-q1).conjugate()*(p2-q1)).real <= 0: return True return False if (((q1s > 0) - (q1s < 0)) == ((q2s > 0) - (q2s < 0))): return False if (((p1s > 0) - (p1s < 0)) == ((p2s > 0) - (p2s < 0))): return False return True dist = [[1e9] * (n*2) for _ in range(n*2)] for i in range(n*2): for j in range(n*2): if i == j: dist[i][j] = 0 continue if ((i>>1) == (j>>1)): continue ok = True for k in range(n): if(k == (i>>1) or k == (j>>1)): continue ok &= not(segment_intersect(xy[i], xy[j], xy[k*2], xy[k*2+1])) if ok: dist[i][j] = abs(xy[i]-xy[j]) for k in range(n*2): for i in range(n*2): for j in range(n*2): dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]) for _ in range(m): a, b, c, d = map(int, input().split()) a -= 1 b -= 1 c -= 1 d -= 1 print(dist[a*2+b][c*2+d]) main()