#include #include #include #include using namespace std; typedef long long ll; struct node { ll x, y; void read() {scanf("%lld%lld", &x, &y);} node() {} node(ll _1, ll _2) {x = _1, y = _2;} }; struct squ { node p1, p2; void read() {p1.read(), p2.read();} }; bool is_in(node p, squ X) { return X.p1.x <= p.x && p.x <= X.p2.x && X.p1.y <= p.y && p.y <= X.p2.y; } int n; squ S[222]; int Head[800010], Next[800010], Go[800010], Cnt = 0; double Val[800010]; void addedge(int x, int y, double z) { Go[++Cnt] = y; Next[Cnt] = Head[x]; Head[x] = Cnt; Val[Cnt] = z; } vector Vx(0), Vy(0); int getid(int a, int b) { return a * Vy.size() + b + 1; } int calc(node X) { int cnt = 0; for(int i = 1; i <= n; i++) cnt += is_in(X, S[i]); return cnt; } double F[800010]; bool vis[800010]; double Solve() { scanf("%d", &n); Vx.clear(), Vy.clear(); for(int i = 1; i <= n; i++) S[i].read(); for(int i = 1; i <= n; i++) Vx.push_back(S[i].p1.x *= 2), Vx.push_back(S[i].p2.x *= 2); for(int i = 1; i <= n; i++) Vy.push_back(S[i].p1.y *= 2), Vy.push_back(S[i].p2.y *= 2); // ans /= 2 node A, B; A.read(), B.read(); Vx.push_back(A.x *= 2), Vx.push_back(B.x *= 2); Vy.push_back(A.y *= 2), Vy.push_back(B.y *= 2); sort(Vx.begin(), Vx.end()), Vx.resize(unique(Vx.begin(), Vx.end()) - Vx.begin()); sort(Vy.begin(), Vy.end()), Vy.resize(unique(Vy.begin(), Vy.end()) - Vy.begin()); /*for(int i = (int) Vx.size() - 1; i > 0; i--) Vx.push_back((Vx[i] + Vx[i - 1]) / 2); for(int i = (int) Vy.size() - 1; i > 0; i--) Vy.push_back((Vy[i] + Vy[i - 1]) / 2); sort(Vx.begin(), Vx.end()), Vx.resize(unique(Vx.begin(), Vx.end()) - Vx.begin()); sort(Vy.begin(), Vy.end()), Vy.resize(unique(Vy.begin(), Vy.end()) - Vy.begin());*/ memset(Head, 0, sizeof Head), Cnt = 0; for(int i = 0; i < Vx.size(); i++) for(int j = 0; j < Vy.size(); j++) { int w = getid(i, j); // vertical if(i + 1 != Vx.size()) { int gV = w + Vy.size(); double lenV = (Vx[i + 1] - Vx[i]) / (1. + calc(node((Vx[i] + Vx[i + 1]) / 2, Vy[j]))); addedge(w, gV, lenV), addedge(gV, w, lenV); } if(j + 1 != Vy.size()) { int gH = w + 1; double lenH = (Vy[j + 1] - Vy[j]) / (1. + calc(node(Vx[i], (Vy[j] + Vy[j + 1]) / 2))); addedge(w, gH, lenH), addedge(gH, w, lenH); } } for(int i = 1; i <= Vx.size() * Vy.size(); i++) F[i] = 1e100; vector V(1, getid(lower_bound(Vx.begin(), Vx.end(), A.x) - Vx.begin(), lower_bound(Vy.begin(), Vy.end(), A.y) - Vy.begin())); F[V[0]] = 0; int E = getid(lower_bound(Vx.begin(), Vx.end(), B.x) - Vx.begin(), lower_bound(Vy.begin(), Vy.end(), B.y) - Vy.begin()); memset(vis, 0, sizeof vis); for(int i = 0; i < V.size(); i++) { int x = V[i]; vis[x] = 0; for(int T = Head[x]; T; T = Next[T]) if(F[Go[T]] > F[x] + Val[T]) { F[Go[T]] = F[x] + Val[T]; if(!vis[Go[T]]) vis[Go[T]] = 1, V.push_back(Go[T]); } } return F[E] / 2; } int main() { int T; scanf("%d", &T); while(T--) { printf("%.5lf\n", Solve()); } return 0; }