#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

const int N=1e6;

int n,m;
int tt[N],a[N],b[N],x[N];

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		memset(tt,0,sizeof tt);
		int n;
		cin>>n;
		int ans=0;
		for(int i=0;i<n;i++)
		{
			scanf("%d %d",&a[i],&b[i]);
			if((b[i]-a[i])%2) x[i]=(b[i]-a[i])/2+1;
			else x[i]=(b[i]-a[i])/2;
		}
		for(int i=0;i<n;i++) scanf("%d",&tt[i]);
		ans=a[0];
		for(int i=0;i<n;i++)
		{
			ans+=tt[i];
			if(i==n-1) break;
			ans+=x[i];	
			if(ans<b[i]) ans=b[i];	
			ans+=a[i+1]-b[i];
		}
		cout<<ans<<endl;
	}
	return 0;
}

