#include #define y1 absdsd using namespace std; typedef long long LL; const int N = 205; int x1[N], x2[N], y1[N], y2[N], prex[N << 1][N << 1], prey[N << 1][N << 1]; double dis[N << 1][N << 1]; bool vis[N << 1][N << 1]; struct qq { int x, y; }; queue q; int main() { #ifdef TEST freopen("input.txt", "r", stdin); #endif int T; cin >> T; while (T--) { int n; scanf("%d", &n); vector allx, ally; for (int i = 0; i < n; ++i) { scanf("%d%d%d%d", &x1[i], &y1[i], &x2[i], &y2[i]); allx.push_back(x1[i]); allx.push_back(x2[i]); ally.push_back(y1[i]); ally.push_back(y2[i]); } int sx, sy, tx, ty; scanf("%d%d%d%d", &sx, &sy, &tx, &ty); allx.push_back(sx); allx.push_back(tx); ally.push_back(sy); ally.push_back(ty); sort(allx.begin(), allx.end()); allx.resize(unique(allx.begin(), allx.end()) - allx.begin()); sort(ally.begin(), ally.end()); ally.resize(unique(ally.begin(), ally.end()) - ally.begin()); sx = lower_bound(allx.begin(), allx.end(), sx) - allx.begin(); tx = lower_bound(allx.begin(), allx.end(), tx) - allx.begin(); sy = lower_bound(ally.begin(), ally.end(), sy) - ally.begin(); ty = lower_bound(ally.begin(), ally.end(), ty) - ally.begin(); memset(prex, 0, sizeof(prex)); memset(prey, 0, sizeof(prey)); for (int i = 0; i < n; ++i) { x1[i] = lower_bound(allx.begin(), allx.end(), x1[i]) - allx.begin(); x2[i] = lower_bound(allx.begin(), allx.end(), x2[i]) - allx.begin(); y1[i] = lower_bound(ally.begin(), ally.end(), y1[i]) - ally.begin(); y2[i] = lower_bound(ally.begin(), ally.end(), y2[i]) - ally.begin(); for (int j = y1[i]; j <= y2[i]; ++j) { prex[x1[i]][j]++; prex[x2[i]][j]--; } for (int j = x1[i]; j <= x2[i]; ++j) { prey[j][y1[i]]++; prey[j][y2[i]]--; } } for (int j = 0; j < ally.size(); ++j) { for (int i = 1; i < allx.size(); ++i) { prex[i][j] += prex[i - 1][j]; } } for (int i = 0; i < allx.size(); ++i) { for (int j = 1; j < ally.size(); ++j) { prey[i][j] += prey[i][j - 1]; } } for (int i = 0; i < allx.size(); ++i) { for (int j = 0; j < ally.size(); ++j) { dis[i][j] = 1e23; } } dis[sx][sy] = 0.; q.push(qq{sx, sy}); vis[sx][sy] = true; while (!q.empty()) { auto x = q.front(); q.pop(); vis[x.x][x.y] = false; qq to = x; if (x.x + 1 != allx.size()) { to.x++; double ds = dis[x.x][x.y] + (allx[to.x] - allx[x.x]) / (prex[x.x][x.y] + 1.); if (dis[to.x][to.y] > ds + 1e-6) { dis[to.x][to.y] = ds; if (!vis[to.x][to.y]) { vis[to.x][to.y] = true; q.push(to); } } } to = x; if (x.y + 1 != ally.size()) { to.y++; double ds = dis[x.x][x.y] + (ally[to.y] - ally[x.y]) / (prey[x.x][x.y] + 1.); if (dis[to.x][to.y] > ds + 1e-6) { dis[to.x][to.y] = ds; if (!vis[to.x][to.y]) { vis[to.x][to.y] = true; q.push(to); } } } to = x; if (x.x) { to.x--; double ds = dis[x.x][x.y] + (allx[x.x] - allx[to.x]) / (prex[to.x][x.y] + 1.); if (dis[to.x][to.y] > ds + 1e-6) { dis[to.x][to.y] = ds; if (!vis[to.x][to.y]) { vis[to.x][to.y] = true; q.push(to); } } } to = x; if (x.y) { to.y--; double ds = dis[x.x][x.y] + (ally[x.y] - ally[to.y]) / (prey[x.x][to.y] + 1.); if (dis[to.x][to.y] > ds + 1e-6) { dis[to.x][to.y] = ds; if (!vis[to.x][to.y]) { vis[to.x][to.y] = true; q.push(to); } } } } printf("%.5f\n", dis[tx][ty]); } return 0; }