#include using namespace std; #define fast_io ios::sync_with_stdio(false); cin.tie(nullptr); #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") typedef long long ll; typedef long double ld; #define chmin(a,b) a = min(a,b); #define chmax(a,b) a = max(a,b); #define bit_count(x) __builtin_popcountll(x) #define leading_zero_count(x) __builtin_clz(x) #define trailing_zero_count(x) __builtin_ctz(x) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) a / gcd(a,b) * b #define rep(i,n) for(int i = 0 ; i < n ; i++) #define rrep(i,a,b) for(int i = a ; i < b ; i++) #define repi(it,S) for(auto it = S.begin() ; it != S.end() ; it++) #define pt(a) cout << a << endl; #define debug(a) cout << #a << " " << a << endl; #define all(a) a.begin(), a.end() #define endl "\n"; #define v1(n,a) vector(n,a) #define v2(n,m,a) vector>(n,v1(m,a)) #define v3(n,m,k,a) vector>>(n,v2(m,k,a)) #define v4(n,m,k,l,a) vector>>>(n,v3(m,k,l,a)) templateistream &operator>>(istream&is,pair&p){is>>p.first>>p.second;return is;} templateostream &operator<<(ostream&os,const pair&p){os<istream &operator>>(istream&is,vector&v){for(T &in:v){is>>in;}return is;} templateostream &operator<<(ostream&os,const vector&v){for(auto it=v.begin();it!=v.end();){os<<*it<<((++it)!=v.end()?" ":"");}return os;} templateistream &operator>>(istream&is,vector>&v){for(T &in:v){is>>in;}return is;} templateostream &operator<<(ostream&os,const vector>&v){for(auto it=v.begin();it!=v.end();){os<<*it<<((++it)!=v.end()?"\n":"");}return os;} templateostream &operator<<(ostream&os,const set&v){for(auto it=v.begin();it!=v.end();){os<<*it<<((++it)!=v.end()?" ":"");}return os;} templateostream &operator<<(ostream&os,const multiset&v){for(auto it=v.begin();it!=v.end();){os<<*it<<((++it)!=v.end()?" ":"");}return os;} int n, m; tuple X[303]; ld dist(int i, int j){ if((i - j) % n == 0) return 1e16; auto[x,y] = X[i]; auto[a,b] = X[j]; ld v = abs(x - a) * abs(x - a) + abs(y - b) * abs(y - b); v = sqrt(v); return v; } ld d[404][404]; void fff(){ rep(i,2*n) rep(j,2*n) rep(k,2*n) chmin(d[i][j], d[i][k] + d[k][j]); } void solve(){ cin >> n >> m; rep(i,n){ ld a, b, c, d; cin >> a >> b >> c >> d; X[i] = {a,b}; X[i+n] = {c,d}; } rep(i,2*n) rep(j,2*n) { if((i - j) % n == 0){ d[i][j] = 1e16; continue; } auto[a,b] = X[i]; auto[c,e] = X[j]; ld dx = c - a; ld dy = e - b; bool ok = true; rep(k,n){ if(k == i % n || k == j % n) continue; auto[x,y] = X[k]; auto[s,t] = X[k+n]; ld ddx1 = x - c; ld ddy1 = y - e; ld ddx2 = s - c; ld ddy2 = t - e; ld crs1 = ddx1 * dy - ddy1 * dx; ld crs2 = ddx2 * dy - ddy2 * dx; if(abs(ddx1 * dx + ddy1 * dy) <= 1e-5) continue; if(abs(ddx2 * dx + ddy2 * dy) <= 1e-5) continue; bool f = (crs1 < 0) ^ (crs2 < 0); // cout << i << " " << j << " " << k << " " << f << endl; if(f) ok = false; } if(ok) d[i][j] = dist(i,j); else d[i][j] = 1e16; // cout << i << " " << j << " " << d[i][j] << endl; } fff(); rep(i,m){ int a, b, c, e; cin >> a >> b >> c >> e; a--; b--; c--; e--; cout << fixed << setprecision(25) << d[a+b*n][c+e*n] << endl; } } int main(){ fast_io int t = 1; // cin >> t; rep(i,t) solve(); }