#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;

LL N;
ii A[200100];
void main1() {
	cin >> N;
	for (LL i = 0; i < N; i++) {
		cin >> A[i].fi;
	}

	for (LL i = 0; i < N; i++) {
		cin >> A[i].se;
	}

	A[N] = {1, 1};
	N++;

	sort(A, A + N, [&](ii a, ii b) {
		return a.fi + a.se < b.fi + b.se;
	});

	LL ans = 0;
	for (LL i = 1; i < N; i++) {
		ii a = A[i - 1];
		ii b = A[i];

		LL l1 = a.fi - a.se;
		LL l2 = b.fi - b.se;

		if (l1 == l2 && l1 % 2 == 0) {
			ans += b.fi - a.fi;
			continue;
		}

		l1 /= 2;
		l2 /= 2;

		ans += l2 - l1;
	}

	cout << ans << endl;
}

LL T2;
int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> T2;

	while (T2--) {
		main1();
	}

	return 0;
}