#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  scanf("%d", &(T));
  while (T--) {
    long long int n, x;
    scanf("%lld%lld", &(n), &(x));
    int m;
    scanf("%d", &(m));
    long long int a = x, b = x;
    for (int i = 1; i <= m; i++) {
      long long int l, r;
      scanf("%lld%lld", &(l), &(r));
      if (a >= l && a <= r) {
        a = min(a, l);
        b = max(b, r);
      } else if (b >= l && b <= r) {
        a = min(a, l);
        b = max(b, r);
      }
    }
    printf("%lld\n", b - a + 1);
  }
}
