// 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/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <ios>
#include <iterator>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
#define Jai_shri_Ram ios_base::sync_with_stdio(false) , cin.tie(NULL);
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x);
#else
#define deb(x...)
#endif
#define debg(x) cout<<#x<<" = "<<x<<endl;
#define pb emplace_back
#define mp make_pair
#define vi vector<int>
#define all(v)   v.begin(),v.end() 
#define rep(x,a,b)  for(int x=a;x<b;x++) 
//#define int long long int 

void solve(){
	int n ; 
	cin >> n ; 
	int a[n] ,b[n] , t[n];
	rep(i , 0 , n) cin >> a[i] >> b[i] ; 
	rep(i , 0 , n) cin >> t[i] ;
	
	int time = 0;
	rep(i , 0 , n){
	  //Adding Arrival Time
  	  if(i == 0)
      	time += a[i] + t[i];
  	  else
      	time += a[i] - b[i-1] + t[i];
    	
  	//Waiting time
    	if(i == n-1)break;
    	//Least waiting time is b[i] - a[i] / 2
    	int waiting = (b[i] - a[i] + 1) / 2;
    	//If wtime is still smaller then the departure 
    	//then we need to wait for untill the departure time
    	if(time + waiting < b[i]) time += b[i]-time;
    	else time += waiting;
	}
	
	cout << time << endl ; 
	
}

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