#include<iostream>
#include<cstring>
#include<stack>
#include<algorithm>

using namespace std;

typedef pair<int, int> PII;

const int N = 1010;

int n;
PII a[N];
int t[N];

int main(){
	
	int T;
	cin >> T;
	
	while(T --){
		cin >> n;
		for(int i = 1; i <= n; ++ i) cin >> a[i].first >>a[i].second;
		
		for(int i = 0; i < n; ++ i) cin >>t[i];
		
		int tt = 0;
		for(int i = 1; i <= n; ++ i){
			tt += t[i - 1] + a[i].first - a[i - 1].second;
			int ans = (a[i].second - a[i].first) / 2;
			if((a[i].second + a[i].first) % 2) ans++;
			if(i < n)tt = max(ans + tt, a[i].second);
		}
		cout << tt << endl; 
	}
	
	return 0;
}
