#include<bits/stdc++.h>
#define int long long
using namespace std;
template<typename T> inline void read(T &x){
	T f=1;x=0;
	char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	x*=f;
}
const int N = 3000;
int T,n;
struct node{
	int x,y;
}f[N];
int t[N],go[N];
signed main(){
	read(T);
	while(T--){
		memset(f,0,sizeof(f));
		memset(t,0,sizeof(t));
		memset(go,0,sizeof(go));
	    read(n);
	   	for(int i=1;i<=n;i++){
	   		read(f[i].x),read(f[i].y);
	   		go[i]=f[i].x-f[i-1].y;
		}
		
		for(int i=1;i<=n;i++){
		read(t[i]);
		go[i]+=t[i];
		}
		int now=0;
		
		for(int i=1;i<=n;i++){
			now+=go[i];
	//		now+=t[i];
			if(i==n){
				printf("%lld\n",now);
				break;
			}
			int lt=ceil((double)(f[i].y-f[i].x) /2.0);
			now+=lt;
			if(now<f[i].y){
				now=f[i].y;
			}
			//now+=t[i];
		}
		
	}
    return 0;
}