#include <bits/stdc++.h>
using namespace std;
template <class T>
void show(const vector<T> &a) {
  for (T x : a) cout << x << " ";
  cout << '\n';
}
vector<long long> xx = {1, 0, -1, 0};
vector<long long> yy = {0, 1, 0, -1};
string dir = "LRUD";
const long long N = 5e5 + 50, oo = 3e18 + 500;
const long long mod = 1e9 + 7;
const long double eps = 1e-12, PI = 2 * acos(0.0);
long long n, m, k;
long long cnt = 0;
long long lg = 18;
vector<long long> g[N];
vector<long long> rg[N];
vector<long long> visit(N, 0);
struct segtree {
  struct node {
    long long set;
    long long add;
    long long sum;
  };
  long long N;
  vector<node> tree;
  long long NO_OPERATION = -1;
  long long NEUTRAL_ELEMENT = 0;
  void init(long long n) {
    N = 1;
    while (N < n) N <<= 1;
    tree.assign(N << 1, {NO_OPERATION, 0, 0});
  }
  void build(long long n) { init(n); }
  void push(long long v, long long lx, long long rx) {
    if (rx == lx) {
      return;
    }
    long long x = tree[v].set;
    if (x != NO_OPERATION) {
      long long m = (lx + rx) >> 1;
      tree[v << 1].set = tree[v << 1 | 1].set = x;
      tree[v << 1].add = tree[v << 1 | 1].add = 0;
      tree[v << 1].sum = x * (m - lx + 1);
      tree[v << 1 | 1].sum = x * (rx - m);
      tree[v].set = NO_OPERATION;
    }
    x = tree[v].add;
    if (x) {
      long long m = (lx + rx) >> 1;
      tree[v << 1].set =
          (tree[v << 1].set == NO_OPERATION ? NO_OPERATION
                                            : tree[v << 1].set + x);
      tree[v << 1].add =
          (tree[v << 1].set == NO_OPERATION ? tree[v << 1].add + x : 0);
      tree[v << 1 | 1].set =
          (tree[v << 1 | 1].set == NO_OPERATION ? NO_OPERATION
                                                : tree[v << 1 | 1].set + x);
      tree[v << 1 | 1].add =
          (tree[v << 1 | 1].set == NO_OPERATION ? tree[v << 1 | 1].add + x : 0);
      tree[v << 1].sum += x * (m - lx + 1);
      tree[v << 1 | 1].sum += x * (rx - m);
      tree[v].add = 0;
    }
  }
  void set(long long v, long long lx, long long rx, long long l, long long r,
           long long x, bool st) {
    push(v, lx, rx);
    if (l > r) return;
    if (lx == l && rx == r) {
      if (st) {
        tree[v].set = x;
        tree[v].add = 0;
        tree[v].sum = (r - l + 1) * x;
      } else {
        tree[v].set =
            (tree[v].set == NO_OPERATION ? NO_OPERATION : tree[v].set + x);
        tree[v].add = (tree[v].set == NO_OPERATION ? tree[v].add + x : 0);
        tree[v].sum += (r - l + 1) * x;
      }
      return;
    }
    long long m = (lx + rx) >> 1;
    set(v << 1, lx, m, l, min(r, m), x, st);
    set(v << 1 | 1, m + 1, rx, max(m + 1, l), r, x, st);
    tree[v].sum = tree[v << 1].sum + tree[v << 1 | 1].sum;
  }
  void set(long long l, long long r, long long x, bool st) {
    set(1, 0, N - 1, l, r, x, st);
  }
  long long get(long long v, long long lx, long long rx, long long l,
                long long r) {
    if (l > r) return NEUTRAL_ELEMENT;
    push(v, lx, rx);
    if (lx == l && rx == r) {
      return tree[v].sum;
    }
    long long m = (lx + rx) >> 1;
    long long g1 = get(v << 1, lx, m, l, min(r, m));
    long long g2 = get(v << 1 | 1, m + 1, rx, max(m + 1, l), r);
    return g1 + g2;
  }
  long long get(long long l, long long r) { return get(1, 0, N - 1, l, r); }
};
signed main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, x, m;
    cin >> n >> x >> m;
    vector<vector<long long> > v;
    long long L = x, R = x;
    for (long long i = 0; i < m; i++) {
      long long l, r;
      cin >> l >> r;
      if (L >= l && L <= r || R >= l && R <= r) {
        L = min(L, l);
        ;
        R = max(R, r);
        ;
      }
    }
    cout << R - L + 1 << '\n';
  }
}
