#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main() {

	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t;
	cin>>t;

	while (t--) {

		ll n;
		cin>>n;

		ll r[n];
		vector<pair<ll, ll>> path(n+1);
		path[0] = {1, 1};
		for (int i = 0; i < n; i++) {
			cin>>r[i];
		}
		for (int i = 1; i <= n; i++) {
            ll c;
			cin>>c;
			path[i] = {r[i-1], c};
		}
		sort(path.begin(), path.end());

        ll cost = 0;
		for (int i = 1; i < path.size(); i++) {

            ll left = (path[i].first - path[i].second) - (path[i-1].first - path[i-1].second);
            ll free = path[i-1].first+path[i-1].second;

            if (free%2 == 0 && left == 0) {
                cost += path[i].first - path[i-1].first;
            }
            else if (free%2 == 1 && left == 0) {
                cost += 0;
            }
            else if (free%2 == 0) {
                cost += left/2;
            }
            else {
                cost += (left+1)/2;
            }
		}

		cout<<cost<<"\n";

	}
}
