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

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define eb          emplace_back
#define endl		'\n'
#define max(a,b)	((a)>(b)?(a):(b))
#define min(a,b)	((a)<(b)?(a):(b))
#define vi          vector<int>
#define vii         vector<pair<int, int> >
#define mp          make_pair
#define mem1(a)     memset((a),-1,sizeof(a))
#define mem0(a)     memset((a),0,sizeof(a))
#define memf(a)     memset((a),false,sizeof(a))
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    (a)*((b)/gcd((a),(b)))
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mi          map<int,int>
#define sz(x)       (ll)(x).size()
#define rep(i,a,b)  for(int i=(a);i<(b);i++)
#define pii         pair<int,int>

int solve()
{
	int n;
	cin >> n;
	int a[n + 1], b[n + 1];
	rep(i, 1, n + 1)
	{
		cin >> a[i] >> b[i];
	}
	b[0] = 0;
	a[0] = 0;
	int tm[n + 1];
	rep(i, 1, n + 1)
	cin >> tm[i];
	int last = 0;
	int arival = a[1] + tm[1];
	rep(i, 1, n + 1)
	{
		arival = last + tm[i] + a[i] - b[i - 1];
		int r = (b[i] - a[i] + 1) / 2;
		int dep = max(arival + r, b[i]);
		last = dep;
	}
	cout << arival << endl;


	return 0;
}
signed main()
{
	FAST
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int t = 1;
	cin >> t;
	while (t)
	{
		solve();
		t--;
	}
	return 0;
}