#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
pair<ll,ll>p[200020];
int main(void){
    ll t,n,i,ans,x,y;
    cin>>t;
    while(t--){
        ans=0;
        scanf("%lld",&n);
        n++;
        p[1]=make_pair(1ll,1ll);
        for(i=2;i<=n;i++) scanf("%lld",&p[i].first);
        for(i=2;i<=n;i++) scanf("%lld",&p[i].second);
        sort(p+1,p+n+1);
        for(i=2;i<=n;i++){
            x=p[i-1].first-p[i-1].second;
            y=p[i].first-p[i].second;
            if(x==y&&x%2==0){
                ans+=p[i].first-p[i-1].first;
                continue;
            }
            x=x/2,y=y/2;
            ans=ans+y-x;
        }
        printf("%lld\n",ans);
    }
}