/* * =template=.cpp * Copyright (C) 2017 hzw * * Distributed under terms of the MIT license. */ #include #include #include #include #include #include #include #include #include #include #include #include #define FR first #define SC second #define MP make_pair #define rep(i,a,b) for (int i=a;i<=b;i++) #define pb push_back #define ws wss #define left lll #define right rrr using namespace std; typedef long long LL; typedef pair PII; template void upmax(T &a,T b) { if (a void upmin(T &a,T b) { if (a>b) a=b;} void read(int &x) { char ch;int fu=1; while ((ch=getchar())<=32); x=0; if (ch=='-') fu=-1;else x=ch-48; while ((ch=getchar())>32) x=x*10+ch-48; x*=fu; } void read(unsigned long long &x) { char ch;int fu=1; while ((ch=getchar())<=32); x=0; if (ch=='-') fu=-1;else x=ch-48; while ((ch=getchar())>32) x=x*10+ch-48; x*=fu; } const double pi=acos(-1); void upmax(int &a,int b) { if (ab) a=b;} //----------------------- int exp(int a,int b,int c) { int d=1; while (b) { if (b&1) d=1LL*d*a%c; b>>=1;a=1LL*a*a%c; } return d; } int gcd(int a,int b) { return b>0?gcd(b,a%b):a;} const int N=110000,p=1000000007; int cas,n; int main() { scanf("%d",&cas); while (cas--) { scanf("%d",&n); int l,r; int cost=0; scanf("%d%d",&l,&r); for (int i=2;i<=n;i++) { int a,b; scanf("%d%d",&a,&b); if (r<=a) { cost+=(a-r+1)/2; l=a; if ((a-r)%2==1&&a=b) { cost+=(l-b+1)/2; r=b; if ((l-b)%2==1&&a