#include<bits/stdc++.h>
using namespace std;

#define int                             long long
#define ff                              first
#define ss                                  second
#define bb                                begin()
#define ee                                end()
#define float                             double
#define pb                              push_back
#define mp                              make_pair
#define pii                             pair<int,int>
#define vi                              vector<int>
#define mii                                map<int,int>
#define setbits(x)                         __builtin_popcountll(x)
#define zrobits(x)                      __builtin_ctzll(x)
#define mod                             1000000007
#define inf                             1e18
#define ps(x,y)                         fixed<<setprecision(y)<<x
#define    all(v)                            v.begin(),v.end()
#define w(e)                               int e; cin>>e; while(e--)
void im_mortal()
{
    w(e)
    {
        int n;
        cin >> n;
        vector<pair<int, int>>vp;
        vp.pb(mp(0, 0));
        for (int i = 0; i < n; i++)
        {
            int x, y;
            cin >> x >> y;
            vp.pb(mp(x, y));
        }
        // for (auto x : vp)
        //     cout << x.ff << " " << x.ss << endl;
        // cout << endl;
        vi v(n);
        v.pb(0);
        for (int i = 1; i <= n; i++)
            cin >> v[i];
        // for (auto x : v)
        //     cout << x << " ";
        // cout << endl;
        // cout << endl;
        vector<pair<int, int>>ans(n + 1);
        ans.pb(mp(0, 0));
        for (int i = 1; i <= n; i++)
        {
            int diff = ceil((vp[i].ss - vp[i].ff) * 1.0 / 2 * 1.0);
            int time = vp[i].ff - vp[i - 1].ss + v[i];
            //cout << time << endl;
            ans[i].ff = time + ans[i - 1].ss;
            ans[i].ss = max(ans[i].ff + diff, vp[i].ss);
        }
        // for (auto x : ans)
        //     cout << x.ff << " " << x.ss << endl;
        // cout << endl;
        cout << ans[n].ff << endl;

    }

}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    im_mortal();
    return 0;
}