#include<bits/stdc++.h>

using namespace std;

#define lli long long int

#define ulli unsigned long long int

#define Pi 3.14159265358979323846264338327950288419716939937510

#define print(x) cout<<endl<<"At line "<<x<<endl;

int main(){
	
    ios :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
   
    //ifstream cin; ofstream cout; cin.open("input.txt"); cout.open("output.txt");
    
    int T = 1;
    
    cin>>T;
    
    int cases = 0;
    
    while(T--){
    	
    	cases += 1;
    	
    	int n;
    	
    	cin>>n;
    	
    	vector < pair <lli, lli> > points(n+1);
    	
    	for(int i=0; i<n; i++){
    		
    		cin>>points[i].first;
		}
		
    	for(int i=0; i<n; i++){
    		
    		cin>>points[i].second;
		}
		
		points[n] = {1LL, 1LL};
		
		sort(points.begin(), points.end());
		
		lli result = 0;
		
		for(int i=0; i<n; i++){
			
			lli d1 = points[i].first - points[i].second;
			
			lli d2 = points[i+1].first - points[i+1].second;
			
			lli d3 = d2 - d1;
			
			lli d = 0;
			
			if(d1&1){
				
				d = (d3 + 1)/2;
			}
			
			else{
				
				if(d1 == d2){
					
					d = points[i+1].first-points[i].first;
				}
				
				else{
					
					d = d3/2;
				}
			}
			
			result += d;
		}
		
		cout<<result<<endl;
	}
}
