#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair<int,int>
#define pb push_back
const int N = 1000000;
const int inf = 1e15;
void solve(int c){
	int n;cin>>n;
	vector<pii>v(n);
	vector<int>tm(n);
	rep(i,0,n-1){
		cin>>v[i].first>>v[i].second;
	}
	rep(i,0,n-1)cin>>tm[i];
	int time= 0;
	rep(i,0,n-1){
		time+=v[i].first-(i>0?v[i-1].second:0) + tm[i]; 
		if(i==n-1)break;
		time+=(v[i].second-v[i].first+1)/2;
		time+=max(v[i].second-time,(int)0);
	}
	cout<<time<<endl;
	return;
}
signed main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t;cin>>t;
	rep(i,1,t)
	solve(i);
	return 0;
}