#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pl pair<ll,ll>
#define pll pair<ll,pl>

void solve()
{
    ll n,i,prevx,prevy,row,col,ans=0;
    vector <pl> v;
    
    cin>>n;
    ll R[n],C[n];
    for(i=0;i<n;i++)
        cin>>R[i];
    for(i=0;i<n;i++)
        cin>>C[i];
        
    for(i=0;i<n;i++)
        v.push_back({R[i],C[i]});
    
    sort(v.begin(),v.end());
    
    prevx = 1;
    prevy = 1;
    
    for(i=0;i<n;i++)
    {
        if(v[i].second < prevy)
        {
            while(true)
            {
                ;
            }
        }
        
        row = v[i].first - prevx;
        col = v[i].second - prevy;
        
        if(row < col)
        {
            while(true)
            {
                ;
            }
        }
        
        if(row == col)
        {
            if((prevx+prevy)%2 == 0)   
                ans += row;
                
            prevx = v[i].first;
            prevy = v[i].second;
        }
        else
        {
            if((prevx+prevy)%2 == 0)
                prevx++;
            
            prevx += col;
            prevy += col;
            
            ans += (v[i].first - prevx + 1)/2;
            prevx = v[i].first;
        }
    }
    
    cout<<ans<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int t;
    cin>>t;
    //t=1;
    while(t--)
        solve();
}

