#include using namespace std; /* vector Match(vector>& graph, int n, int m) { vector l(n, -1), r(m, n), q, dist; function dfs = [&](int u) { if(u == n) return true; int d = dist[u]; dist[u] = -1; for(auto v : graph[u]) { if(dist[r[v]] == d + 1 && dfs(r[v])) { return l[u] = v, r[v] = u, true; } } return false; }; while(true) { dist.assign(n + 1, -1);q.clear(); for(int i = 0; i < n; ++i) { if(l[i] == -1) { dist[i] = 0, q.push_back(i); } } for(int i = 0; i < (int)q.size(); ++i) { int u = q[i]; if(u == n) break; for(auto v: graph[u]) { if(dist[r[v]] == -1) { dist[r[v]] = 1 + dist[q[i]], q.push_back(r[v]); } } } if(dist[n] == -1) break; for(int i = 0; i < n; ++i) { if(l[i] == -1) { dfs(i); } } } return l; } bool check(const vector &a, const vector &b, int delta) { int __next = 0; int last_i = -1; vector taken(b.size(), false); for(int i = 0; i < (int)a.size(); i++) { while(__next < (int)b.size() && b[__next] - a[i] < delta) { __next++; } if(__next == (int)a.size()) { last_i = i; break; } taken[__next] = true; __next++; } if(last_i == -1) { return true; } __next = 0; for(int i = last_i; i < (int)a.size(); i++) { while(__next < (int)b.size() && taken[__next]) { __next++; } if(__next == (int)b.size() || a[i] - b[__next] < delta) { return false; } taken[__next] = true; __next++; } return true; } */ int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while(t--) { int n; cin >> n; vector a(n), b(n); // int __max = 0; for(auto &it: a) { cin >> it; // __max = max(__max, it); } for(auto &it: b) { cin >> it; // __max = max(__max, it); } sort(a.begin(), a.end()); sort(b.begin(), b.end()); /* int curr = 0; for(int h = (1 << 29); h; h >>= 1) { if(curr + h <= __max && check(a, b, curr + h)) { curr += h; } } cout << curr << "\n"; */ int64_t ans = abs(b[0] - a[0]); for (int i = 0; i < n; ++i) { ans = min(ans, abs(b[i] - a[i])); } for (int i = 0; i < n; ++i) { // i is the displacement int64_t curr = (int64_t)1e18; for (int j = 0; j < n; ++j) { if (i + j < n) { curr = min(curr, abs(b[i + j] - a[j])); } else { curr = min(curr, abs(b[i + j - n] - a[j])); } } ans = max(ans, curr); } cout << ans << '\n'; } return 0; }