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

void solve()
{
	int n;
	cin>>n;
	vector<pair<int, int>> v;
	for(int i = 0; i < n; ++i)
	{
		int a, b;
		cin>>a>>b;
		v.push_back({a, b});
	}
	vector<int> diff;
	for(int i = 0; i < n; ++i)
	{
		int a;
		cin>>a;
		diff.push_back(a);
	}
	long long int ans = 0;
	for(int i = 0; i < n-1; ++i)
	{
		int a = v[i].first;
		int b = v[i].second;
		int c = diff[i];
		int min = b-a;
		if(a >= ans)
		{
			ans = a;
		}
		else
		{

		}
		ans+=c;
		
		if(min%2==0)
			{
				min = min/2;
			}
			else
			{
				min = min/2 + 1;
			}
				if(ans+min>=b)
				{
					ans = ans+min;
				}
				else
					{
						ans = b;
					}
			
			if(i!=n-1)
			ans+=(v[i+1].first-v[i].second);
	}
	if(v[n-1].first >= ans)
		{
			ans = v[n-1].first;
		}
		else
		{

		}
	cout<<ans+diff[n-1]<<endl;
	// cout<<min(ans+diff[n-1])<<endl;
}

int main()
{
	// freopen("input1.txt", "r", stdin);
	// freopen("ou.txt", "w", stdout);

	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}