#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;

#define MAXN 200200
#define ll long long

int t, n, r[MAXN];
vector<pair<int,int> > pts;

ll cost(pair<int,int> a, pair<int,int> b) {

	if (b.first - a.first == b.second - a.second)
		return ((a.first + a.second) % 2) ? 0 : (b.first - a.first);

	return ((b.first - a.first) - (b.second - a.second) + ((a.first + a.second) % 2)) / 2;

}

int main() {

	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		pts.push_back(make_pair(1,1));
		for (int i = 0; i < n; i++) scanf("%d", &r[i]);
		for (int i = 0; i < n; i++) {
			int c; scanf("%d", &c);
			pts.push_back(make_pair(r[i], c));
		}
		sort(pts.begin(), pts.end());

		ll ans = 0;
		for (int i = 1; i <= n; i++) {
			ans += cost(pts[i-1], pts[i]);
		}

		printf("%lld\n", ans);
		pts.clear();

	}

}