#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <iomanip>
using namespace std;

#define ll long long int
#define pii pair<ll, ll>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define ff first
#define ss second
#define M 500005
#define MOD 1000000007
#define inf LLONG_MAX
#define endl "\n"
#define MAX 1000004 // 10^6
ll power(ll,ll);
ll mpower(ll,ll,ll);
ll gcd(ll , ll );
void seive();
vector<ll> prime;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t = 1;
    cin >> t;
    while (t--)
    {
        ll n,i,j;
        cin>>n;
        vector<pii> s(n);
        for(i=0;i<n;i++){
            cin>>s[i].first>>s[i].second;
        }
        vector<ll> tm(n);
        for(i=0;i<n;i++){
            cin>>tm[i];
        }
        ll cur=0,preOD=0,preD=0;
        for(i=0;i<n;i++){
            cur+=s[i].first - preD + tm[i];
            if(i==n-1) break;
            cur = cur+ ceil((s[i].second-s[i].first)/2.0);
            preOD = cur;
            preD= s[i].second;
            if(cur<s[i].second){
                cur+=s[i].second- cur;
            }
        }
        cout<<cur<<endl;
    }
    return 0;
}



ll power(ll x, ll y)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1ll)
        {
            res = (res * x);
        }
        y = y >> 1ll;
        x = (x * x);
    }
    return res;
}
ll mpower(ll x, ll y, ll p)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1ll)
        {
            res = (res * x) % p;
        }
        y = y >> 1ll;
        x = (x * x) % p;
    }
    return res;
}
ll gcd(ll x,ll y){
    if(y==0){
        return x;
    }
    return gcd(y,x%y);
}

void seive(){
    ll i,j;
    ll isprime[MAX]={0};
    for(i=2;i<MAX;i++){
        if(isprime[i]==0){
            prime.push_back(i);
            for(j=i+i;j<MAX;j+=i)
                isprime[j]=1;
        }
    }
}

