// 1506f.cpp
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

void solve() {
    int n;
    cin >> n;
    vector<pair<ll, ll>> v(n);

    for (int i = 0; i < n; i++)
        cin >> v[i].first;
    for (int i = 0; i < n; i++)
        cin >> v[i].second;

    sort(v.begin(), v.end());

    auto last = make_pair(1LL, 1LL);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (v[i] == last)
            continue;

        if (v[i].first - last.first == v[i].second - last.second) {
            ans += (last.first + last.second) % 2 == 0 ? v[i].first - last.first : 0;
            last = v[i];
            continue;
        }

        ll dr = v[i].first - last.first;
        ll dc = v[i].second - last.second;
        // --d;
        if ((last.first + last.second) % 2 == 0) {
            ans += (dr - dc)/2;
        } else {
            ans += (dr - dc + 1)/2;
        }
        last = v[i];
    }

    cout << ans << endl;
}

int main() {
    int tc;
    cin >> tc;
    while (tc--)
        solve();
}