#include <bits/stdc++.h>
#define forr(i,a,b) for(int i=(a);i<(b);i++)
#define forn(i,n) forr(i,0,n)
#define dforn(i,n) for(int i=n-1;i>=0;i--)
#define forall(it,v) for(auto it=v.begin();it!=v.end();it++)
#define sz(c) ((int)c.size())
#define rsz resize
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fst first
#define snd second

#ifdef ANARAP
//prueba
#else
//real
#endif

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

int main()
{
	#ifdef ANARAP
		freopen("input.in", "r", stdin);
		//freopen("output.out", "w", stdout);
		unsigned t0, t1; t0=clock();
	#endif
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int t; cin >> t;
	forn(T,t){
		int n; cin >> n;
		vector<ii> a(n+1);
		a[0].fst = 1;
		a[0].snd=1;
		forn(i,n) cin >> a[i+1].fst;
		forn(i,n) cin >> a[i+1].snd;
		sort(a.begin(), a.end());
		ll ans = 0;
		
		forn(i,n){
			int actual = a[i].fst+a[i].snd;
			ll difx = a[i+1].fst-a[i].fst;
			ll dify = a[i+1].snd-a[i].snd;
			if(dify == difx){
				if(actual%2 == 0) ans+=difx;
			}
			else{
				int dif = abs(difx-dify);
				if(actual%2)ans+=(dif+1)/2;
				else{
					a[i].fst++;
					actual++;
					difx = a[i+1].fst-a[i].fst;
					dify = a[i+1].snd-a[i].snd;
					if(dify == difx){
						if(actual%2 == 0) ans+=difx;
					}
					else{
						int dif = abs(difx-dify);
						if(actual%2)ans+=(dif+1)/2;
					}
				}
			}
		}
		cout << ans << '\n';
	}
	
	
	#ifdef ANARAP
	t1 = clock();double time = (double(t1-t0)/CLOCKS_PER_SEC); cout << "Execution Time: " << time << endl;
	#endif
	return 0;
}

