#include <iostream>
#include <cstdio>
#include <cstring>
#define ll long long
#define ull unsigned long long
using namespace std;
inline int read(){
	int f=0,num;
	char ch;
	while(ch=getchar(),!isdigit(ch))if(ch=='-')f=1;num=ch-'0';
	while(ch=getchar(), isdigit(ch))num=num*10+ch-'0';
	return f?-num:num;
}

int n,s,t,a[105],b[105],p[105];
int main()
{
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
		for(int i=1;i<=n;i++)cin>>p[i];
		s=0;
		for(int i=0;i<n;i++)
		{
			s=max(s+(b[i]-a[i]+1)/2,b[i]);
			s+=a[i+1]-b[i]+p[i+1];
		}
		cout<<s<<endl;
	}
	return 0;
}