#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-Ofast")
#pragma GCC optimize ("unroll-loops")
#define TASK "task"

using namespace std;

void openFiles() {
    #ifdef THEMIS
    freopen(TASK ".inp", "r", stdin);
    freopen(TASK ".out", "w", stdout);
    #endif
}

const long long MOD = 1e9 + 7;
const int maxN = 2e6 + 5;

int fact[maxN];

void factorial(int n) {
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) {
        fact[i] = 1ll * fact[i - 1] * i % MOD;
    }
}

int Pow(int b, int e = MOD - 2) {
    if (e == 0) return 1;
    int x = Pow(b, e / 2);
    if (e % 2 == 0) return 1ll * x * x % MOD;
    return (1ll * x * x % MOD) * b % MOD;
}

int catalan(int n) {
    int res = 1ll * fact[2 * n] * Pow(fact[n]) % MOD;
    res = 1ll * res * Pow(fact[n + 1]) % MOD;
    return res; 
}

void BracketSequencesI() { /// cses
    int n; cin >> n;
    if (n % 2 == 1) {
        cout << 0;
        return;
    }
    n /= 2;
    factorial(2 * n + 1);
    cout << catalan(n);
}

void BracketSequencesII() { /// cses
    int n; cin >> n;
    string s; cin >> s;
    if (n % 2 == 1) {
        cout << 0;
        return;
    }
    factorial(2 * n + 1);
    int k = 0;
    for (char i : s) {
        if (i == '(') k++;
        else k--;
        if (k < 0) break;
        if (k > n / 2) {
            k = -1;
            break;
        }
    }
    if (k < 0) {
        cout << 0;
        return;
    }
}

typedef pair<int, int> i2;

void solveF_TriangularPaths() {
    int t; cin >> t;
    while (t--) {
        int n; cin >> n;
        vector<i2> arr(n, i2(0, 0));
        for (int i = 0; i < n; ++i) cin >> arr[i].first;
        for (int i = 0; i < n; ++i) cin >> arr[i].second;
        sort(arr.begin(), arr.end(), [] (i2 a, i2 b) {
            if (a.second - a.first == b.second - b.first) return a.first < b.first;
            return a.first - a.second < b.first - b.second;
        });
        int curr = 0, x = 1, y = 1;
        long long res = 0;
        for (auto it : arr) {
            int xx = it.first;
            int yy = it.second;
            int cnt = (xx - yy) / 2 - (x - y) / 2;
            res += cnt;
            int tmp = (xx - yy) - (x - y);
            if ((xx - yy) % 2 == 0 && (xx - yy) == (x - y)) res += yy - y;
            x = xx;
            y = yy;
        }
        cout << res << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    openFiles();
    // BracketSequencesI();
    // BracketSequencesII();
    solveF_TriangularPaths();
}