#include<bits/stdc++.h>
using namespace std;
const int MAX_N=1e6+10;
int n,a[MAX_N],b[MAX_N],c[MAX_N],d[MAX_N];

int main(){
	ios::sync_with_stdio(0);
	int t;
	cin>>t;
	while(t--){
		unsigned long long ans=0;
		cin>>n;
		for(int i=1;i<=n;i++){
			cin>>a[i]>>b[i];
			d[i]=(b[i]-a[i])/2;
			if((b[i]-a[i])%2==1){
				d[i]++;
			}
		}
		for(int i=1;i<=n;i++){
			cin>>c[i];
			c[i]=a[i]-b[i-1]+c[i];
		}
		for(int i=1;i<=n;i++){
			if(ans<b[i-1]){ans=b[i-1];}
			ans+=c[i]+d[i];
			
		}
		cout<<ans-d[n]<<endl;
	} 
	return 0;
} 
