#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define fixx(n) fixed << setprecision(n)
#define F first
#define S second
#define PI  3.14159265358979323846
#define ll  long long int
#define int ll
#define double long double
const int mod = 1e9 + 7;
const int modd = 998244353;
const int N = 1e5;


signed main()
{

    FAST;
    int t;
    cin >> t;
    while(t --) {
        int n;
        cin >> n;
        int a[n + 5], b[n + 5];
        int tm[n + 5];
        for(int i = 0; i < n;i ++) cin >> a[i] >> b[i];

        for(int i = 0; i < n; i ++) {
            cin >> tm[i];
        }
        int ans = a[0] + tm[0];
        if(n - 1){
            ans += ((b[0] - a[0] + 1) / 2);
            if(n != 1 && b[0] > ans)
            ans =  b[0];
        }
        for(int i = 1; i < n; i++){
            ans += (a[i] - b[i - 1] + tm[i]);
            if(i == (n - 1))  break;
            ans += ((b[i] - a[i] + 1) / 2);
            if(b[i] > ans) ans = b[i];
        }

        cout << ans << '\n';
    }
    return 0;
}
