You are given an array consisting of n integers a_1, a_2, ..., a_n. Initially a_x = 1, all other elements are equal to 0.

You have to perform m operations. During the i-th operation, you choose two indices c and d such that l_i ≤ c, d ≤ r_i, and swap a_c and a_d.

Calculate the number of indices k such that it is possible to choose the operations so that a_k = 1 in the end.

Input

The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. Then the description of t testcases follow.

The first line of each test case contains three integers n, x and m (1 ≤ n ≤ 10^9; 1 ≤ m ≤ 100; 1 ≤ x ≤ n).

Each of next m lines contains the descriptions of the operations; the i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n).

Output

For each test case print one integer — the number of indices k such that it is possible to choose the operations so that a_k = 1 in the end.

Example

Input


3
6 4 3
1 6
2 3
5 5
4 1 2
2 4
1 2
3 3 2
2 3
1 2


Output


6
2
3

Note

In the first test case, it is possible to achieve a_k = 1 for every k. To do so, you may use the following operations:

  1. swap a_k and a_4; 
  2. swap a_2 and a_2; 
  3. swap a_5 and a_5. 



In the second test case, only k = 1 and k = 2 are possible answers. To achieve a_1 = 1, you have to swap a_1 and a_1 during the second operation. To achieve a_2 = 1, you have to swap a_1 and a_2 during the second operation.
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long pow_mod(long long x, long long n, long long mod) {
  long long res = 1;
  while (n) {
    if (n & 1) res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
long long fact_pow(long long n, long long p) {
  long long res = 0;
  while (n) {
    n /= p;
    res += n;
  }
  return res;
}
long long mult(long long a, long long b, long long p) {
  a %= p;
  b %= p;
  long long r = 0, v = a;
  while (b) {
    if (b & 1) {
      r += v;
      if (r > p) r -= p;
    }
    v <<= 1;
    if (v > p) v -= p;
    b >>= 1;
  }
  return r;
}
long long quick_pow(long long a, long long b, long long p) {
  long long r = 1, v = a % p;
  while (b) {
    if (b & 1) r = mult(r, v, p);
    v = mult(v, v, p);
    b >>= 1;
  }
  return r;
}
bool CH(long long a, long long n, long long x, long long t) {
  long long r = quick_pow(a, x, n);
  long long z = r;
  for (long long i = 1; i <= t; i++) {
    r = mult(r, r, n);
    if (r == 1 && z != 1 && z != n - 1) return true;
    z = r;
  }
  return r != 1;
}
bool Miller_Rabin(long long n) {
  if (n < 2) return false;
  if (n == 2) return true;
  if (!(n & 1)) return false;
  long long x = n - 1, t = 0;
  while (!(x & 1)) {
    x >>= 1;
    t++;
  }
  srand(time(NULL));
  long long o = 8;
  for (long long i = 0; i < o; i++) {
    long long a = rand() % (n - 1) + 1;
    if (CH(a, n, x, t)) return false;
  }
  return true;
}
struct Tree {
  long long l, r, sum, lazy, maxn, minn;
} tree[4 * 100005];
inline void push_up(long long rt) {
  tree[rt].sum = tree[rt << 1].sum + tree[rt << 1 | 1].sum;
  tree[rt].maxn = max(tree[rt << 1].maxn, tree[rt << 1 | 1].maxn);
  tree[rt].minn = min(tree[rt << 1].minn, tree[rt << 1 | 1].minn);
}
inline void push_down(long long rt, long long length) {
  if (tree[rt].lazy) {
    tree[rt << 1].lazy += tree[rt].lazy;
    tree[rt << 1 | 1].lazy += tree[rt].lazy;
    tree[rt << 1].sum += (length - (length >> 1)) * tree[rt].lazy;
    tree[rt << 1 | 1].sum += (length >> 1) * tree[rt].lazy;
    tree[rt << 1].minn += tree[rt].lazy;
    tree[rt << 1 | 1].minn += tree[rt].lazy;
    tree[rt << 1].maxn += tree[rt].lazy;
    tree[rt << 1 | 1].maxn += tree[rt].lazy;
    tree[rt].lazy = 0;
  }
}
inline void build(long long l, long long r, long long rt, long long* aa) {
  tree[rt].lazy = 0;
  tree[rt].l = l;
  tree[rt].r = r;
  if (l == r) {
    tree[rt].sum = aa[l];
    tree[rt].minn = tree[rt].sum;
    tree[rt].maxn = tree[rt].sum;
    return;
  }
  long long mid = (l + r) >> 1;
  build(l, mid, rt << 1, aa);
  build(mid + 1, r, rt << 1 | 1, aa);
  push_up(rt);
}
inline void update_range(long long L, long long R, long long key,
                         long long rt) {
  if (tree[rt].r < L || tree[rt].l > R) return;
  if (L <= tree[rt].l && R >= tree[rt].r) {
    tree[rt].sum += (tree[rt].r - tree[rt].l + 1) * key;
    tree[rt].minn += key;
    tree[rt].maxn += key;
    tree[rt].lazy += key;
    return;
  }
  push_down(rt, tree[rt].r - tree[rt].l + 1);
  long long mid = (tree[rt].r + tree[rt].l) >> 1;
  if (L <= mid) update_range(L, R, key, rt << 1);
  if (R > mid) update_range(L, R, key, rt << 1 | 1);
  push_up(rt);
}
inline long long query_range(long long L, long long R, long long rt) {
  if (L <= tree[rt].l && R >= tree[rt].r) {
    return tree[rt].sum;
  }
  push_down(rt, tree[rt].r - tree[rt].l + 1);
  long long mid = (tree[rt].r + tree[rt].l) >> 1;
  long long ans = 0;
  if (L <= mid) ans += query_range(L, R, rt << 1);
  if (R > mid) ans += query_range(L, R, rt << 1 | 1);
  return ans;
}
inline long long query_min(long long L, long long R, long long rt) {
  if (L <= tree[rt].l && R >= tree[rt].r) {
    return tree[rt].minn;
  }
  push_down(rt, tree[rt].r - tree[rt].l + 1);
  long long mid = (tree[rt].r + tree[rt].l) >> 1;
  long long ans = (0x3f3f3f3f3f3f3f3fll);
  if (L <= mid) ans = min(ans, query_min(L, R, rt << 1));
  if (R > mid) ans = min(ans, query_min(L, R, rt << 1 | 1));
  return ans;
}
inline long long query_max(long long L, long long R, long long rt) {
  if (L <= tree[rt].l && R >= tree[rt].r) {
    return tree[rt].maxn;
  }
  push_down(rt, tree[rt].r - tree[rt].l + 1);
  long long mid = (tree[rt].r + tree[rt].l) >> 1;
  long long ans = -(0x3f3f3f3f3f3f3f3fll);
  if (L <= mid) ans = max(ans, query_max(L, R, rt << 1));
  if (R > mid) ans = max(ans, query_max(L, R, rt << 1 | 1));
  return ans;
}
void exgcd(long long a, long long b, long long& d, long long& x, long long& y) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    exgcd(b, a % b, d, y, x);
    y -= x * (a / b);
  }
}
long long INV(long long a, long long p) {
  long long d, x, y;
  exgcd(a, p, d, x, y);
  return d == 1 ? (x + p) % p : -1;
}
long long getcnt(long long x) {
  long long ret = 0;
  while (x) x -= x & (-x), ret++;
  return ret;
}
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, x, m;
    cin >> n >> x >> m;
    long long l = x, r = x;
    for (long long i = 0; i < m; i++) {
      long long a, b;
      cin >> a >> b;
      if (b < l || a > r)
        continue;
      else {
        l = min(l, a);
        r = max(r, b);
      }
    }
    cout << r - l + 1 << endl;
  }
}
