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;
const int INF = (int)1e9;
const int EPS = 1e-8;
const int MOD = 1000000007;
const long double PI = 3.14159265359;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
inline bool grid_inside(int x, int y, int n, int m) {
  return x >= 1 && x <= n && y >= 1 && y <= m;
}
bool inrange(int a, int b, int a1, int b1) {
  if (a >= a1 && a <= b1) return true;
  if (b >= a1 && b <= b1) return true;
  if (a1 >= a && a1 <= b) return true;
  if (b1 >= a && b1 <= b) return true;
  return false;
}
template <typename T>
T lcm(T a, T b) {
  return (a * b) / __gcd(a, b);
}
template <typename ForwardIterator, typename T>
T first_val(ForwardIterator first, ForwardIterator last, T value) {
  auto it = std::lower_bound(first, last, value);
  return (it != last) ? (it - first) : -1;
}
template <typename ForwardIterator, typename T>
T last_val(ForwardIterator first, ForwardIterator last, T value) {
  auto it = std::upper_bound(first, last, value);
  return ((it != last) ? ((it - first) - 1) : -1);
}
template <typename T>
T Dis(T x1, T y1, T x2, T y2) {
  return sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)));
}
template <typename T>
T Angle(T x1, T y1, T x2, T y2) {
  return atan((double)(y1 - y2) / (double)(x1 - x2));
}
int Set(int N, int pos) { return N = N | (1 << pos); }
int Reset(int N, int pos) { return N = N & ~(1 << pos); }
bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }
template <class T, class X>
inline T togglebit(T a, X i) {
  T t = 1;
  return (a ^ (t << i));
}
bool compare(const pair<int, int> &i, const pair<int, int> &j) {
  return i.first < j.first;
}
int doubleCompare(double x, double y) {
  if (fabs(x - y) <= EPS) return 0;
  if (x < y) return -1;
  return 1;
}
int LSOne(long long int n) { return log2(n & -n) + 1; }
int rangeClear(int n, int i, int j) {
  int ones = ~0;
  int a = ones << (j + 1);
  int b = (i << 2) - 1;
  int mask = a | b;
  int ans = n & mask;
  return ans;
}
int countSetBits(int n) {
  int count = 0;
  while (n > 0) {
    count += (n & 1);
    n = n >> 1;
  }
  return count;
}
int getPosBit(int n, int k) { return (n & (1 << k)) != 0 ? 1 : 0; }
void setPosBit(int &n, int k) { n = n | (1 << k); }
long long int fast_power(long long int a, long long int x) {
  if (x == 0)
    return 1;
  else if (x == 1)
    return a;
  else {
    long long int R = fast_power(a, x >> 1);
    if (!(x & 1))
      return R * R;
    else
      return R * a * R;
  }
}
long long int fast_power_unlocked(long long int a, long long int n,
                                  long long int mod) {
  long long int res = 1;
  while (n > 0) {
    if (n & 1) {
      res = (res * a) % mod;
    }
    a = (a * a) % mod;
    n = n >> 1;
  }
  return res;
}
long long int modInverse(long long int A, long long int M) {
  return fast_power_unlocked(A, M - 2, M);
}
bool checkPrime(long long int n) {
  int cnt = 0;
  for (long long int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;
      else
        cnt += 2;
    }
  }
  if (cnt == 2)
    return true;
  else
    return false;
}
const int MAX_N = 1001;
void solve() {
  int n, x, m;
  cin >> n >> x >> m;
  pair<int, int> v;
  v = make_pair(x, x);
  int k = 1;
  while (m--) {
    int a, b;
    cin >> a >> b;
    if (inrange(a, b, v.first, v.second)) {
      if (a < v.first) v.first = a;
      if (b > v.second) v.second = b;
    }
  }
  cout << v.second - v.first + 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ;
  for (auto blockTime = make_pair(chrono::high_resolution_clock::now(), true);
       blockTime.second;
       fprintf(stderr, "%s: %ld ms\n", "Time Taken",
               chrono::duration_cast<chrono::milliseconds>(
                   chrono::high_resolution_clock::now() - blockTime.first)
                   .count()),
            fflush(stderr), blockTime.second = false) {
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i) {
      solve();
      cout << '\n';
    }
  }
}
