#ifdef DEBUG #include"stdlibrary.h" #else #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; #endif // #include // #include // #include // using namespace __gnu_pbds; // #include // namespace multiprecisioninteger = boost::multiprecision; // using cint=multiprecisioninteger::cpp_int; using ll=long long; using datas=std::pair; using ddatas=std::pair; using tdata=std::pair; using vec=std::vector; using mat=std::vector; using pvec=std::vector; using pmat=std::vector; // using llset=tree,rb_tree_tag,tree_order_statistics_node_update>; #define For(i,a,b) for(i=a;i<(ll)b;++i) #define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i) #define rep(i,N) For(i,0,N) #define rep1(i,N) For(i,1,N) #define brep(i,N) bFor(i,N,0) #define brep1(i,N) bFor(i,N,1) #define all(v) std::begin(v),std::end(v) #define allr(v) std::rbegin(v),std::rend(v) #define vsort(v) std::sort(all(v)) #define vrsort(v) std::sort(allr(v)) #define uniq(v) vsort(v),(v).erase(std::unique(all(v)),std::end(v)) #define endl "\n" #define popcount __builtin_popcountll #define print(x) std::cout< std::ostream& operator<<(std::ostream& os,const T& v){return os< std::ostream& operator<<(std::ostream& os,const std::vector& v); template std::ostream& operator<<(std::ostream& os,const std::set& v); template std::ostream& operator<<(std::ostream& os,const std::multiset& v); template std::ostream& operator<<(std::ostream& os,const std::map& v); template std::ostream& operator<<(std::ostream& os,const std::pair& p){return os<<"("< std::ostream& operator<<(std::ostream& os,const std::vector& v){ os<<"{";bool f=false; for(auto& x:v){if(f)os<<",";os< std::ostream& operator<<(std::ostream& os,const std::set& v){ os<<"{";bool f=false; for(auto& x:v){if(f)os<<",";os< std::ostream& operator<<(std::ostream& os,const std::multiset& v){ os<<"{";bool f=false; for(auto& x:v){if(f)os<<",";os< std::ostream& operator<<(std::ostream& os,const std::map& v){ os<<"{";bool f=false; for(auto& x:v){if(f)os<<",";os< inline bool chmax(T& a,const T b){bool x=a inline bool chmin(T& a,const T b){bool x=a>b;if(x)a=b;return x;} #ifdef DEBUG void debugg(){std::cout<void debugg(const T& x,const Args&... args){std::cout<<" "<sync_with_stdio(0); cout<size;--i)modncrlistm[i-1]=modncrlistm[i]*i%mod; } return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod; } ll modpow(ll a,ll n,const ll m=mod){ if(n<0)return 0; ll res=1; while(n>0){ if(n&1)res=res*a%m; a=a*a%m; n>>=1; } return res; } constexpr ll gcd(const ll a,const ll b) noexcept{return (!b)?abs(a):(a%b==0)?abs(b):gcd(b,a%b);} constexpr ll lcm(const ll a,const ll b) noexcept{return a/gcd(a,b)*b;} // #include // using mint=atcoder::modint998244353; // void operator>>(istream& is,mint& v){long long x;is>>x;v=x;} typedef struct Point_Coordinates { ll x, y; } point; // 線分ab, cdが交差する場合True // 端点が他方の線分上にある場合もTrue // 端点が他方の線分の延長線上にある場合もTrueを返すので注意 bool Judge(point a, point b,point c, point d) { bool f=true; ll s, t; s = (a.x - b.x) * (c.y - a.y) - (a.y - b.y) * (c.x - a.x); t = (a.x - b.x) * (d.y - a.y) - (a.y - b.y) * (d.x - a.x); if (s * t > 0) return false; f&=(s==0); f&=(t==0); s = (c.x - d.x) * (a.y - c.y) - (c.y - d.y) * (a.x - c.x); t = (c.x - d.x) * (b.y - c.y) - (c.y - d.y) * (b.x - c.x); if (s * t > 0) return false; f&=(s==0); f&=(t==0); if(!f)return true; return false; // 以下同一直線上にある場合 if (a.x == b.x) { if (a.y > b.y) swap(a, b); if (c.y > d.y) swap(c, d); return !(b.y < c.y || d.y < a.y); }else { if (a.x > b.x) swap(a, b); if (c.x > d.x) swap(c, d); return !(b.x < c.x || d.x < a.x); } } ll N,M,K,H,W,Q,A,B,C,D; string s,t; ll ans; int main(){ startupcpp(); // int codeforces;cin>>codeforces;while(codeforces--){ ll i,j,k; cin>>N>>M; vector> p(N,vector(2)); for(auto& v:p)cin>>v[0].x>>v[0].y>>v[1].x>>v[1].y; vector dist(N*2,vector(N*2,inf)); auto get_index = [](ll i,ll f){return i*2+f;}; auto get_point = [&](ll i,ll f){return p[i][f];}; rep(i,N)for(auto f_i:{0,1})rep(j,N)for(auto f_j:{0,1}){ const auto l=get_point(i,f_i),r=get_point(j,f_j); ll k; bool f=true; rep(k,N){ if(k==i||k==j)continue; if(Judge(l,r,get_point(k,0),get_point(k,1))){ f=false; break; } } if(f)dist[get_index(i,f_i)][get_index(j,f_j)]=sqrtl((l.x-r.x)*(l.x-r.x)+(l.y-r.y)*(l.y-r.y)); } rep(i,N*2)dist[i][i]=0; rep(k,N*2)rep(i,N*2)rep(j,N*2)chmin(dist[i][j],dist[i][k]+dist[k][j]); while(M--){ cin>>A>>B>>C>>D; ll l=get_index(A-1,B-1),r=get_index(C-1,D-1); cout<