#include using namespace std; int t, n; int xa[205], xb[205], ya[205], yb[205], xx[905], yy[905]; int za[905][905], zb[905][905]; double d[905][905]; priority_queue>, vector>>, greater>>> q; int sa, sb, ta, tb; int main() { scanf("%d", &t); while (t--) { map mx, my; scanf("%d", &n); for (int i = 0; i <= n; i++) { scanf("%d%d%d%d", xa + i, ya + i, xb + i, yb + i); mx[xa[i]] = 0; mx[xb[i]] = 0; mx[xb[i] + 1] = 0; my[ya[i]] = 0; my[yb[i]] = 0; my[yb[i] + 1] = 0; } int ca = 0, cb = 0; for (auto& i : mx) xx[i.second = ca++] = i.first; for (auto& i : my) yy[i.second = cb++] = i.first; for (int i = 0; i < ca; i++) for (int j = 0; j < cb; j++) { za[i][j] = zb[i][j] = 0; d[i][j] = 0; } za[0][0] = zb[0][0] = 1; for (int i = 0; ; i++) { if (i == n) { sa = mx[xa[i]]; sb = mx[xb[i]]; ta = my[ya[i]]; tb = my[yb[i]]; break; } za[mx[xa[i]]][my[ya[i]]]++; za[mx[xa[i]]][my[yb[i]]]--; za[mx[xb[i] + 1]][my[ya[i]]]--; za[mx[xb[i] + 1]][my[yb[i]]]++; zb[mx[xa[i]]][my[ya[i]]]++; zb[mx[xa[i]]][my[yb[i] + 1]]--; zb[mx[xb[i]]][my[ya[i]]]--; zb[mx[xb[i]]][my[yb[i] + 1]]++; } for (int i = 0; i < ca; i++) for (int j = 0; j < cb; j++) { d[i][j] = 0; if (i) { za[i][j] += za[i - 1][j]; zb[i][j] += zb[i - 1][j]; } if (j) { za[i][j] += za[i][j - 1]; zb[i][j] += zb[i][j - 1]; } if (i && j) { za[i][j] -= za[i - 1][j - 1]; zb[i][j] -= zb[i - 1][j - 1]; } } // for (int i = 0; i < ca; i++) for (int j = 0; j < cb; j++) printf("%d%c", za[i][j], " \n"[j == cb - 1]); // for (int i = 0; i < ca; i++) for (int j = 0; j < cb; j++) printf("%d%c", zb[i][j], " \n"[j == cb - 1]); // for (int i = 0; i < ca; i++) printf("%d%c", xx[i], " \n"[i == ca - 1]); // for (int i = 0; i < cb; i++) printf("%d%c", yy[i], " \n"[i == cb - 1]); d[sa][ta] = 1; q.emplace(1, make_pair(sa, ta)); // int cccc = 0; while (!q.empty()) { double di = q.top().first; int tx = q.top().second.first; int ty = q.top().second.second; q.pop(); if (d[tx][ty] != di) continue; // printf("d[%d][%d]=%.5lf\n", tx, ty, d[tx][ty]); // if (cccc ++ > 10 ) return 0; if (tx) { double dd = di + (double)(xx[tx] - xx[tx - 1]) / zb[tx - 1][ty]; if (d[tx - 1][ty] == 0 || dd + 1e-9 < d[tx - 1][ty]) q.emplace(d[tx - 1][ty] = dd, make_pair(tx - 1, ty)); } if (ty) { double dd = di + (double)(yy[ty] - yy[ty - 1]) / za[tx][ty - 1]; if (d[tx][ty - 1] == 0 || dd + 1e-9 < d[tx][ty - 1]) q.emplace(d[tx][ty - 1] = dd, make_pair(tx, ty - 1)); } if (tx != ca - 1) { double dd = di + (double)(xx[tx + 1] - xx[tx]) / zb[tx][ty]; if (d[tx + 1][ty] == 0 || dd + 1e-9 < d[tx + 1][ty]) q.emplace(d[tx + 1][ty] = dd, make_pair(tx + 1, ty)); } if (ty != cb - 1) { double dd = di + (double)(yy[ty + 1] - yy[ty]) / za[tx][ty]; if (d[tx][ty + 1] == 0 || dd + 1e-9 < d[tx][ty + 1]) q.emplace(d[tx][ty + 1] = dd, make_pair(tx, ty + 1)); } // printf("%d\n", (int)q.size()); } // for (int i = 0; i < ca; i++) for (int j = 0; j < cb; j++) printf("%.1lf%c", d[i][j], " \n"[j == cb - 1]); printf("%.5lf\n", d[sb][tb] - 1); } }