/*                               _          __    __    
                                / \        |  \  /  |
                               / _ \       | | \/ | |
                              / ___ \      | |    | |
                             /_/   \_\ ()  |_|    |_| ()
                                                                                                            */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
#define test ll t; cin>>t; for(;t--;)
#define f1(a,b) for(ll i=a;i<b;i++)
#define f2(a,b) for(ll j=a;j<b;j++)
#define f3(b,a) for(ll i=b;i>=a;i--)
#define f4(b,a) for(ll j=b;j>=a;j--)
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define pob push_back
#define el "\n"
int gcd(ll a, ll b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
 
void code()
{
        
        
        ll n,i,j,c=0,s=0;
        cin>>n;
        ll a[1000],b[1000],t[1000];
		for(i=1;i<=n;++i)
			cin>>a[i]>>b[i];
		for(i=1;i<=n;++i)
			cin>>t[i];
		for(i=1;i<=n;++i)
		{
			s+=a[i]-b[i-1]+t[i];
			if(i!=n)
				s=max(b[i],s+(b[i]-a[i]+1)/2);
		}
		cout<<s<<el;
    
}
        
    
int main()
{
        flash;
        test{
            code();
        }
}