#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, x, m;
    cin >> n >> x >> m;
    long long l, r;
    l = r = x;
    while (m--) {
      long long u, v;
      cin >> u >> v;
      if (u > v) swap(u, v);
      if (r < u || v < l)
        continue;
      else {
        l = min(l, u);
        r = max(r, v);
      }
    }
    cout << r - l + 1 << endl;
  }
}
