#include<bits/stdc++.h>
using namespace std;
struct node{
	int r,c,d;
}a[200010];
int t,n,ans=0;
bool cmp(node a,node b){
	return a.r<b.r;
}
int main(){
	scanf("%d",&t);
	while(t--){
		ans=0;
		scanf("%d",&n);a[0]={1,1,0};
	    for(int i=1;i<=n;i++)scanf("%d",&a[i].r);
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i].c);
            a[i].d=a[i].r-a[i].c;
        }
	    sort(a+1,a+n+1,cmp);
	    for(int i=1;i<=n;i++){
            if(a[i].d==a[i-1].d){
               if(a[i].d%2==0)ans+=a[i].c-a[i-1].c;
            }
            else{
               if(a[i-1].d%2==0)ans+=(a[i].d-a[i-1].d)/2;
               else ans+=(a[i].d-a[i-1].d+1)/2;
            }
        }
        printf("%d\n",ans);
	}
	
}