#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 2e5+55;
struct node {
    int a, b;
};
node no[maxn];
int main() {
    int t;
    cin >> t;
    while (t --) {
        int n;
        cin >> n;
        for (int i = 0; i < n; ++ i) {
            cin >> no[i].a;
        }
        for (int i = 0; i < n; ++ i) {
            cin >> no[i].b;
        }
        sort(no, no+n, [](node x, node y){
            return x.a < y.a;
        });
        int x = 1, y = 1, ans = 0;
        for (int i = 0; i < n; ++ i) {
            if ((x-y) / 2 == (no[i].a-no[i].b) / 2) {
                if ((no[i].a-no[i].b) % 2 == 0) {
                    ans += (no[i].a - x);
                }
            }
            else {
                ans += abs((x-y) / 2 - (no[i].a-no[i].b) / 2);
            }
            // cout << x << " " << y << " " << ans << endl;
            x = no[i].a, y = no[i].b;
        }
        cout << ans << endl;
    }
    return 0;
}