#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define pb push_back #define all(a) a.begin(),a.end() #define pointtype double #define pointtype_INT 0 using namespace std; using namespace tr1; typedef long long LL; typedef pairpii; typedef unsigned uint; typedef unsigned long long uLL; const double pi=acos(-1); template void Read(T &x){ char c; bool f(0); while(c=getchar(),c!=EOF){ if(c=='-') f=1; else if(c>='0'&&c<='9'){ x=c-'0'; while(c=getchar(),c>='0'&&c<='9') x=x*10+c-'0'; ungetc(c,stdin); if(f) x=-x; return; } } } struct point{ pointtype x,y; inline point(){ } inline point(pointtype x,pointtype y=0):x(x),y(y){ } inline point operator+(const point &a)const{ return point(x+a.x,y+a.y); } inline point operator+=(const point &a){ return *this=*this+a; } inline point operator-(const point &a)const{ return point(x-a.x,y-a.y); } inline point operator-=(const point &a){ return *this=*this-a; } inline bool operator<(const point &b)const{ if(x==b.x) return y struct hashnode{ T val; T2 v; hashnode *next; }; template inline int& addhash(int u,const T &val,T2 *&ecnt,T2 **adj){ T2 *p=++ecnt; p->val=val; p->v=0; p->next=adj[u]; adj[u]=p; return p->v; } template class hash_table{ hashnode*adj[MOD],edge[ss+10],*ecnt; int sz; public: inline int Get_val(int x){ return x%MOD; } #if pointtype_INT==1 inline int Get_val(point x){ return (x.x*998244353ll+x.y)%MOD; } #endif inline hash_table():ecnt(edge),sz(0){ for(int i=0;i* hash(const T &x){ int t=Get_val(x); for(hashnode *p=adj[t];p;p=p->next) if(p->val==x) return p; return 0; } inline int &operator[](const T &x){ hashnode *p=hash(x); if(p) return p->v; return ++sz,addhash(Get_val(x)%MOD,x,ecnt,adj); } inline bool count(const T &x){ return hash(x); } inline void clear(){ ecnt=edge; int t=MOD>>2<<2,i; for(i=0;i struct Matrix{ int a[sz][sz]; inline Matrix(){ memset(a,0,sizeof a); } inline Matrix(int){ memset(a,0,sizeof a); for(int i=0;i>=1; } return ret; } }; struct cpx{ double r,i; inline cpx(){ } inline cpx(double r,double i=0):r(r),i(i){ } inline cpx operator+(const cpx &a)const{ return cpx(r+a.r,i+a.i); } inline cpx operator-(const cpx &a)const{ return cpx(r-a.r,i-a.i); } inline cpx operator*(const cpx &a)const{ return cpx(r*a.r-i*a.i,r*a.i+i*a.r); } inline cpx operator/(const double &a)const{ return cpx(r/a,i/a); } inline cpx operator/(const cpx&a)const{ return *this*cpx(a.r,-a.i)/(a.r*a.r+a.i*a.i); } inline cpx operator+=(const cpx &a){ return *this=*this+a; } inline cpx operator-=(const cpx &a){ return *this=*this-a; } inline cpx operator*=(const cpx &a){ return *this=*this*a; } inline cpx operator/=(const cpx &a){ return *this=*this/a; } inline cpx conj(){ return cpx(r,-i); } }; template struct polynomial{ T a[len]; inline void clear(){ int t=len>>2<<2,i; for(i=0;i>2<<2,i; for(i=0;i>2<<2,i; for(i=0;i>=1,~j&t;); if(i,class cmp=std::less > struct priority_queue{ std::priority_queueins,del; inline void push(T a){ ins.push(a); } inline void erase(T a){ del.push(a); } inline void pop(){ while(!del.empty()&&ins.top()==del.top()) ins.pop(),del.pop(); ins.pop(); } inline T top(){ while(!del.empty()&&ins.top()==del.top()) ins.pop(),del.pop(); return ins.top(); } inline T second_top(){ T tmp=top(),ret; pop(); ret=top(); push(tmp); return ret; } inline void clear(){ while(!ins.empty()) ins.pop(); while(!del.empty()) del.pop(); } inline int size(){ return ins.size()-del.size(); } inline bool empty(){ return !size(); } }; } void exgcd(long long a,long long b,long long &d,long long &x,long long &y){ if(!b){ d=a; x=1; y=0; return; } exgcd(b,a%b,d,y,x); y-=a/b*x; } //template #define MAXN 200 #define EPS (1e-8) int T; int n,rx[MAXN*2+10],ry[MAXN*2+10],cx,cy; int d[MAXN*2+10][MAXN*2+10],d2[MAXN*2+10][MAXN*2+10]; bool vis[MAXN*2+10][MAXN*2+10]; double dist[MAXN*2+10][MAXN*2+10]; struct rect{ pii a,b; }a[MAXN+10]; pii st,ed; priority_queue,vector > ,greater > >q; void spfa(){ int i,j; for(i=1;i<=cx;i++) for(j=1;j<=cy;j++) dist[i][j]=1e20; dist[st.first][st.second]=0; q.push({0,st}); while(!q.empty()){ pii u=q.top().second; q.pop(); if(vis[u.first][u.second]) continue; // vis[u.first][u.second]=1; pii t=u; t.first--; if(t.first>=1){ if(dist[t.first][t.second]>dist[u.first][u.second]+1.0*(rx[u.first]-rx[t.first])/(d[t.first][t.second]+1)+EPS){ dist[t.first][t.second]=dist[u.first][u.second]+1.0*(rx[u.first]-rx[t.first])/(d[t.first][t.second]+1); q.push({dist[t.first][t.second],t}); } } // t=u; t.first++; if(t.first<=cx){ if(dist[t.first][t.second]>dist[u.first][u.second]+1.0*(rx[t.first]-rx[u.first])/(d[u.first][u.second]+1)+EPS){ dist[t.first][t.second]=dist[u.first][u.second]+1.0*(rx[t.first]-rx[u.first])/(d[u.first][u.second]+1); q.push({dist[t.first][t.second],t}); } } // t=u; t.second--; if(t.second>=1){ if(dist[t.first][t.second]>dist[u.first][u.second]+1.0*(ry[u.second]-ry[t.second])/(d2[t.first][t.second]+1)+EPS){ dist[t.first][t.second]=dist[u.first][u.second]+1.0*(ry[u.second]-ry[t.second])/(d2[t.first][t.second]+1); q.push({dist[t.first][t.second],t}); } } // t=u; t.second++; if(t.second<=cy){ if(dist[t.first][t.second]>dist[u.first][u.second]+1.0*(ry[t.second]-ry[u.second])/(d2[u.first][u.second]+1)+EPS){ dist[t.first][t.second]=dist[u.first][u.second]+1.0*(ry[t.second]-ry[u.second])/(d2[u.first][u.second]+1); q.push({dist[t.first][t.second],t}); } } } } int main() { Read(T); while(T--){ memset(d,0,sizeof d); memset(d2,0,sizeof d2); memset(vis,0,sizeof vis); cx=cy=0; Read(n); int i,j; for(i=1;i<=n;i++){ Read(a[i].a.first),Read(a[i].a.second); Read(a[i].b.first),Read(a[i].b.second); rx[++cx]=a[i].a.first,ry[++cy]=a[i].a.second; rx[++cx]=a[i].b.first,ry[++cy]=a[i].b.second; } Read(st.first),Read(st.second); Read(ed.first),Read(ed.second); rx[++cx]=st.first,ry[++cy]=st.second;; rx[++cx]=ed.first,ry[++cy]=ed.second; sort(rx+1,rx+cx+1); sort(ry+1,ry+cy+1); cx=unique(rx+1,rx+cx+1)-rx-1; cy=unique(ry+1,ry+cy+1)-ry-1; for(i=1;i<=n;i++){ a[i].a.first=lower_bound(rx+1,rx+cx+1,a[i].a.first)-rx; a[i].a.second=lower_bound(ry+1,ry+cy+1,a[i].a.second)-ry; a[i].b.first=lower_bound(rx+1,rx+cx+1,a[i].b.first)-rx; a[i].b.second=lower_bound(ry+1,ry+cy+1,a[i].b.second)-ry; d[a[i].a.first][a[i].a.second]++; d[a[i].b.first][a[i].a.second]--; d[a[i].a.first][a[i].b.second+1]--; d[a[i].b.first][a[i].b.second+1]++; d2[a[i].a.first][a[i].a.second]++; d2[a[i].b.first+1][a[i].a.second]--; d2[a[i].a.first][a[i].b.second]--; d2[a[i].b.first+1][a[i].b.second]++; } st.first=lower_bound(rx+1,rx+cx+1,st.first)-rx; st.second=lower_bound(ry+1,ry+cy+1,st.second)-ry; ed.first=lower_bound(rx+1,rx+cx+1,ed.first)-rx; ed.second=lower_bound(ry+1,ry+cy+1,ed.second)-ry; for(i=1;i<=cx;i++) for(j=1;j<=cy;j++){ d[i][j]+=d[i-1][j]+d[i][j-1]-d[i-1][j-1]; d2[i][j]+=d2[i-1][j]+d2[i][j-1]-d2[i-1][j-1]; } spfa(); printf("%.5lf\n",dist[ed.first][ed.second]); } }