#include using namespace std; const int N = 510; typedef double ld; const int inf = 2000000001; struct element{ int id; ld weight; }; struct cmp{ bool operator () (element x, element y){ return x.weight > y.weight; } }; priority_queue, cmp> hp; struct edge{ int ne, to; ld w; }e[2000100]; int he[N * N], tot = 0, n, m, S, T, vis[N * N], binx[N], biny[N], cntx, cnty; ld dis[N * N]; struct rectangle{ int x1, x2, y1, y2; }rec[N]; void add(int x, int y, ld w){ e[++tot].ne = he[x]; he[x] = tot; e[tot].to = y; e[tot].w = w; } void addedge(int x, int y, ld w){ add(x, y, w); add(y, x, w); } int sort_and_unique(int array[], int &n){ sort(array + 1, array + n + 1); int top = 0, i, j; for (i = 1; i <= n; i = j + 1){ j = i; while ((j < n) && (array[j + 1] == array[j])){ j++; } array[++top] = array[i]; } n = top; } void dijkstra(){ int i, j, x, y; while (!hp.empty()){ hp.pop(); } for (i = 1; i <= m; i++){ dis[i] = inf; vis[i] = 0; } dis[S] = 0; hp.push((element){S, 0}); while (!hp.empty()){ x = hp.top().id; hp.pop(); if (vis[x]){ continue; } vis[x] = 1; for (i = he[x]; i; i = e[i].ne){ y = e[i].to; if (dis[y] > dis[x] + e[i].w){ dis[y] = dis[x] + e[i].w; hp.push((element){y, dis[y]}); } } } } void init(){ memset(he, 0, sizeof(he)); tot = 0; } int main(){ //freopen("a.in", "r", stdin); //freopen("b.out", "w", stdout); int i, j, k, Ti; int stx, sty, edx, edy; scanf("%d", &Ti); while (Ti--){ init(); scanf("%d", &n); cntx = 0; cnty = 0; for (i = 1; i <= n; i++){ scanf("%d%d%d%d", &rec[i].x1, &rec[i].y1, &rec[i].x2, &rec[i].y2); binx[++cntx] = rec[i].x1; binx[++cntx] = rec[i].x2; biny[++cnty] = rec[i].y1; biny[++cnty] = rec[i].y2; } binx[++cntx] = 0; binx[++cntx] = 1000000000; biny[++cnty] = 0; biny[++cnty] = 1000000000; scanf("%d%d%d%d", &stx, &sty, &edx, &edy); binx[++cntx] = stx; binx[++cntx] = edx; biny[++cnty] = sty; biny[++cnty] = edy; sort_and_unique(binx, cntx); sort_and_unique(biny, cnty); m = cntx * cnty; for (i = 1; i <= cntx; i++){ for (j = 1; j <= cnty; j++){ if ((stx == binx[i]) && (sty == biny[j])){ S = (i - 1) * cnty + j; } if ((edx == binx[i]) && (edy == biny[j])){ T = (i - 1) * cnty + j; } if (j == cnty){ continue; } int pass_cnt = 1; for (k = 1; k <= n; k++){ if ((rec[k].x1 <= binx[i]) && (binx[i] <= rec[k].x2) && (biny[j] >= rec[k].y1) && (biny[j + 1] <= rec[k].y2)){ pass_cnt++; } } int cur = (i - 1) * cnty + j; addedge(cur, cur + 1, (ld)(biny[j + 1] - biny[j]) / (ld)pass_cnt); } } for (i = 1; i < cntx; i++){ for (j = 1; j <= cnty; j++){ int pass_cnt = 1; for (k = 1; k <= n; k++){ if ((rec[k].x1 <= binx[i]) && (binx[i + 1] <= rec[k].x2) && (biny[j] >= rec[k].y1) && (biny[j] <= rec[k].y2)){ pass_cnt++; } } int cur = (i - 1) * cnty + j; addedge(cur, cur + cnty, (ld)(binx[i + 1] - binx[i]) / (ld)pass_cnt); } } dijkstra(); printf("%.5f\n", dis[T] + 1e-9); } return 0; }