#include <bits/stdc++.h>

using namespace std;
#define IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;

const int N = 2e5+5;
int n, m, k, t, mx;
pair<int, int> p[N];
string s;

int main()
{
    IO;
    cin >> t;
    while(t--){
        cin >> n;
        k = 0;
        for (int i = 0; i < n; ++i) cin >> p[i].first;
        for (int i = 0; i < n; ++i) cin >> p[i].second;
        sort(p, p+n);
        if(p[0].first == p[0].second) k = max(p[0].first - 1, k);
        else k = max(k, (p[0].first-p[0].second)/2);
        for(int i = 1; i < n; ++i){
            int l = p[i].first-p[i].second, r = p[i-1].first-p[i-1].second;
            if(l == r && (p[i-1].first + p[i-1].second) % 2 == 0){
                k += p[i].first - p[i-1].first;
                continue;
            }
            if((p[i-1].first + p[i-1].second) % 2 == 0) ++p[i-1].first;
            l = p[i].first-p[i].second, r = p[i-1].first-p[i-1].second;
            k += (l-r+1)/2;
        }
        cout << k << endl;
    }
}
/*
1
8
1  3  4  8  10  13  14  15
1  1  2  5  6   6   6   6

 *
 */