#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
const ll maxn=1e5 + 100;
ll a[maxn],b[maxn],tm[maxn];
int main()
{
	ll t;
	cin >> t;
	while (t--)
	{
		ll n;
		cin >> n;
		a[0] = 0; b[0] = 0;
		ll tim = 0;
		for (int i = 1; i <= n; i++)
		{
			cin >> a[i] >> b[i];
		}
		for (int i = 1; i <= n; i++)
		{
			cin >> tm[i];
		}
		ll last = 0;
		for(int i = 1; i <= n; i++)
		{
			last = (b[i] - a[i] + 1) / 2;
			tim += a[i] - b[i - 1] + tm[i];
			if (i == n)break;
			if (tim + last > b[i])tim += last;
			else tim = b[i];
		}
		cout << tim << endl;
	}
	return 0;
}

