#include using namespace std; #define Dv(v) for (auto x : v) cerr << x << ' '; cerr << endl; #define D(x) cerr << #x << " = " << x << ", " using ll = long long; using vi = vector; using vvi = vector; const ll INF = 1e18; #define VEI(w,e) ((E[e].u == w) ? E[e].v : E[e].u) #define CAP(w,e) ((E[e].u == w) ? E[e].cap[0] - E[e].flow : E[e].cap[1] + E[e].flow) #define ADD(w,e,f) E[e].flow += ((E[e].u == w) ? (f) : (-(f))) struct Edge { int u, v; ll cap[2], flow; }; vi d, act; vector E; vvi adj; void addEdge(int x, int y, pair c) { Edge e; e.u = x; e.v = y; e.cap[0] = c.first; e.cap[1] = c.second; adj[x].push_back(E.size()); adj[y].push_back(E.size()); E.push_back(e); } bool bfs(int s, int t) { queue Q; d = vi(adj.size(), -1); d[t] = 0; Q.push(t); while (not Q.empty()) { int u = Q.front(); Q.pop(); for (int i=0; i < int(adj[u].size()); ++i) { int e = adj[u][i], v = VEI(u, e); if (CAP(v, e) > 0 and d[v] == -1) { d[v] = d[u] + 1; Q.push(v); } } } return d[s] >= 0; } ll dfs(int u, int t, ll bot) { if (u == t) return bot; for (; act[u] < int(adj[u].size()); ++act[u]) { int e = adj[u][act[u]]; if (CAP(u, e) > 0 and d[u] == d[VEI(u, e)] +1) { ll inc = dfs(VEI(u, e),t,min(bot,CAP(u,e))); if (inc) { ADD(u, e, inc); return inc; } } } return 0; } ll maxflow(int s, int t) { //for (int i=0; i < int(E.size()); ++i) E[i].flow = 0; ll flow = 0, bot; while (bfs(s, t)) { act = vi(adj.size(), 0); while((bot = dfs(s, t, INF))) flow += bot; } return flow; } ll ab(ll x) { return x > 0 ? x : -x; } bool test(const vi& a, const vi& b, ll dst) { int n = (int)a.size(); int N = 2*n+2; adj = vvi(N); E.clear(); for (int i=0; i < n; ++i) { addEdge(0, i+1, {1, 0}); addEdge(i+n+1, N-1, {1, 0}); for (int j=0; j < n; ++j) { if (a[i]-b[j] >= dst || a[i]-b[j] <= -dst) { addEdge(i+1, j+n+1, {1, 0}); } } } return maxflow(0, N-1) == n; } int main() { ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while(T--) { int n; cin >> n; vi a(n); vi b(n); for (auto& x : a) cin >> x; for (auto& x : b) cin >> x; sort(a.begin(), a.end()); sort(b.begin(), b.end()); ll best = 0; for (int d=0; d <= n; ++d) { ll cur = 1e9; for (int i=0; i < d; ++i) { cur = min(cur, ab(a[i]-b[n-d+i])); } for (int i=d; i < n; ++i) { cur = min(cur, ab(a[i]-b[i-d])); } best = max(best, cur); } cout << best << '\n'; } }