#include using namespace std; #define fi first #define sc second #define pii pair #define pb push_back #define umap unordered_map #define mset multiset #define pq priority_queue #define ull unsigned long long #define i128 __int128 const int maxn=2e5+10; int n,x[maxn],m,y[maxn]; vector vec[maxn]; void solve(){ cin>>n; for(int i=1;i<=n;i++) cin>>x[i]>>y[i]; cin>>m; for(int i=1;i<=n;i++){ int a,b; cin>>a>>b; vec[a].pb(b); } int res=1e9; for(int i=1;i<=n;i++){ for(int j=0;j<1e3;j++){ auto p=upper_bound(vec[j].begin(),vec[j].end(),y[i]); if(p!=vec[j].end()) res=min(res,abs(x[i]-j)+abs(y[i]-(*p))); if(p!=vec[j].begin()) p--,res=min(res,abs(x[i]-j)+abs(y[i]-(*p))); } } cout<>t; while(t--) solve(); return 0; } /* Samples input: output: THINGS TODO: ??freopen??????? ???? ???????????? */