#include<bits/stdc++.h>
#define int long long 
using namespace std;
 
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<pair<int,int>> a(n);
        for(int i = 0; i < n; i++) cin >> a[i].first;
        for(int i = 0; i < n; i++) cin >> a[i].second;
        sort(a.begin(), a.end());
        pair<int,int> prev = {1, 1};
        int cost = 0;
        for(int i = 0; i < n; i++){
            pair<int,int> cur = a[i];
            int down, right;
            right = cur.second - prev.second;
            down = cur.first - prev.first - right;

            if(right == 0 && down == 0) continue;

            if(down == 0){
                if((prev.first + prev.second) % 2 == 0) cost += right;
            }

            else{
                cost += (down / 2);
                if(down & 1){
                    if((prev.first + prev.second) & 1) cost++;
                }
            }
            prev = cur;
            // cout << cur.first << ' ' << cur.second << ' ' << cost << ' ';
        }
        cout << cost << '\n';
    }
}

/*
3
1 4 2
1 3 1
1,1 2,1 4,3

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10

1,1 2,2 10,4 
5 3

even - odd (0)
odd - odd (0)
even - even(1)
odd - even (1)

even  ....... odd

2, 6

even - even

odd - even / even - odd (6)
odd - odd / even - even (2)




*/