#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf (ll)2e18
#define mod 1000000007
//#define mod 998244353
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
const ll N=17 ;
int main()
{
	fast ;
	ll t ;
	cin>>t ;
	while(t--)
	{
		ll n ;
		cin>>n ;
		ll r[n] ;
		for(ll i=0;i<n;i++) cin>>r[i] ;
		vector<pll>v ;
		for(ll i=0;i<n;i++)
		{
			ll c ;
			cin>>c ;
			v.push_back({r[i],c}) ;
		}
		sort(all(v)) ;
		ll curx=1,cury=1 ;
		ll ans=0 ;
		for(ll i=0;i<n;i++)
		{
			ll id1=abs(curx-cury) ;
			ll id2=abs(v[i].ff-v[i].ss) ;
			ll temp=(id2/2-id1/2) ;
			ans+=temp ;
			if(temp)
			{
				cury=v[i].ss ;
				curx=cury+2*(id2/2) ;
			}
			
			if(id2%2==0)
			{
				ans+=v[i].ff-curx ;
			}
			curx=v[i].ff ;
			cury=v[i].ss ;
		}
		cout<<ans<<endl ;
	}
	
	
}
