#include using namespace std; const double inf = 1e15; int T, n, xl[205], xr[205], yl[205], yr[205], sumx[405][405], sumy[405][405], xa, xb, ya, yb; bool done[405][405]; double dis[405][405]; int main() { scanf("%d", &T); while (T--) { vector vx, vy; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d%d%d%d", xl + i, yl + i, xr + i, yr + i); vx.push_back(xl[i]), vx.push_back(xr[i]); vy.push_back(yl[i]), vy.push_back(yr[i]); } scanf("%d%d%d%d", &xa, &ya, &xb, &yb); vx.push_back(xa), vx.push_back(xb); vy.push_back(ya), vy.push_back(yb); sort(vx.begin(), vx.end()); vx.erase(unique(vx.begin(), vx.end()), vx.end()); sort(vy.begin(), vy.end()); vy.erase(unique(vy.begin(), vy.end()), vy.end()); for (int i = 0; i < (int)vx.size(); ++i) for (int j = 0; j < (int)vy.size(); ++j) dis[i][j] = inf, done[i][j] = false, sumx[i][j] = sumy[i][j] = 0; xa = lower_bound(vx.begin(), vx.end(), xa) - vx.begin(); xb = lower_bound(vx.begin(), vx.end(), xb) - vx.begin(); ya = lower_bound(vy.begin(), vy.end(), ya) - vy.begin(); yb = lower_bound(vy.begin(), vy.end(), yb) - vy.begin(); for (int i = 0; i < n; ++i) { xl[i] = lower_bound(vx.begin(), vx.end(), xl[i]) - vx.begin(); xr[i] = lower_bound(vx.begin(), vx.end(), xr[i]) - vx.begin(); yl[i] = lower_bound(vy.begin(), vy.end(), yl[i]) - vy.begin(); yr[i] = lower_bound(vy.begin(), vy.end(), yr[i]) - vy.begin(); if (xl[i] < xr[i]) { ++sumx[xl[i]][yl[i]]; --sumx[xr[i]][yl[i]]; if (yr[i] + 1 < (int)vy.size()) { --sumx[xl[i]][yr[i] + 1]; ++sumx[xr[i]][yr[i] + 1]; } } if (yl[i] < yr[i]) { ++sumy[xl[i]][yl[i]]; --sumy[xl[i]][yr[i]]; if (xr[i] + 1 < (int)vx.size()) { --sumy[xr[i] + 1][yl[i]]; ++sumy[xr[i] + 1][yr[i]]; } } } for (int i = 0; i < (int)vx.size(); ++i) for (int j = 1; j < (int)vy.size(); ++j) sumx[i][j] += sumx[i][j - 1], sumy[i][j] += sumy[i][j - 1]; for (int i = 1; i < (int)vx.size(); ++i) for (int j = 0; j < (int)vy.size(); ++j) sumx[i][j] += sumx[i - 1][j], sumy[i][j] += sumy[i - 1][j]; priority_queue>> q; q.emplace(dis[xa][ya] = 0, make_pair(xa, ya)); while (!q.empty()) { auto p = q.top(); q.pop(); int x = p.second.first, y = p.second.second; if (done[x][y]) continue; done[x][y] = true; if (x > 0) { double w = 1.0 * (vx[x] - vx[x - 1]) / (1 + sumx[x - 1][y]); if (dis[x][y] + w < dis[x - 1][y]) q.emplace(-(dis[x - 1][y] = dis[x][y] + w), make_pair(x - 1, y)); } if (x + 1 < (int)vx.size()) { double w = 1.0 * (vx[x + 1] - vx[x]) / (1 + sumx[x][y]); if (dis[x][y] + w < dis[x + 1][y]) q.emplace(-(dis[x + 1][y] = dis[x][y] + w), make_pair(x + 1, y)); } if (y > 0) { double w = 1.0 * (vy[y] - vy[y - 1]) / (1 + sumy[x][y - 1]); if (dis[x][y] + w < dis[x][y - 1]) q.emplace(-(dis[x][y - 1] = dis[x][y] + w), make_pair(x, y - 1)); } if (y + 1 < (int)vy.size()) { double w = 1.0 * (vy[y + 1] - vy[y]) / (1 + sumy[x][y]); if (dis[x][y] + w < dis[x][y + 1]) q.emplace(-(dis[x][y + 1] = dis[x][y] + w), make_pair(x, y + 1)); } } printf("%.5f\n", dis[xb][yb]); } return 0; }