#include using namespace std; #define reg register typedef long long ll; #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i) char IO; int rd(){ int s=0,f=0; while(!isdigit(IO=getchar())) if(IO=='-') f=1; do s=(s<<1)+(s<<3)+(IO^'0'); while(isdigit(IO=getchar())); return f?-s:s; } const int N=810; const int z[5][4]={{0,1},{0,-1},{1,0},{-1,0}}; int n; int hx[N],cx; int hy[N],cy; int x1[N],yy[N],x2[N],y2[N]; int sx,sy,fx,fy; int cnt[N][N][4]; double dp[N][N]; struct node{ int x,y; double dis; bool operator < (const node __) const{ return dis>__.dis; } }; priority_queue Q; int main(){ rep(kase,1,rd()){ n=rd();cx=cy=0; rep(i,1,n) { x1[i]=rd(),yy[i]=rd(),x2[i]=rd(),y2[i]=rd(); hx[++cx]=x1[i]; hx[++cx]=x2[i]; hy[++cy]=yy[i]; hy[++cy]=y2[i]; } sx=rd(),sy=rd(),fx=rd(),fy=rd(); hx[++cx]=sx; hx[++cx]=fx; hy[++cy]=sy; hy[++cy]=fy; sort(hx+1,hx+cx+1),cx=unique(hx+1,hx+cx+1)-hx-1; sort(hy+1,hy+cy+1),cy=unique(hy+1,hy+cy+1)-hy-1; memset(cnt,0,sizeof cnt); rep(i,1,n) { x1[i]=lower_bound(hx+1,hx+cx+1,x1[i])-hx; x2[i]=lower_bound(hx+1,hx+cx+1,x2[i])-hx; yy[i]=lower_bound(hy+1,hy+cy+1,yy[i])-hy; y2[i]=lower_bound(hy+1,hy+cy+1,y2[i])-hy; rep(x,x1[i]+1,x2[i]-1) rep(y,yy[i]+1,y2[i]-1) rep(o,0,3) cnt[x][y][o]++; rep(x,x1[i],x1[i]) rep(y,yy[i]+1,y2[i]-1) cnt[x][y][0]++,cnt[x][y][1]++,cnt[x][y][2]++; rep(x,x2[i],x2[i]) rep(y,yy[i]+1,y2[i]-1) cnt[x][y][0]++,cnt[x][y][1]++,cnt[x][y][3]++; rep(y,yy[i],yy[i]) rep(x,x1[i]+1,x2[i]-1) cnt[x][y][2]++,cnt[x][y][3]++,cnt[x][y][0]++; rep(y,y2[i],y2[i]) rep(x,x1[i]+1,x2[i]-1) cnt[x][y][2]++,cnt[x][y][3]++,cnt[x][y][1]++; cnt[x1[i]][yy[i]][0]++; cnt[x1[i]][yy[i]][2]++; cnt[x2[i]][yy[i]][0]++; cnt[x2[i]][yy[i]][3]++; ; cnt[x1[i]][y2[i]][1]++; cnt[x1[i]][y2[i]][2]++; cnt[x2[i]][y2[i]][1]++; cnt[x2[i]][y2[i]][3]++; ; } fx=lower_bound(hx+1,hx+cx+1,fx)-hx; sx=lower_bound(hx+1,hx+cx+1,sx)-hx; sy=lower_bound(hy+1,hy+cy+1,sy)-hy; fy=lower_bound(hy+1,hy+cy+1,fy)-hy; rep(i,1,cx) rep(j,1,cy) dp[i][j]=1e12; Q.push((node){sx,sy,0});dp[sx][sy]=0; while(!Q.empty()) { int x=Q.top().x,y=Q.top().y; double t=Q.top().dis; Q.pop(); if(t>dp[x][y]) continue; //cout<cx||y1>cy) continue; double w=1.0*(abs(hx[x1]-hx[x])+abs(hy[y1]-hy[y]))/(1.0*cnt[x][y][i]+1.0); //cout<<"#"<dp[x][y]+w) { dp[x1][y1]=dp[x][y]+w; Q.push((node){x1,y1,dp[x1][y1]}); } } } //cout<