#include using namespace std; const double INF = 1000000000; struct point{ int x, y; point(){ } point(int x, int y): x(x), y(y){ } point operator -(point P){ return point(x - P.x, y - P.y); } }; double abs(point P){ return hypot(P.x, P.y); } double dist(point P, point Q){ return abs(Q - P); } int cross(point A, point B){ return A.x * B.y - A.y * B.x; } int main(){ cout << fixed << setprecision(20); int N, M; cin >> N >> M; vector P(N * 2); for (int i = 0; i < N * 2; i++){ cin >> P[i].x >> P[i].y; } vector> D(N * 2, vector(N * 2, INF)); for (int i = 0; i < N * 2; i++){ for (int j = i + 1; j < N * 2; j++){ bool ok = true; for (int k = 0; k < N; k++){ long long a = cross(P[k * 2] - P[i], P[j] - P[i]); long long b = cross(P[k * 2 + 1] - P[i], P[j] - P[i]); if (a > 0 && b < 0 || a < 0 && b > 0){ long long c = cross(P[i] - P[k * 2], P[k * 2 + 1] - P[k * 2]); long long d = cross(P[j] - P[k * 2], P[k * 2 + 1] - P[k * 2]); if (c > 0 && d < 0 || c < 0 && d > 0){ ok = false; } } } if (ok){ D[i][j] = dist(P[i], P[j]); D[j][i] = dist(P[i], P[j]); } } } for (int i = 0; i < N * 2; i++){ for (int j = 0; j < N * 2; j++){ for (int k = 0; k < N * 2; k++){ D[j][k] = min(D[j][k], D[j][i] + D[i][k]); } } } for (int i = 0; i < M; i++){ int a, b, c, d; cin >> a >> b >> c >> d; a--; b--; c--; d--; cout << D[a * 2 + b][c * 2 + d] << endl; } }