// Premature optimization is the root of all evil in programming - Knuth.

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

#define mod (int) (1e9+7)

ll gcd(ll a, ll b){
	
	if(b==0){

	   return a;
	}
	
	return gcd(b, a%b);
	
}

void solve(){
	
	ll n; cin>>n;
	
	ll a[n+1],b[n+1]; a[0]=b[0]=0;
	
	for(int i=1; i<=n; i++){
		cin>>a[i]>>b[i];
	}
	
	ll tm[n+1]; tm[0]=0;
	
	for(int i=1; i<=n; i++){
		cin>>tm[i];
	}
	
	ll tim=0,res=0;
	
	for(int i=1; i<=n; i++){
		tim+=(a[i]-b[i-1]+tm[i]);
		tim=max(tim,a[i]);
		res=tim;
		ll wait=(b[i]-a[i]+1)/2;
		if(b[i]-tim<wait){
			tim+=wait;
		}
		else{
			tim=b[i];
		}
	}
	
	cout<<res<<"\n";
	
	return;
	
}


int main(){
    ios_base::sync_with_stdio(0);
    
    cin.tie(0);
    
    int t=1;cin>>t;
   
    // clock_t begin, end;
    
    // double time_spent;
    
    // begin = clock(); // Time taken till now.
    
    while(t--){
    
	  solve();
        
    }
    
   //end= clock(); // Total  Time taken till now.
   
   //time_spent= (end- begin) / CLOCKS_PER_SEC; 
   
   //cout<<time_spent<<"\n";
   
	return 0;
}

