//Created by: Aditya Singh
//Bleed Blue
#include <bits/stdc++.h>

using namespace std;

// #pragma GCC optimize("O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define unm map<int,int>
#define pb emplace_back
#define PI 3.1415926535897932384626433
#define inf 1e18

const int N = 200005;

P ar[N];

int dist(int r1, int c1, int r2, int c2) {
    if (r1 - c1 == r2 - c2)
        return (r1 + c1) & 1 ? 0 : r2 - r1;
    r2 -= r1 - 1, c2 -= c1 - 1;
    return (r1 + c1) & 1 ^ 1 ? (r2 - c2) / 2 : (r2 - c2 + 1) / 2;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t; cin >> t; while (t--)
    {
        int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
        cin >> n;
        for (i = 0; i < n; i++)
            cin >> ar[i].F;
        for (i = 0; i < n; i++)
            cin >> ar[i].S;

        sort(ar, ar + n);
        int a = 1, b = 1;
        for (i = 0; i < n; i++) {
            ans += dist(a, b, ar[i].F, ar[i].S);
            a = ar[i].F, b = ar[i].S;
        }
        cout << ans << '\n';
    }
    return 0;
}