#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int T, n, x, m, a[N], b[N], cnta, le[N], ri[N], y[505];
map<int, int> vis, to;
int main() {
  scanf("%d", &T);
  while (T--) {
    memset(y, 0, sizeof(y));
    scanf("%d%d%d", &n, &x, &m);
    to.clear();
    cnta = 0;
    a[++cnta] = x;
    for (long long i = 1; i <= m; i++) {
      scanf("%d%d", &le[i], &ri[i]);
      a[++cnta] = le[i];
      a[++cnta] = ri[i];
    }
    sort(a + 1, a + cnta + 1);
    int len = unique(a + 1, a + cnta + 1) - a - 1;
    for (long long i = 1; i <= len; i++) to[a[i]] = i;
    y[to[x]] = 1;
    int flg = 0;
    for (long long i = 1; i <= m; i++) {
      int fg = 0;
      for (long long j = to[le[i]]; j <= to[ri[i]]; j++) {
        if (y[j]) fg = 1;
      }
      if (fg) {
        if (le[i] != ri[i]) flg = 1;
        for (long long j = to[le[i]]; j <= to[ri[i]]; j++) {
          y[j] = 1;
        }
      }
    }
    a[0] = a[1];
    int ans = 0, f1 = 0;
    for (long long i = 1; i <= len; i++) {
      if (y[i]) {
        if (f1)
          ans += a[i] - a[i - 1];
        else
          f1 = 1;
      }
    }
    if (flg)
      printf("%d\n", ans + 1);
    else
      printf("1\n");
  }
}
