#include <bits/stdc++.h>
#define debug freopen("in.txt","r",stdin); freopen("out.txt","w",stdout)
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAXN=1e6+100;
const int MOD=1e9+7;
const int INF=0x3f3f3f3f;
const int SUB=-0x3f3f3f3f;
const int eps=1e-4;
const double E=exp(1);
const double pi=acos(-1);
int t,n;
int a[MAXN],b[MAXN],d[MAXN];
int main(){
	ios;
	cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
		for(int i=1;i<=n;i++) cin>>d[i];
		int now=0;
		for(int i=1;i<=n;i++){
			now+=a[i]-b[i-1]+d[i];
			if(i==n) break;
			if(now>a[i]) now+=(b[i]-a[i]+1)/2;
			if(now<b[i]) now=b[i];
		}
		cout<<now<<'\n';
	}

	return 0;
}

