#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) { vector> graph(a.size()); for(int i = 0; i < a.size(); i++) { for(int j = 0; j < b.size(); j++) { if(abs(a[i] - b[j]) >= delta) { graph[i].push_back(j); } } } auto l = Match(graph, a.size(), b.size()); for(auto &it: l) { if(it == -1) { return false; } } 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); } 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"; } return 0; }