
// Problem: A. Alexey and Train
// Contest: Codeforces - Codeforces Round #707 (Div. 2, based on Moscow Open Olympiad in Informatics)
// URL: https://codeforces.com/contest/1501/problem/0
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld long double
#define maxheap priority_queue<int>
#define minheap priority_queue<int, vector<int>, greater<int>>
#define pb push_back
int inf=1e18;


int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<int> a(n),b(n),c(n);
		for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
		for(int i=0;i<n;i++)
		cin>>c[i];
		int d[n];
		d[0]=a[0]+c[0];
		for(int i=1;i<n;i++)
		{
			d[i]=a[i]-b[i-1]+c[i];
			
		} 
		int ti=d[0];
		for(int i=0;i<n-1;i++)
		{
			ti+=(b[i]-a[i]+1)/2;
			if(ti<b[i])
			ti=b[i];
			ti+=d[i+1];
		}
		
		cout<<ti<<"\n";
		
	}
	return 0;	
}