#include <bits/stdc++.h>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int rs[n];
		int cs[n];
		map<int,int> m;
		for(int i=0;i<n;i++){
			cin>>rs[i];
		}
		for(int i=0;i<n;i++){
			cin>>cs[i];
		}
		for(int i=0;i<n;i++){
			m.insert(pair<int,int>(rs[i],cs[i]));
		}
		m.insert(pair<int,int>(1,1));
		map<int,int>::reverse_iterator it;
		map<int,int>::reverse_iterator jt;
		int cost =0;
		for(it= m.rbegin(),jt = ++m.rbegin();jt!=m.rend();it++,jt++){
	
			int dy = it->first - jt->first;
			int dx = it->second - jt->second;
			
			if(dx==dy){
				
				//are they on the track or not
				if((it->first+it->second)%2==0){cost+=dx;}
				else{
				//we dont do anything here they are on a track
				}
			}
			else if(dx==0){
				//we can combinte some cases (1 and 3 but we wont)
				//for debugging
				if(dy%2==0){cost+=dy/2;}
				else if((it->first+it->second)%2==0){cost+=dy/2+1;}
				else{cost+=dy/2;}
			}
			else{
				//this means that it is inbetween
				// we know that there is at least one track between those
				
				int diff = dy-dx;
				if(diff%2==0){cost+=diff/2;}
				else if((it->first+it->second)%2==0){cost+=diff/2+1;}
				else{cost+=diff/2;}
			}
			
		}
		cout<<cost<<endl;
	}
	return 0;
}
