#include<bits/stdc++.h>
using namespace std;
int a[105];
int b[105];
int cha[105];
int ex[105];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(int i=1;i<=n;i++)
		{
			cin>>a[i]>>b[i];
		}
		for(int i=1;i<=n;i++) cin>>ex[i];
		int cnt=1;
		int now=a[1];
		while(cnt<n)
		{
			now+=(ex[cnt]+((b[cnt]-a[cnt])%2?1:0)+(b[cnt]-a[cnt])/2);
			if(now<b[cnt]) now=b[cnt];
			now+=a[cnt+1]-b[cnt];
			cnt++;
		}
		cout<<now+ex[n]<<endl;
	}
	return 0;
} 