//Ho bakri bulekhe vich Sher ban jandi aa Te cheete ohda karde shikaar ne..✔
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
  
    fastio;
   
   //q = (x + y - 1) / y; ceil dividion
    ll t;cin>>t;
    while(t--){
        ll n,a,b;cin>>n;
        vector<pair<int,int>>v;
        rep(i,n){cin>>a>>b; v.pb(make_pair(a,b));}
    ll extra[n];
    rep(i,n){cin>>extra[i];}
    ll ans=0,arrival,dep;
    rep(i,n-1){
        arrival=ans+v[i].first+extra[i];
        ll temp=ceil((double)(v[i].second-v[i].first)/2);
        dep=arrival+temp;

        if(dep< v[i].second){
            dep=v[i].second;
        }
        ans=dep-v[i].second;
        dep=0;
    }
    cout<<ans+v[n-1].first+extra[n-1]<<endl;
    }
    

return 0;
}

