#include<bits/stdc++.h>
using namespace std;
int main()
{
    int tc;cin>>tc;while(tc--)
    {
        int n;cin>>n;
        int a[101],b[101],t[101];
        for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
        for(int i=1;i<=n;i++) cin>>t[i];
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum=max(sum+(b[i]-a[i]+1)/2,b[i]);// cout<<"m1="<<sum<<endl;
            sum+=a[i+1]-b[i]+t[i+1];//cout<<"m2="<<sum<<endl;
        }
        cout<<sum<<endl;
    }
    return 0;
}

//joyed
