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


int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
cin>>t;
while(t--){
int n;
cin>>n;
vector<pair<int,int>> v(n+1);
vector<int> late(n+1);
for(int i=1;i<=n;i++)
cin>>v[i].first>>v[i].second;
v[0]={0,0};
for(int i=1;i<=n;i++)
cin>>late[i];
int total_t=0;
int dept=0;
for(int i=1;i<=n;i++){
	int arrv=v[i].first-v[i-1].second+late[i]+dept;
	total_t+=(arrv-dept);
	dept=max(v[i].second,arrv+(v[i].second-v[i].first+1)/2);
	if(i<n)total_t+=(dept-arrv);  //We just need time till arrival at nth station.
}
cout<<total_t<<endl;
}

return 0;
}
