#include using namespace std; int t, n; int main() { scanf("%d", &t); for (int tt = 0; tt < t; tt++) { scanf("%d", &n); int L = 1; int R = 1000000; int Z = 0; for (int i = 0; i < n; i++) { int a, b; scanf("%d%d", &a, &b); if (R < a) { if ((a - R) % 2 != 0 && (b - a) >= 1) { Z += (a - R + 1) / 2; L = a; R = a + 1; } else { Z += (a - R + 1) / 2; L = R = a; } } else if (b < L) { if ((L - b) % 2 != 0 && (b - a) >= 1) { Z += (L - b + 1) / 2; L = b - 1; R = b; } else { Z += (L - b + 1) / 2; L = R = b; } } else { L = max(L, a); R = min(R, b); } } printf("%d\n", Z); } return 0; }