#include<bits/stdc++.h>
#define int long long
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
using namespace std;
inline int read() {
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x; return x;
}
const int maxn=120;
int T,n,a[maxn],b[maxn],tt[maxn],ans;
signed main()
{
	T=read();
	while(T--)
	{
		n=read();
		For(i,1,n) a[i]=read(),b[i]=read();
		For(i,1,n) tt[i]=read();
		ans=a[1]+tt[1];
		if(n==1)
		{
			printf("%lld\n",ans);
			continue;
		}
		int ed=ans+ceil((b[1]-a[1])/2.0);
		ans=max(ed,b[1]);
		For(i,2,n)
		{
			ans+=a[i]-b[i-1]+tt[i];
			if(i==n) break;
			ed=ans+ceil((b[i]-a[i])/2.0);
			ans=max(ed,b[i]);
		}
		printf("%lld\n",ans);
	}
	return 0;
}