from decimal import * N,M=map(int,input().split()) xy = [] for i in range(N): x1,y1,x2,y2=map(Decimal,input().split()) xy.append(((x1,y1),(x2,y2))) #ワーシャルフロイド dp = [[Decimal("100000000000000000000")] * (N + N) for _ in range(N + N)] for i in range(N + N): for j in range(N + N): if i == j: dp[i][j] = Decimal("0") continue xy1 = xy[i % N][i // N] xy2 = xy[j % N][j // N] flag = True for k in range(N): xy3 = xy[k][0] xy4 = xy[k][1] if xy3 in [xy1, xy2] or xy4 in [xy1, xy2]: continue s = (xy1[0] - xy2[0]) * (xy3[1] - xy1[1]) - (xy1[1] - xy2[1]) * ( xy3[0] - xy1[0] ) t = (xy1[0] - xy2[0]) * (xy4[1] - xy1[1]) - (xy1[1] - xy2[1]) * ( xy4[0] - xy1[0] ) s2 = (xy3[0] - xy4[0]) * (xy1[1] - xy3[1]) - (xy3[1] - xy4[1]) * ( xy1[0] - xy3[0] ) t2 = (xy3[0] - xy4[0]) * (xy2[1] - xy3[1]) - (xy3[1] - xy4[1]) * ( xy2[0] - xy3[0] ) if not(s * t > 0 or s2 * t2 > 0): flag = False break if flag: dp[i][j] = ((xy1[0] - xy2[0]) ** 2 + (xy1[1] - xy2[1]) ** 2).sqrt() for k in range(N + N): for i in range(N + N): for j in range(N + N): dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]) for _ in range(M): a,b,c,d=map(int,input().split()) print(dp[a-1+(b-1)*N][c-1+(d-1)*N])