#include <bits/stdc++.h>
#define int long long
using pii=std::pair<int,int>;
using namespace std;

const int maxn = 2e5 + 5;

int t, n, r[maxn], c[maxn];
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> t;
    for(int cases = 0; cases < t; cases++)
    {
        cin >> n;
        for(int i = 0; i < n; i++)
            cin >> r[i];
        for(int i = 0; i < n; i++)
            cin >> c[i];
        vector<pii> order;
        order.push_back({1, 1});
        for(int i = 0; i < n; i++)
            order.push_back({r[i], c[i]});
        sort(order.begin(), order.end());
        int ans = 0;
        for(int i = 1; i < order.size(); i++)
        {
            assert(order[i].first - order[i].second >= order[i - 1].first - order[i - 1].second);
            int down = (order[i].first - order[i - 1].first);
            int left = (order[i - 1].second + down - order[i].second);
            int curcost = 0;
            if(left == 0 && (order[i].first + order[i].second) % 2 == 0)
                curcost += down;
            if((order[i].first + order[i].second) % 2 == 1)
                curcost += left / 2;
            else
                curcost += (left + 1) / 2;
            ans += curcost;
        }
        cout << ans << "\n";
    }
    return 0;
}