#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define mem0(x) memset(x,0,sizeof(x))
#define meminf(x) memset(x,0x3f,sizeof(x))
#define VI vector<int>
#define VL vector<ll>
#define pb push_back
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define endl '\n'
#define pb push_back
#define fi first 
#define se second

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//#define DEBUG
using namespace  std;


const int N = 150+5, inf = 0x3f3f3f3f;

int n,k;
ll a[N],b[N],tmm[N];

void solve(){
   	cin>>n;
   	rep(i,1,n){
   		cin>>a[i]>>b[i];
   	}
   	rep(i,1,n){
   		cin>>tmm[i];
   	}
   	
   	ll tim = 0;

   	rep(i,1,n){
   		tim += a[i]-b[i-1]+tmm[i];
   		if(n == i) break;
   		ll lim = max(b[i]-tim, (b[i]-a[i]+1)/2);
   		tim += lim;
   	}
    cout << tim <<endl;
    
}


int main(){
    ios::sync_with_stdio(0);
    int tt;cin>>tt;
    while(tt--){
        solve();
    }
}