#include using namespace std; const int MAXN = 505; const int INF = 50; struct Snake { int x1, y1, x2, y2; Snake() {}; Snake(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) { check(); }; void check() { assert(x1 >= 1 && x1 <= INF); assert(y1 >= 1 && y1 <= INF); assert(x2 >= 1 && x2 <= INF); assert(y2 >= 1 && y2 <= INF); assert(x1 == x2 || y1 == y2); if (x1 > x2) { swap(x1, x2); swap(y1, y2); } else if (y1 > y2) { swap(x1, x2); swap(y1, y2); } } void read() { scanf("%d %d %d %d", &x1, &y1, &x2, &y2); check(); } }; int distance(int x, int y, Snake s) { if (s.y1 == s.y2) { if (x > s.x1 && x <= s.x2) { return abs(s.y1 - y); } } if (s.x1 == s.x2) { if (y >= s.y1 && y <= s.y2) { return abs(s.x1 - x); } } int ans = min(abs(x - s.x1) + abs(y - s.y1), abs(x - s.x2) + abs(y - s.y2)); return ans; } int main() { /* Snake s(2, 2, 2, 2); cout << distance(1, 1, s) << endl; */ int T; scanf("%d", &T); assert(T >= 1 && T <= 50); while (T--) { int n; cin >> n; assert(n >= 1 && n <= 50); vector snakes(n); for (int i = 0; i < n; i++) { snakes[i].read(); } int ans = (int) 1e9; const int LARGE = 100; for (int x = 1; x <= LARGE; x++) { for (int y = 1; y <= LARGE; y++) { int mx = 0; for (int i = 0; i < n; i++) { mx = max(mx, distance(x, y, snakes[i])); } //cerr << x << " " << y << " " << mx << endl; ans = min(ans, mx); } } cout << ans << endl; } return 0; }