#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll t = 1,n,m,c,u,v,x,y,z;
string s;
struct st{ll x,y;}p[200009];
bool cmp(const st &a,const st &b){return a.x < b.x;}
int main(){cin>>t;
while (t --){
	cin>>n; ll ans = 0;
	for (ll i = 1;i <= n;i += 1) cin>>p[i].x;
	for (ll i = 1;i <= n;i += 1) cin>>p[i].y;
	sort(p + 1,p + n + 1,cmp); p[0].x = 1;
	ll pre = 0;
	for (ll i = 1;i <= n;i += 1){
		ll qwq = p[i].x - p[i].y;
		if (qwq / 2 != pre / 2) ans += qwq / 2 - pre / 2;
		else if (pre % 2 == 0 && qwq % 2 == 0) ans += p[i].x - p[i - 1].x;
		//cout<<ans<<endl;
		pre = qwq;
	}
	cout<<ans<<endl;
}
	return 0;
}