#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short

#define pb push_back

#define fst first
#define snd second
#define mp make_pair

#define MOD 1000000007
#define all(v) (v).begin(),(v).end()
#define frl(i,n) for(long long i=0;i<n;i++)

#define ms(x,i)	memset(x,i,sizeof(x))
#define dbg(x)	cerr << #x << " = " << x << "\n"
#define displayvec(vec) cerr<<#vec<<": "; for(auto vd : vec) cerr<<vd<<" "; cerr<<"\n"

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for(auto &i : v) cin>>i;
  return is;
}

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  for(auto &i : v) cout<<i;
  return os;
}

int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        vector< ll > a(n + 1), b(n + 1), tm(n + 1);
        for(ll i = 1; i <= n; ++i){
            cin>>a[i]>>b[i];
        }
        for(ll i = 1; i <= n; ++i){
            cin>>tm[i];
        }

        vector< ll > arrive(n + 1), leave(n + 1);
        for(ll i = 1; i <= n; ++i){
            arrive[i] = leave[i - 1] + tm[i] + a[i] - b[i - 1];
            leave[i] = max(b[i], arrive[i] + (b[i] - a[i] + 1)/2);
        }
        cout<<arrive[n]<<"\n";
	}
    return 0;
}
