#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define bug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 1e18;
const int nax = 200005;
struct pt
 {
  int y, x;
 }a[nax];
void solve() 
 {
  int n;
  cin>>n;
  for(int i = 1; i <= n; i++)
     cin>>a[i].y;
  for(int i = 1; i <= n; i++)
     cin>>a[i].x;
  a[0].y = 1, a[0].x = 1;
  int ans = 0;
  sort(a, a + n + 1, [](const pt A, const pt B)
     {
      return A.y < B.y;
     });
  for(int i = 1; i <= n; i++)
     {
      int diff_2 = a[i].y - a[i].x;
      int diff_1 = a[i - 1].y - a[i - 1].x;
      int diff = diff_2 - diff_1;
      int now = 0;
      if(diff == 0)
       {
         if(diff_2 % 2 == 0)
          now += a[i].y - a[i - 1].y;
       }
      else 
         {
          if(diff_2 % 2)
             now += diff/2;
          else 
             {
              diff--;
              now += 1 + diff/2;
             }
         }
      ans += now;
     }
  cout<<ans<<END;
 } 
int32_t main()
 {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("error.txt","w",stderr);  
   #endif
   int t = 1;
   cin>>t;
   while(t--)
    solve();
   return 0;
 }    
