#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define IN insert
#define ALL(a) a.begin(),a.end()
typedef long long int ll;

ll solve(pair<ll, ll> p1, pair<ll, ll> p2) {

	if (p1.ff - p1.ss == p2.ff - p2.ss) {
		// cout << p1.ff << " " << p1.ss << " " << " " << p2.ff << " " << p2.ss << endl;
		if ((p1.ff + p1.ss) % 2)return 0;
		else return p2.ff - p1.ff;
	}
	p2.ff = p2.ff - (p1.ff - 1);
	p2.ss = p2.ss - (p1.ss - 1);
	if ((p1.ff + p1.ss) % 2 == 0) {
		return (p2.ff - p2.ss) / 2;
	}
	else {
		return (p2.ff - p2.ss + 1 ) / 2;
	}
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output56.txt", "w", stdout);
#endif
	ll t; cin >> t;
	while (t--) {
		ll n; cin >> n;
		vector<pair<ll, ll>> v(n);
		for (int i = 0; i < n; i++) {
			ll a; cin >> a;
			v[i].ff = a;
		} for (int i = 0; i < n; i++) {
			ll a; cin >> a;
			v[i].ss = a;
		}
		v.pb({1, 1});
		sort(ALL(v));
		ll ans = 0;
		for (int i = 1; i < v.size(); i++) {
			ans += solve(v[i - 1], v[i]);
			// cout << ans << endl;
		}
		cout << ans << endl;
	}
}
