#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loop1(i,a,b) for(ll i=a;i<=b;i++)
#define rloop(i,b,a) for(ll i=b;i>=a;i--)
#define test() int t;cin>>t;while(t-->0) 
#define speed ios_base::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
#define endl "\n" 
#define mp make_pair
#define pb push_back
#define mod 1000000007
//const ld PI  = 3.141592653589793;

bool isPrime(int n) 
{ 
    // Corner cases 
    if(n<=3){
        return true;
    }
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}


int main()
{
   speed
   test(){
       int n;
       cin>>n;
        int a[n],b[n];
       for(int i=0;i<n;i++){
           cin>>a[i]>>b[i];
       }
       int c[n];
       for(int i=0;i<n;i++){
           cin>>c[i];
       }
       int r=a[0];
       a[0]+=c[0];
       int x=(b[0]-r+1)/2;
       int j=b[0];
       int b2=a[0]+x;
       b[0]=max(b[0],b2);
       //cout<<a[0]<<" "<<b[0]<<" ";
       for(int i=1;i<n;i++){
           r=a[i];
           a[i]=b[i-1]+c[i]+(a[i]-j);
           j=b[i];
           x=(b[i]-r+1)/2;
           b2=a[i]+x;
           b[i]=max(b[i],b2);
        }
       cout<<a[n-1]<<endl;
   }
   return 0;
}