#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;

#define ll long long
#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define twv vector<vector<int>>
#define fo(i,a,n) for(int i=int(a);i<int(n);i++)
#define op(x) cout<<x
#define ip(x) cin>>x
#define si set<int>
#define sc set<char>
#define ss set<string>
#define qqi queue<int>
#define qqc queue<char>
#define sti stack<int>
#define stc stack<char>
#define nl cout<<"\n"
#define pb(x) push_back(x)



//graph
/*
vi w={-1,0,1,0};
vi z={0,-1,0,1}; */


ll int mod=1e9+7;

/* HCF
ll int gcd(ll int a,ll int b){
    if(a==0)return b;
    return gcd(b%a,a);
} 
    */
//ll int lcm(ll int a,ll int b){return (a*b)/gcd(a,b);}

/*  PRIME_NUMBER
vi prime_number(int n){
    vi prime(n+1,1);
    prime[0]=0;
    prime[1]=0;
    prime[2]=1;
    fo(i,3,n+1){if(i%2==0)prime[i]=0;}
    fo(i,1,n+1){
        if(prime[i]){
            for(int j=i*i;j<n+1;j+=i){
                if(prime[j])prime[j]=0;
            }
        }
    }
    return prime;
}   */

int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int test;cin>>test;
    while(test--){
        int n;cin>>n;
        vi a(n+1,0);vi b(n+1,0);
        vi c(n+1,0);
        for(int i=1;i<=n;i++){
            cin>>a[i]>>b[i];
            ll int t=abs(b[i]-a[i]);
            ll int z=t/2;
            if(t%2!=0)z++;
            c[i]=z;
        }
        vi tm(n+1,0);
        for(int i=1;i<=n;i++)cin>>tm[i];
        ll int x=0;
        for(int i=1;i<n;i++){
            x+=a[i]-b[i-1]+tm[i];
            x+=c[i];
            if(x<b[i]){x=b[i];}
        }
        x+=a[n]-b[n-1]+tm[n];
        cout<<x;nl;
    }
    return 0;

}