
                                                    /* Thank you. 5,12,21,25.
                                                Sometimes, there is no moving forward.
                                                You just have to live with it always. */


#include<bits/stdc++.h>
using namespace std;
typedef long long LL ;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define ook order_of_key
#define fbk find_by_order
#define bug printf("Massacre.\n");
#define pf printf
#define sf scanf
#define pb push_back
#define r0 return 0
#define ff first
#define ss second
#define mp make_pair
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define si(a) scanf("%d" , &a)
#define sl(a) scanf("%lld" , &a)
#define sii(a,b) scanf("%d %d" , &a , &b)
#define siii(a,b,c) scanf("%d %d %d" , &a , &b, &c)
#define sll(a,b) scanf("%lld %lld" , &a , &b)
#define slll(a,b,c) scanf("%lld %lld %lld" , &a , &b, &c)
#define pll pair <LL, LL>
#define pii pair <int, int>
#define vi  vector <int>
#define vl  vector <LL>
#define all(x) (x).begin(), (x).end()
#define vii vector <pair <int, int> >
#define vll vector < pair <LL, LL> >
#define mod 1000000007

//using namespace __gnu_pbds;
//typedef tree < int, null_type ,less<int>,rb_tree_tag,tree_order_statistics_node_update > ordered_set;

void func(void)
{
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
}

void print(vector <LL> &v){
    cout << v.size() << endl;
    for(int i = 0; i < v.size(); i++){
        pf("%lld ", v[i]);
    }
    cout << "------------------------------------------------------\n";
    pf("\n");
}

void print(vector <pll> &v){
    cout << v.size() << endl;
    for(int i = 0; i < v.size(); i++){
        pf("%lld %lld\n", v[i].ff, v[i].ss);
    }
    cout << "----------------------------------------------------------\n";
}

void print(double d){
    cout << fixed << setprecision(10) << d << endl;
    cout << "--------------------------------------------------------\n";
}

void print(string s, double d){
    cout << s << " ";
    cout << fixed << setprecision(10) << d << endl;
    cout << "-----------------------------------------------------------\n";
}

template <typename T>
void readToVector(vector <T> &v, LL n){
    T x;
    for(int i = 0; i < n; i++){
        cin >> x;
        v.pb(x);
    }
//    for(T y : v){
//        cout << y << " ";
//    }
//    cout << endl;
}

void solve(){
    LL n, q, i,j = 0, temp, t, k, ans = 0, sum = 0, x, y, z, cnt = 0, m, fg = 0, mx = 0, mx1 = 0, mn = 8000000000000000000, mn1 = 8000000000000000000;
    cin >> n;
    vector <pll> v;
    for(int i = 0; i < n; i++){
        cin >> x >> y;
        v.pb({x, y});
    }
    vector <LL> ex;
    readToVector(ex, n);
    LL cur = v[0].first - 0 + ex[0];
    for(int i = 1; i < n; i++){
        LL arr = v[i].first - v[i - 1].second + ex[i];
        LL stay = (v[i - 1].second - v[i - 1].first + 1LL)/2LL;
        cur = max(cur + stay, v[i - 1].second);
        cur += arr;
    }
    cout << cur << endl;
}


int main(){
//    ios_base::sync_with_stdio(0); cin.tie(0);
//    func();
    LL t;
    cin >> t;
    while(t--)solve();

}
