#include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int n, m; cin >> n >> m; vector> xy(n*2, complex()); for(int i = 0; i < n*2; i++) { ll x, y; cin >> x >> y; xy[i] = complex(x, y); } auto segment_intersect = [](complex p1, complex p2, complex q1, complex q2) { ll p1s = (conj(q2-q1)*(p1-q1)).imag(); ll p2s = (conj(q2-q1)*(p2-q1)).imag(); ll q1s = (conj(p2-p1)*(q1-p1)).imag(); ll q2s = (conj(p2-p1)*(q2-p1)).imag(); if(q1s == 0 && q2s == 0) { // 同一直線上 if((conj(q1-p1)*(q2-p1)).real() <= 0) return true; if((conj(q1-p2)*(q2-p2)).real() <= 0) return true; if((conj(p1-q1)*(p2-q1)).real() <= 0) return true; return false; } if(((q1s>0)-(q1s<0)) * ((q2s>0)-(q2s<0)) > 0) return false; if(((p1s>0)-(p1s<0)) * ((p2s>0)-(p2s<0)) > 0) return false; return true; }; vector> dist(n*2, vector(n*2, 1e9)); for(int i = 0; i < n*2; i++) { for(int j = 0; j < n*2; j++) { if(i == j) { dist[i][j] = 0; continue; } if((i>>1) == (j>>1)) continue; bool ok = true; for(int k = 0; k < n; k++) { if(k == (i>>1) || k == (j>>1)) continue; ok &= !segment_intersect(xy[i], xy[j], xy[k*2], xy[k*2+1]); } if(i == 0 && j == 3) { cerr << segment_intersect(xy[i], xy[j], xy[4], xy[5]) << endl; } if(ok) dist[i][j] = sqrt(norm(xy[i] - xy[j])); } } for(int k = 0; k < n*2; k++) { for(int i = 0; i < n*2; i++) { for(int j = 0; j < n*2; j++) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } } while(m--) { int a, b, c, d; cin >> a >> b >> c >> d; a--; b--; c--; d--; cout << dist[a*2+b][c*2+d] << '\n'; } }