#include <cstdio>
int a[105],b[105],tm[105],p[105],q[105];
int main()
{
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d%d",&a[i],&b[i]);
        for(int i=1;i<=n;i++)
            scanf("%d",&tm[i]);
        for(int i=1;i<=n;i++)
        {
            p[i]=q[i-1]+(a[i]-b[i-1]+tm[i]);
            if(b[i]-p[i]>=(b[i]-a[i]+1)/2)
                q[i]=b[i];
            else q[i]=p[i]+(b[i]-a[i]+1)/2;
        }
        printf("%d\n",p[n]);
    }
    return 0;
}