#include using namespace std; #define fwd(i, a, n) for (int i = (a); i < (n); i ++) #define rep(i, n) fwd(i, 0, n) #define all(X) begin(X), end(X) #define sz(X) ((int)X.size()) #define st first #define nd second #define pii pair #define vi vector #define ll long long #ifdef LOC auto &operator<<(auto &out, pair a) { return out << "(" << a.st << ", " << a.nd << ")"; } auto &operator<<(auto &out, auto a) { out << "{"; for (auto b : a) out << b << ", "; return out << "}"; } void dump(auto... x) { ((cerr << x << ", "), ...) << '\n'; } #define debug(x...) cerr << "[" #x "]: ", dump(x) #else #define debug(...) 0 #endif int turbo(int v, vector &g, vi& mt, vi& vis){ if(vis[v])return 0; vis[v] = 1; for(auto u : g[v]){ if(mt[u] == -1 || turbo(mt[u], g, mt, vis)){ mt[u] = v; mt[v] = u; return 1; } } return 0; } int turboMatching(vector &g, vi&mt){ int n = sz(g); vi vis(n); int res = 0, flow = 1; while(flow){ flow = 0; fill(all(vis), 0); rep(i, n){ if(mt[i] == -1 && turbo(i, g, mt, vis)){ flow++; } } res += flow; } return res; } void solve(){ int n; cin>>n; vector a(n); vector b(n); rep(i, n)cin>>a[i]; rep(i, n)cin>>b[i]; vector> g(2*n); rep(i, 2*n)g[i].reserve(n); vector mt(2*n, -1); int l = 0; int r = 1e9; while(l < r){ int m = (l + r)/ 2 + 1; rep(i, 2*n)mt[i] = -1; rep(i, 2*n)g[i].clear(); rep(i, n){ rep(j, n){ if(abs(a[i] - b[j]) >= m){ g[i].push_back(j + n); g[j+ n].push_back(i); } } } if(turboMatching(g, mt) == n){ l = m; }else{ r = m-1; } } cout<>t; while(t--){ solve(); } return 0; }