#include #define fi first #define se second #define pb push_back #define SZ(x) ((int)x.size()) #define L(i,u) for (register int i=head[u]; i; i=nxt[i]) #define rep(i,a,b) for (register int i=(a); i<=(b); i++) #define per(i,a,b) for (register int i=(a); i>=(b); i--) using namespace std; typedef long long ll; typedef unsigned int ui; typedef pair Pii; typedef pair Pdi; typedef vector Vi; template inline void read(T &x){ x=0; char c=getchar(); int f=1; while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();} while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f; } template inline void umin(T &x, T y){x=x inline void umax(T &x, T y){x=x>y?x:y;} inline ui R() { static ui seed=416; return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13; } const int N = 1003; struct rec{ int x1,y1,x2,y2; }a[N],f; int n,m,s[N],t[N],heng[N][N],shu[N][N];double dis[N][N]; void ini(rec c){ s[++n]=c.x1; s[++n]=c.x2; t[++m]=c.y1; t[++m]=c.y2; } priority_queue,greater >heap; inline double calc(int i, int j, int x, int y){ if(i+j>x+y)swap(i,x),swap(j,y); if(i==x)return (t[y]-t[y-1])/(1.0+heng[i][j]); return (s[x]-s[x-1])/(1.0+shu[i][j]); } rec getreal(rec c){ c.x1=lower_bound(s+1,s+n+1,c.x1)-s; c.x2=lower_bound(s+1,s+n+1,c.x2)-s; c.y1=lower_bound(t+1,t+m+1,c.y1)-t; c.y2=lower_bound(t+1,t+m+1,c.y2)-t; return c; } int dx[]={1,-1,0,0}; int dy[]={0,0,1,-1}; int main() { int T;read(T);while(T--){ int tot;read(tot); rep(i,1,tot)read(a[i].x1),read(a[i].y1),read(a[i].x2),read(a[i].y2); read(f.x1),read(f.y1),read(f.x2),read(f.y2); n=m=0;rep(i,1,tot)ini(a[i]);ini(f); sort(s+1,s+n+1);sort(t+1,t+m+1);assert(n==m);//no!!! memset(heng,0,sizeof(heng));memset(shu,0,sizeof(shu));f=getreal(f); rep(i,1,tot){ a[i]=getreal(a[i]); a[i].y2--; heng[a[i].x1][a[i].y1]++; heng[a[i].x1][a[i].y2+1]--; heng[a[i].x2+1][a[i].y1]--; heng[a[i].x2+1][a[i].y2+1]++; a[i].y2++; a[i].x2--; shu[a[i].x1][a[i].y1]++; shu[a[i].x1][a[i].y2+1]--; shu[a[i].x2+1][a[i].y1]--; shu[a[i].x2+1][a[i].y2+1]++; a[i].x2++; } rep(i,1,n)rep(j,1,m)heng[i][j]+=heng[i][j-1]; rep(i,1,n)rep(j,1,m)heng[i][j]+=heng[i-1][j]; rep(i,1,n)rep(j,1,m)shu[i][j]+=shu[i][j-1]; rep(i,1,n)rep(j,1,m)shu[i][j]+=shu[i-1][j]; rep(i,1,n)rep(j,1,m)dis[i][j]=1e9+3;dis[f.x1][f.y1]=0; heap.push(Pdi(0,f.x1*N+f.y1)); while(!heap.empty()){ Pdi tmp=heap.top();heap.pop();int x=tmp.se/N,y=tmp.se%N; if(dis[x][y]!=tmp.fi)continue; rep(k,0,3)if(x+dx[k]>=1&&x+dx[k]<=n&&y+dy[k]>=1&&y+dy[k]<=m) if(dis[x+dx[k]][y+dy[k]]>dis[x][y]+calc(x,y,x+dx[k],y+dy[k])){ dis[x+dx[k]][y+dy[k]]=dis[x][y]+calc(x,y,x+dx[k],y+dy[k]); heap.push(Pdi(dis[x+dx[k]][y+dy[k]],(x+dx[k])*N+y+dy[k])); } } printf("%.5lf\n",dis[f.x2][f.y2]); } return 0; }