#include <iostream>
using namespace std;

#define int long long

const int MAX_N = 100 + 7;

int T, n;
int a[MAX_N], b[MAX_N], tm[MAX_N];

signed main() {
    ios::sync_with_stdio(false);
    cin >> T;
    while (T--) {
        cin >> n;
        for (int i = 1; i <= n; ++i) {
            cin >> a[i] >> b[i];
        }
        for (int i = 1; i <= n; ++i) {
            cin >> tm[i];
        }

        int ans = 0;
        for (int i = 1; i < n; ++i) {
            ans += a[i] - b[i - 1] + tm[i];
            int wt = (b[i] - a[i] + 1) / 2;
            ans = max(b[i], ans + wt);
        }
        ans += a[n] - b[n - 1] + tm[n];

        cout << ans << endl;
    }

    return 0;
}
