#include <bits/stdc++.h>

using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<pair<int, int>> v(n);
        for (int i = 0; i < n; i++)
        {
            cin >> v[i].first >> v[i].second;
        }
        int tm[n];
        for (int i = 0; i < n; i++)
            cin >> tm[i];
        int delay = 0, at;
        for (int i = 0; i < n; i++)
        {
            at = tm[i] + v[i].first + delay;
            // cout << at << endl;
            int thres = (v[i].second - v[i].first) / 2;
            if ((v[i].second - v[i].first) % 2 != 0)
                thres++;
            int stays = v[i].second - at;
            int left;
            if (stays < thres)
                left = at + thres;
            else
                left = v[i].second;
            // cout << "thres: "  << thres << endl;
            // cout << "left: " << left << endl;
            delay = abs(left - v[i].second);
        }
        cout << at << endl;
    }
}