#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <complex>
#include <functional>
using namespace std;
#define ll long long

inline long long read(){
    long long x = 0; int zf = 1; char ch = ' ';
    while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
    if (ch == '-') zf = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
}

#define ll long long
#define MOD 1000000007

using namespace std;

struct Node {
    ll r;
    ll c;
};

Node node[200005];

void solve() {
    ll n = read();
    for(int i=0; i<n; i++) node[i].r = read();
    for(int i=0; i<n; i++) node[i].c = read();
    sort(node, node+n, [](const Node&lhs, const Node&rhs){
        return lhs.r < rhs.r;
    });
    ll r = 1;
    ll c = 1;
    ll res = 0;
    for(int i=0; i<n; i++) {
        ll tr = node[i].r;
        ll tc = node[i].c;
        if(tr==r) {
            continue;
        }
        ll delta_r = tr - r;
        ll delta_c = tc - c;
        if (delta_c==delta_r) {
            if ((r+c) % 2 == 0){
                res += delta_r;
            }
        } else {
            int gap = delta_r - delta_c;
            if ((r+c) % 2 == 0) {
                res += gap / 2;
            } else {
                res += (gap+1) / 2;
            }
        }
        r = tr;
        c = tc;
    }
    cout << res << endl;
}

int main() {
    ll t = read();
    while(t--) {
        solve();
    }
//    solve();
    return 0;
}