#include<bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define eps 0.000000001
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;
int a[maxn],b[maxn];
pair<int,int> p[maxn];
bool cmp(pair<int,int> a,pair<int,int> b){
	return a.first<b.first;
}
int main(){
	int T;scanf("%d",&T);
	while(T--){
		map<int,int> mp;
		int n;scanf("%d",&n);
		rep(i,1,n) scanf("%d",&a[i]);
		rep(i,1,n) scanf("%d",&b[i]);
		rep(i,1,n) p[i].first=a[i],p[i].second=b[i];
		sort(p+1,p+n+1,cmp);	
		int prex=1,prey=1,precha=0;	
		ll sum=0;
		rep(i,1,n){
			int cha=p[i].first-p[i].second;
			if(cha%2==0){
				if(cha==precha){
					sum+=p[i].first-prex;
				}else{
					sum+=(cha/2-precha/2);
				}
			}else{
				if(cha!=precha){
					sum+=(cha/2-precha/2);
				}else{
					sum+=0;
				}
			}
			prex=p[i].first;
			prey=p[i].second;
			precha=prex-prey;
		}
		cout<<sum<<endl;
	}
}
