/* -> Written by <-
   -----------
  |K_A_Z_A_M_A|
  |___________|
  |    ___    |
  |   (^_^)   |
  |  /( | )\  |
  |____|_|____|
    H O A N G
*/

#include <bits/stdc++.h>

#define Task            "running"
#define F               first
#define S               second
#define pb              push_back
#define bit(x, i)       ((x >> (i)) & 1)
#define inf             1e9 + 7
#define INF             1e18 + 7
#define ll              long long
#define pii             pair <int, int>
#define debug(x)        cerr << #x << " is " << x << "\n";

using namespace std;

const int MOD = 1e9 + 7;
const int maxn = 1e5 + 5;
const int base = 3e5 + 1;

int n;
pair <int, int> a[200005];

int CalDis(int r1, int c1, int r2, int c2) {
    if (r1 - c1 == r2 - c2) {
        if ((r1 + c1) % 2 == 0) return r2 - r1;
        return 0;
    }
    int newr = r2 - c2 + c1;
    int newc = c1;
    int x = newr - r1;
    if ((newr + newc) % 2) return x / 2;
    return (x + 1) / 2;
}

void Solve() {
    cin >> n;
    for (int i = 1; i <= n; ++ i) {
        cin >> a[i].F;
    }
    for (int i = 1; i <= n; ++ i) {
        cin >> a[i].S;
    }
    sort(a + 1, a + 1 + n);
    int r1 = 1, c1 = 1;
    ll res = 0;
    for (int i = 1; i <= n; ++ i) {
        int r2 = a[i].F;
        int c2 = a[i].S;
        res += CalDis(r1, c1, r2, c2);
        c1 = c2;
        r1 = r2;
    }
    cout << res << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    if (fopen(Task".inp", "r")){
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
//    Prepare();
    int test_case = 1;
    cin >> test_case;
    while (test_case --){
        Solve();
    }
    return 0;
}
