#include<bits/stdc++.h>
using namespace std;
long long m[1010], a[1010], b[1010];
signed main() {
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        long long ans = 0;
        for (int i = 1; i <= n; i++)
            cin >> a[i] >> b[i];
        for (int i = 1; i <= n; i++)
            cin >> m[i];
        for (int i = 1; i <= n; i++) {
            ans += a[i] - b[i - 1] + m[i];
            if (i != n)ans += (b[i] - a[i] + 1) / 2;
            if (i != n && ans < b[i]) ans = b[i];
        }
        cout << ans << endl;
    }
    return 0;
}