#include<bits/stdc++.h>
using namespace std;

void __print(int x){cerr << x;}
void __print(long x){cerr << x;}
void __print(long long x){cerr << x;}
void __print(unsigned x){cerr << x;}
void __print(unsigned long x){cerr << x;}
void __print(unsigned long long x){cerr << x;}
void __print(float x){cerr << x;}
void __print(double x){cerr << x;}
void __print(long double x){cerr << x;}
void __print(char x){cerr << '\'' << x << '\'';}
void __print(const char *x){cerr << '\"' << x << '\"';}
void __print(const string &x){cerr << '\"' << x << '\"';}
void __print(bool x){cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x){cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x){int f = 0; cerr << '{'; for(auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print(){cerr << "]\n";}
template<typename T, typename... V>
void _print(T t, V... v){__print(t); if(sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef pair<ll, ll>pll;

const int M = 2e5 + 3;
const int MOD = 1e9 + 7;


void solve(){

    int n;
    cin >> n;

    vector<pii>v;
    int rr[n], cc[n];

    for(int i=0; i<n; i++) cin >> rr[i];
    for(int i=0; i<n; i++){
        cin >> cc[i];
        if(rr[i] != 1) v.push_back({rr[i], rr[i] - cc[i]});
    }
    v.push_back({1, 0});

    sort(v.begin(), v.end());

    int ans = 0;

    for(int i=0; i+1<v.size(); i++){
        int r1 = v[i].first, x1 = v[i].second;
        int r2 = v[i+1].first, x2 = v[i+1].second;
        assert(x2 >= x1);
        ans += (x2 - x1 + x1 % 2) / 2;
        r1 += x2 - x1;
        if(x1 == x2 and x2 % 2 == 0) ans += r2 - r1;
    }

    cout << ans << "\n";



}


int main(){

    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



    int tc;
    cin >> tc;

    for(int i=1; i<=tc; i++){
        solve();
    }

}