#include<bits/stdc++.h>
using namespace std;

// template 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

#define pb push_back
#define mp make_pair
#define f first
#define s second
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,v) for(int i=0;i<v.size();i++)
#define reps(i,s) for(int i=0;i<s.length();i++)
#define allv(v) v.begin(),v.end()
#define alla(arr,sz) arr,arr+sz
#define rev(v) reverse(allv(v))
#define reva(a) reverse(alla(a))


void solve(){
	int n;
	cin>>n;
	int tm[n],a[n],b[n+1];
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i+1];
	}
	b[0] = 0;
	for(int i=0;i<n;i++){
		cin>>tm[i];
	}
	int start_t = 0;
	// int tr1 = (b[0] - a[0])/2 +(b[0] - a[0])%2;
	// if(tm[0] +a[0] > b[0])
	// 	start_t = b[0] + tr1;
	// else{
	// 	int tw = b[0] - (a[0] + tm[0]);
	// 	if(tw >= tr1){
	// 		start_t = b[0];
	// 	}
	// 	else{
	// 		start_t = b[0] + (tr1 - tw);
	// 	}

	// }
	for(int i=0;i<n-1;i++){
		int ct = (a[i] - b[i]) + tm[i];
		if(start_t + ct > b[i+1]){
			start_t += ct + (b[i+1] - a[i])/2 +(b[i+1] - a[i])%2;
		}
		else{
			int tr = (b[i+1] - a[i])/2 +(b[i+1] - a[i])%2;
			int tw = b[i+1] - (start_t + ct);
			if(tw >= tr){
				start_t = b[i+1];
			}
			else{
				start_t = b[i+1] + (tr - tw);
			}
		}
		// cout<<start_t<<endl;
	}
	int ct = (a[n-1] - b[n-1]) + tm[n-1];
	start_t += ct;
	cout<<start_t<<endl;	
}

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	int t;
	// t = 1;
	cin>>t;
	while(t--){
		solve();
	}
}