#include<iostream> 
#include <cassert>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#include <cstring>
using namespace std;

const int N = 3e5 + 123;
int n, q;
int a[N], b[N];


void solve() {
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i] >> b[i];
	int cur = 0;
	for(int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		int need = (b[i] - a[i] + 1) / 2;
		cur += a[i] - b[i - 1] + x;
		need = max(need, b[i] - cur);
//		cout << cur << 'x'<<need << endl;
		if(i == n)
			break;
		cur += need;
	}
	cout << cur << endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin >> T;
	while(T--) solve();
	return 0; 
}



