#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)
#define rep1(i, n) for (int i = 1; i < (int)(n); ++ i)
#define foreach(itr, c) for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); ++ itr)

typedef long long LL;
typedef pair<int, int> pii;

const int N = 2e5 + 5;

int T, n;
pii a[N];

LL solve(pii s, pii t){
    int sr = s.first, sc = s.second;
    int tr = t.first, tc = t.second;
    if (sr - sc == tr - tc){
        if ((sr + sc) & 1) return 0;
        else return tr - sr;
    }
    tr -= tc - sc;
    tc = sc;
    int dist = tr - sr;
    if (dist & 1){
        if ((sr + sc) & 1) return dist / 2 + 1;
        else return dist / 2;
    }
    return dist / 2;
}

int main(){
    scanf("%d", &T);
    while (T --){
        scanf("%d", &n);
        rep(i, n) scanf("%d", &a[i].first);
        rep(i, n) scanf("%d", &a[i].second);
        sort(a, a + n);
        pii cur(1, 1);
        LL ret = 0;
        rep(i, n){
            ret += solve(cur, a[i]);
            cur = a[i];
        }
        printf("%lld\n", ret);
    }
    return 0;
}